Skip to content

Commit

Permalink
Wrap JSON.parse in try catch
Browse files Browse the repository at this point in the history
Also change console.log to logger.debug
  • Loading branch information
bsu3338 authored Feb 9, 2024
1 parent 774f651 commit 2662b9b
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions api/app/clients/tools/structured/StableDiffusion.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,27 @@ class StableDiffusionAPI extends StructuredTool {
async _call(data) {
const url = this.url;
const { prompt, negative_prompt } = data;
const defaultPayload = process.env.SD_WEBUI_DEFAULT_PARAMETERS
? JSON.parse(process.env.SD_WEBUI_DEFAULT_PARAMETERS)
: {
sampler_name: 'DPM++ 2M Karras',
cfg_scale: 4.5,
steps: 22,
width: 1024,
height: 1024,
};
let defaultPayload;
try {
defaultPayload = process.env.SD_WEBUI_DEFAULT_PARAMETERS
? JSON.parse(process.env.SD_WEBUI_DEFAULT_PARAMETERS)
: {
sampler_name: 'DPM++ 2M Karras',
cfg_scale: 4.5,
steps: 22,
width: 1024,
height: 1024,
};
} catch (error) {
logger.error('[StableDiffusion] Error while parsing JSON:', error);
}

const payload = {
prompt: prompt,
negative_prompt: defaultPayload.negative_prompt || negative_prompt,
...defaultPayload,
};
console.log('Payload after parsing SD_WEBUI_DEFAULT_PARAMETERS JSON:', payload);
logger.debug(`[StableDiffusion] Payload: ${JSON.stringify(defaultPayload)}`);
const response = await axios.post(`${url}/sdapi/v1/txt2img`, payload);
const image = response.data.images[0];
const pngPayload = { image: `data:image/png;base64,${image}` };
Expand Down

0 comments on commit 2662b9b

Please sign in to comment.