From 8aa04464db6dd8e9446a031fd7bec4112c3cb6c2 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 7 Dec 2025 22:20:05 -0600 Subject: [PATCH] Greatly simplify image generation config tools --- src/lib/tools/ConfigureImageGenerationTool.ts | 30 +++------- src/lib/tools/ViewAvailableModelsTool.ts | 58 +++++++------------ 2 files changed, 28 insertions(+), 60 deletions(-) diff --git a/src/lib/tools/ConfigureImageGenerationTool.ts b/src/lib/tools/ConfigureImageGenerationTool.ts index 6b880943..227ea81e 100644 --- a/src/lib/tools/ConfigureImageGenerationTool.ts +++ b/src/lib/tools/ConfigureImageGenerationTool.ts @@ -17,10 +17,10 @@ interface ProviderModel { } export class ConfigureImageGenerationTool implements Tool { - readonly description = 'Configure the AI model to use for image generation. The modelId must be a complete model identifier in the format "provider/model" (e.g., "openrouter/openai/gpt-image-1", "openai/dall-e-3", or "shakespeare/gpt-image-1"). IMPORTANT: You MUST call the view_available_models tool FIRST to see which models are available and support image generation (look for models with "image" in their modalities). Select a high-quality yet affordable model like gpt-image-1 or dall-e-3 unless the user has specific requirements. Consider the currently configured model (if any) to understand user preferences.'; + readonly description = 'Configure the AI model to use for image generation. The modelId must be a complete model identifier in the format "provider/model" (e.g., "openrouter/openai/gpt-image-1", "openai/dall-e-3", or "shakespeare/gpt-image-1"). You can optionally call view_available_models first to see available image models, but any valid model ID from a configured provider will work. Select a high-quality yet affordable model like gpt-image-1 or dall-e-3 unless the user has specific requirements.'; readonly inputSchema = z.object({ - modelId: z.string().describe('The complete model identifier in "provider/model" format (e.g., "openrouter/openai/gpt-image-1", "openai/dall-e-3"). Must be from the available models list.'), + modelId: z.string().describe('The complete model identifier in "provider/model" format (e.g., "openrouter/openai/gpt-image-1", "openai/dall-e-3").'), }); constructor( @@ -33,37 +33,23 @@ export class ConfigureImageGenerationTool implements Tool m.fullId === modelId); - - if (!model) { - return `ERROR: Model "${modelId}" is not available in the configured providers.\n\n` + - 'Please call the view_available_models tool to see the list of available models, then select one from that list.'; - } - - // Check if model supports image generation - const supportsImage = model.modalities?.includes('image'); - - if (!supportsImage) { - return `ERROR: Model "${modelId}" does not support image generation.\n\n` + - 'Please call the view_available_models tool and select a model that has "image" listed in its modalities (look for models marked with "✅ Supports image generation").'; - } // Update the settings this.aiSettings.updateSettings({ imageModel: modelId }); let response = `✅ Successfully configured image generation!\n\n`; response += `**Image Model**: ${modelId}\n`; - - if (model.name) { + + if (model?.name) { response += `**Name**: ${model.name}\n`; } - - if (model.description) { + + if (model?.description) { response += `**Description**: ${model.description}\n`; } diff --git a/src/lib/tools/ViewAvailableModelsTool.ts b/src/lib/tools/ViewAvailableModelsTool.ts index 99fceb5a..57e1bf91 100644 --- a/src/lib/tools/ViewAvailableModelsTool.ts +++ b/src/lib/tools/ViewAvailableModelsTool.ts @@ -26,67 +26,49 @@ export class ViewAvailableModelsTool implements Tool> { return 'No AI models are currently available. Please configure at least one AI provider in Settings > AI.'; } + // Filter image-capable models + const filteredModels = this.models.filter(m => !m.modalities || m.modalities.includes('image')); + // Group models by provider const modelsByProvider = new Map(); - for (const model of this.models) { + for (const model of filteredModels) { const providerModels = modelsByProvider.get(model.provider) || []; providerModels.push(model); modelsByProvider.set(model.provider, providerModels); } // Build output - let output = '# Available AI Models\n\n'; + let output = '# Available Models\n\n'; // Add note about current image model if configured if (this.currentImageModel) { - output += `**Current Image Model**: ${this.currentImageModel}\n\n`; - output += 'This indicates the user\'s current preference. When selecting a new model, consider choosing a similar provider or model family unless the user requests otherwise.\n\n'; + output += `**Current Image Model**: ${this.currentImageModel} ⭐\n\n`; } else { output += '**Current Image Model**: Not configured\n\n'; } - output += '## Models by Provider\n\n'; + if (filteredModels.length === 0) { + output += 'No models found in configured providers.\n'; + output += `Total models available: ${this.models.length} (none support image generation)\n`; + return output; + } + + output += `Found ${filteredModels.length} models:\n\n`; for (const [provider, providerModels] of modelsByProvider) { - output += `### ${provider}\n\n`; + output += `### ${provider} (${providerModels.length} models)\n\n`; for (const model of providerModels) { const isCurrentModel = this.currentImageModel === model.fullId; - const marker = isCurrentModel ? ' ⭐ **CURRENT**' : ''; - - output += `- **${model.fullId}**${marker}\n`; - - if (model.name && model.name !== model.id) { - output += ` - Name: ${model.name}\n`; - } - - if (model.description) { - output += ` - Description: ${model.description}\n`; - } - - if (model.contextLength) { - output += ` - Context Length: ${model.contextLength.toLocaleString()} tokens\n`; - } - - if (model.modalities && model.modalities.length > 0) { - output += ` - Modalities: ${model.modalities.join(', ')}\n`; - - // Highlight image generation capability - if (model.modalities.includes('image')) { - output += ` - ✅ **Supports image generation**\n`; - } - } - - output += '\n'; + const marker = isCurrentModel ? ' ⭐' : ''; + output += `- ${model.fullId}${marker}\n`; } + output += '\n'; } - output += '\n## Image Generation Recommendations\n\n'; - output += 'When selecting an image model:\n'; - output += '1. **Look for models with "image" in their modalities** - these support image generation\n'; - output += '2. **Consider cost and quality** - Models like gpt-image-1, dall-e-3, or similar are good balanced choices\n'; - output += '3. **Check the current model** (marked with ⭐) to understand user preferences\n'; - output += '4. **Prefer models from the same provider** as the current model when possible\n'; + if (this.currentImageModel) { + output += `Current selection (⭐) indicates user preference for this provider/model family.\n`; + } return output; }