mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 08:23:34 +00:00
Greatly simplify image generation config tools
This commit is contained in:
2 files changed
+28
-60
No files matched your search
@@ -17,10 +17,10 @@ interface ProviderModel {
|
||||
}
|
||||
|
||||
export class ConfigureImageGenerationTool implements Tool<ConfigureImageGenerationParams> {
|
||||
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<ConfigureImageGenerati
|
||||
|
||||
// Validate model ID format
|
||||
if (!modelId.includes('/')) {
|
||||
return 'ERROR: Invalid model ID format. The modelId must be in "provider/model" format (e.g., "openrouter/openai/gpt-image-1" or "openai/dall-e-3").\n\n' +
|
||||
'Please call the view_available_models tool first to see the list of available models and their full IDs, then use one of those full IDs.';
|
||||
return 'ERROR: Invalid model ID format. The modelId must be in "provider/model" format (e.g., "openrouter/openai/gpt-image-1" or "openai/dall-e-3").';
|
||||
}
|
||||
|
||||
// Check if model exists in available models
|
||||
// Check if model exists in available models (optional - provides helpful info if available)
|
||||
const model = this.models.find(m => 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`;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,67 +26,49 @@ export class ViewAvailableModelsTool implements Tool<Record<string, never>> {
|
||||
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<string, ProviderModel[]>();
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user