Validate and clean idea text before generating image prompt

This commit is contained in:
Victor Giers
2025-11-30 08:19:44 +01:00
parent c810eef5c8
commit d4e69db554

View File

@@ -583,11 +583,14 @@ ASSISTANT:
def generate_image_prompt_for_idea(idea_text: str, *, client: OllamaClient, model: str) -> str: def generate_image_prompt_for_idea(idea_text: str, *, client: OllamaClient, model: str) -> str:
details = classify_idea(idea_text) cleaned = (idea_text or "").strip()
if not cleaned:
raise ValueError("Idea text is empty")
details = classify_idea(cleaned)
category: IdeaCategory = details.get("category", IdeaCategory.APP_OR_TOOL) category: IdeaCategory = details.get("category", IdeaCategory.APP_OR_TOOL)
visualization_hint = details.get("visualization_hint", VISUALIZATION_HINTS.get(category, "")) visualization_hint = details.get("visualization_hint", VISUALIZATION_HINTS.get(category, ""))
system_message = build_image_prompt_system_message(category, visualization_hint) system_message = build_image_prompt_system_message(category, visualization_hint)
prompt = f"{system_message}\n\nUSER IDEA:\n{idea_text.strip()}\n\nASSISTANT:" prompt = f"{system_message}\n\nUSER IDEA:\n{cleaned}\n\nASSISTANT:"
raw = client.generate(model=model, prompt=prompt) raw = client.generate(model=model, prompt=prompt)
return sanitize_llm_text_simple(raw) return sanitize_llm_text_simple(raw)