diff --git a/src/games/storywriter/utils/prompt.ts b/src/games/storywriter/utils/prompt.ts index dbf304d..f26d401 100644 --- a/src/games/storywriter/utils/prompt.ts +++ b/src/games/storywriter/utils/prompt.ts @@ -284,8 +284,19 @@ namespace Prompt { return lines.join('\n'); } + const objectUrls = new Map(); function stripDataUrlImages(text: string): string { - return text.replace(/!\[([^\]]*)\]\(data:[^)]+\)/g, (_, alt) => `[image: ${alt}]`); + return text.replace(/!\[([^\]]*)\]\((data:([^;]*);base64,[^)]+)\)/g, (_, alt, dataUrl, type) => { + let blobUrl = objectUrls.get(dataUrl); + if (!blobUrl) { + const b64 = dataUrl.replace(/^data:[^;]*;base64,/, ''); + const imageData = atob(b64); + const blob = new Blob([imageData], { type }); + blobUrl = URL.createObjectURL(blob); + objectUrls.set(dataUrl, blobUrl); + } + return `![${alt}](${blobUrl})`; + }); } export function substituteVars(state: AppState, text: string): string { diff --git a/src/games/storywriter/utils/tools.ts b/src/games/storywriter/utils/tools.ts index bb62720..232274a 100644 --- a/src/games/storywriter/utils/tools.ts +++ b/src/games/storywriter/utils/tools.ts @@ -478,14 +478,14 @@ export namespace Tools { if (!appState.imageModel) { return 'Error: No image model configured'; } - const { width: defaultWidth, height: defaultHeight, negative_prompt, sampler_name } = appState.imageGenerationSettings; + const { width, height, negative_prompt, sampler_name } = appState.imageGenerationSettings; const response = await LLM.generateImage(appState.connection, { model: appState.imageModel.id, prompt: args.prompt, output_format: 'jpeg', image_settings: { - width: args.width ?? defaultWidth, - height: args.height ?? defaultHeight, + width, + height, negative_prompt: negative_prompt || undefined, sampler_name: sampler_name || undefined, }, @@ -502,8 +502,6 @@ export namespace Tools { description: 'Generate an image from a text prompt. Format prompt as tags: masterpiece, best quality, ...', parameters: Type.Object({ prompt: Type.String({ description: 'The image generation prompt' }), - width: Type.Optional(Type.Integer({ description: 'Image width in pixels' })), - height: Type.Optional(Type.Integer({ description: 'Image height in pixels' })), }), }), };