From 6ec28d33a4b91acf0602c2549bd744dd617a5e0a Mon Sep 17 00:00:00 2001 From: OpenClaw Agent Date: Fri, 10 Jul 2026 11:23:28 +0000 Subject: [PATCH] Retry truncated Ollama character analysis --- ltx_director.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/ltx_director.py b/ltx_director.py index 83dec6a..8044128 100644 --- a/ltx_director.py +++ b/ltx_director.py @@ -466,6 +466,17 @@ def _extract_ollama_generated_text(resp_json: dict) -> str: return "" +def _analysis_text_is_usable(text: str) -> bool: + text = (text or "").strip() + if not text: + return False + if len(text) < 24: + return False + if len(text.split()) < 6: + return False + return True + + def _compress_analysis_image_b64(b64_payload: str, max_dim: int = 768, quality: int = 82) -> str: """Shrink analysis images so multimodal providers do not burn their full context on pixels.""" try: @@ -540,6 +551,10 @@ async def analyze_character_endpoint(request): "images": analysis_images, "stream": False, "keep_alive": 0, + "options": { + "temperature": 0.2, + "num_predict": 120, + }, } async with session.post(f"{base_url}/api/generate", json=payload, timeout=300) as response: if response.status != 200: @@ -558,6 +573,28 @@ async def analyze_character_endpoint(request): else: resp_json = await response.json() generated_text = _extract_ollama_generated_text(resp_json) + + if not _analysis_text_is_usable(generated_text): + chat_payload = { + "model": model_name, + "messages": [{ + "role": "user", + "content": _ANALYZE_PROMPT, + "images": analysis_images, + }], + "stream": False, + "keep_alive": 0, + "options": { + "temperature": 0.2, + "num_predict": 120, + }, + } + async with session.post(f"{base_url}/api/chat", json=chat_payload, timeout=300) as response: + if response.status == 200: + resp_json = await response.json() + chat_text = _extract_ollama_generated_text(resp_json) + if _analysis_text_is_usable(chat_text): + generated_text = chat_text else: # OpenAI-compatible vision chat (LM Studio / Custom). content = [{"type": "text", "text": _ANALYZE_PROMPT}]