From d8806d1ee4e69750a2e9e16f53747e741723751c Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 9 Dec 2025 01:17:15 -0600 Subject: [PATCH] Prefer high compression, jpeg/webp images --- src/lib/system.ts | 19 +++++++++---------- src/lib/tools/GenerateImageTool.ts | 22 ++++++++++------------ 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/lib/system.ts b/src/lib/system.ts index ddee40b0..20ade5be 100644 --- a/src/lib/system.ts +++ b/src/lib/system.ts @@ -180,6 +180,13 @@ When a project is first created, you (the AI) choose an appropriate template fro - URL: {{ template.url }} {% endfor %} +## Available Tools +{% if tools.length > 0 %} +You have access to the following tools: +{% for tool in tools %}{% if tool.type === 'function' %} +- **{{ tool.function.name }}**: {{ tool.function.description or 'No description available' }}{% endif %}{% endfor %}{% else %} +There are no tools available to you.{% endif %} + ## Image Generation Shakespeare supports AI-powered image generation. Users can configure an image model in **Settings > AI** under the "Advanced" section. @@ -187,17 +194,9 @@ Shakespeare supports AI-powered image generation. Users can configure an image m {% if imageModel %}- **Configured Image Model**: {{ imageModel }}{% else %}- **Image Model Status**: Not configured{% endif %} **Important Notes:** -- Not all models support image generation -- If users experience issues with image generation, they should try selecting a different image model in Settings > AI -- Recommended models include gpt-image-1 and gemini-3-pro-image +- Not all models support image generation. If users experience issues with image generation, they should try selecting a different image model in Settings > AI - The generate_image tool will only be available once a compatible image model is configured - -## Available Tools -{% if tools.length > 0 %} -You have access to the following tools: -{% for tool in tools %}{% if tool.type === 'function' %} -- **{{ tool.function.name }}**: {{ tool.function.description or 'No description available' }}{% endif %}{% endfor %}{% else %} -There are no tools available to you.{% endif %} +- When generating images for projects, prefer "jpeg" or "webp" output formats with compression set between 70-90. You must supply these parameters when calling the generate_image tool to ensure optimal image quality and file size for web usage. ## Skills diff --git a/src/lib/tools/GenerateImageTool.ts b/src/lib/tools/GenerateImageTool.ts index 13f346a6..db224576 100644 --- a/src/lib/tools/GenerateImageTool.ts +++ b/src/lib/tools/GenerateImageTool.ts @@ -9,7 +9,7 @@ import { proxyUrl } from '../proxyUrl'; interface GenerateImageParams { prompt: string; output_format?: "png" | "jpeg" | "webp"; - quality?: "auto" | "standard" | "hd" | "low" | "medium" | "high"; + output_compression?: number; size?: "auto" | "1024x1024" | "1536x1024" | "1024x1536" | "256x256" | "512x512" | "1792x1024" | "1024x1792"; } @@ -21,7 +21,7 @@ export class GenerateImageTool implements Tool { readonly inputSchema = z.object({ prompt: z.string().describe('A detailed text description of the image to generate'), output_format: z.enum(["png", "jpeg", "webp"]).optional().describe('Output format for the image (e.g., "png", "jpeg", "webp"). Support varies by model - leave blank if unsure'), - quality: z.enum(["auto", "standard", "hd", "low", "medium", "high"]).optional().describe('Quality setting for the image (e.g., "high", "medium", "low"). Support varies by model - leave blank if unsure'), + output_compression: z.number().min(1).max(100).optional().describe('Compression quality for the image (0 to 100). Only applicable for "jpeg" and "webp" formats'), size: z.enum(["auto", "1024x1024", "1536x1024", "1024x1536", "256x256", "512x512", "1792x1024", "1024x1792"]).optional().describe('Size of the generated image (e.g., "1024x1024", "1536x1024"). Support varies by model - leave blank if unsure'), }); @@ -36,14 +36,14 @@ export class GenerateImageTool implements Tool { ) {} async execute(args: GenerateImageParams): Promise { - const { prompt, output_format, quality, size } = args; + const { prompt, output_format, output_compression, size } = args; try { const client = createAIClient(this.provider, this.user, this.corsProxy); let cost: number | undefined; let imageData: Uint8Array; - let extension = 'png'; + let extension = output_format ?? 'png'; // Use chat completions endpoint for models that support image output modality if (this.mode === 'chat') { @@ -91,7 +91,10 @@ export class GenerateImageTool implements Tool { throw new Error('Invalid data URI format'); } - extension = dataUriMatch[1]; + if (dataUriMatch[1] === "png" || dataUriMatch[1] === "jpeg" || dataUriMatch[1] === "webp") { + extension = dataUriMatch[1]; + } + const base64Data = dataUriMatch[2]; // Decode base64 to bytes @@ -106,7 +109,7 @@ export class GenerateImageTool implements Tool { model: this.model, prompt, output_format, - quality, + output_compression, size, }); @@ -145,18 +148,13 @@ export class GenerateImageTool implements Tool { const contentType = imageResponse.headers.get('content-type'); if (contentType) { const match = contentType.match(/image\/([^;]+)/); - if (match) { + if (match && (match[1] === 'png' || match[1] === 'jpeg' || match[1] === 'webp')) { extension = match[1]; } } } else { throw new Error('No base64 image data or URL returned from the API'); } - - // Default extension is PNG for standard OpenAI responses - if (extension === 'png') { - extension = 'png'; - } } // Generate unique filename