Skip to content

Commit 96c1928

Browse files
committed
fix(tools): make SD model list update dynamically
UniversalToolRegistry now rebuilds tool descriptions on each system prompt generation. ImageGenerationTool description re-evaluated fresh each time. Clarified MODELS section (installed) vs REQUIREMENTS section (reference knowledge). SD models now visible immediately after download without restart.
1 parent 0c3dd81 commit 96c1928

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

Sources/APIFramework/UniversalToolRegistry.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,19 @@ public class UniversalToolRegistry: ObservableObject, ToolRegistryProtocol {
240240
// MARK: - Tool Discovery (System Prompt Integration)
241241

242242
/// Get all tool definitions for injection into system prompts LLM discovers tools through system context.
243+
/// IMPORTANT: Rebuilds definitions dynamically to pick up updated tool descriptions (e.g., new models).
243244
public func getToolDefinitionsForSystemPrompt() -> [OpenAITool] {
244-
return toolDefinitions
245+
/// Rebuild tool definitions from current registered tools to ensure dynamic content (like ImageGenerationTool's model list) is fresh
246+
return registeredTools.values.map { tool in
247+
OpenAITool(
248+
type: "function",
249+
function: OpenAIFunction(
250+
name: tool.name,
251+
description: tool.description, // Re-read description (may be computed property)
252+
parameters: tool.parameters
253+
)
254+
)
255+
}
245256
}
246257

247258
/// Get tool definitions formatted for system prompt text.

Sources/StableDiffusionIntegration/ImageGenerationTool.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,15 @@ public class ImageGenerationTool: MCPTool, @unchecked Sendable {
126126
- generate (default): Create images from prompts
127127
- list_loras: Get full list of installed LoRAs with compatibility info
128128
\(modelsList)\(lorasList)
129-
MODEL REQUIREMENTS (CRITICAL):
130-
- SD1.5: 512x512, steps 20-50, guidance 5-15
131-
- SDXL: 1024x1024, steps 25-60, guidance 5-12
132-
- Z-Image: 1024x1024, steps 4-8 ONLY, guidance MUST BE 0, use SHORT prompts
129+
AVAILABLE MODELS (above):
130+
CRITICAL: ONLY use models listed above in MODELS section!
131+
Model types are classified as SD1.5, SDXL, or Z-Image based on their architecture.
132+
If no models are installed, you cannot generate images - ask user to download models first.
133+
134+
REQUIREMENTS BY MODEL TYPE (reference only - check actual installed models above):
135+
- SD1.5 models: 512x512 default, steps 20-50, guidance 5-15
136+
- SDXL models: 1024x1024 default, steps 25-60, guidance 5-12
137+
- Z-Image models: 1024x1024 default, steps 4-8 ONLY, guidance MUST BE 0, use SHORT prompts
133138
\(engineInfo)
134139
RESOLUTION OPTIONS (choose ONE method):
135140
1. PRESETS (easiest): preset='sd15_square', 'sd15_portrait', 'sd15_landscape', 'sdxl_square', 'sdxl_portrait', 'sdxl_landscape', 'sdxl_ultrawide', '720p', '1080p', '1024x768', '1296x800'

0 commit comments

Comments
 (0)