Harden vision LLM fallback, folder upload validation, and export memory

This commit is contained in:
CREDO23 2026-04-09 16:14:53 +02:00
parent e164fe0612
commit 4ccdd80e26
4 changed files with 79 additions and 15 deletions

View file

@ -1,3 +1,4 @@
import asyncio
import base64
import os
@ -13,6 +14,8 @@ _MAX_IMAGE_BYTES = (
5 * 1024 * 1024
) # 5 MB (Anthropic Claude's limit, the most restrictive)
_INVOKE_TIMEOUT_SECONDS = 120
_EXT_TO_MIME: dict[str, str] = {
".png": "image/png",
".jpg": "image/jpeg",
@ -52,7 +55,9 @@ async def parse_with_vision_llm(file_path: str, filename: str, llm) -> str:
{"type": "image_url", "image_url": {"url": data_url}},
]
)
response = await llm.ainvoke([message])
response = await asyncio.wait_for(
llm.ainvoke([message]), timeout=_INVOKE_TIMEOUT_SECONDS
)
text = response.content if hasattr(response, "content") else str(response)
if not text or not text.strip():
raise ValueError(f"Vision LLM returned empty content for {filename}")