Fix vision attachment timeout and stale cache
Increase local vision model timeout and avoid caching transient VL failure placeholders.\n\nCloses #202.
This commit is contained in:
committed by
GitHub
parent
71d74290f0
commit
4a04068818
@@ -223,19 +223,22 @@ class ChatHandler:
|
||||
if os.path.exists(_vcache):
|
||||
try:
|
||||
with open(_vcache) as _vf:
|
||||
vl_desc = _vf.read()
|
||||
cached_desc = _vf.read().strip()
|
||||
if cached_desc and not cached_desc.startswith("["):
|
||||
vl_desc = cached_desc
|
||||
except Exception:
|
||||
vl_desc = None
|
||||
if not vl_desc:
|
||||
vl_result = analyze_image_with_vl_result(file_info["path"])
|
||||
vl_desc = vl_result.get("text", "")
|
||||
vl_model = vl_result.get("model", "")
|
||||
try:
|
||||
os.makedirs(os.path.join(UPLOAD_DIR, ".vision"), exist_ok=True)
|
||||
with open(_vcache, "w") as _vf:
|
||||
_vf.write(vl_desc or "")
|
||||
except Exception:
|
||||
pass
|
||||
if vl_desc and not vl_desc.startswith("["):
|
||||
try:
|
||||
os.makedirs(os.path.join(UPLOAD_DIR, ".vision"), exist_ok=True)
|
||||
with open(_vcache, "w") as _vf:
|
||||
_vf.write(vl_desc)
|
||||
except Exception:
|
||||
pass
|
||||
enhanced_message = f"{enhanced_message}\n\n[Image: {file_info['name']}]\n{vl_desc}"
|
||||
# Surface the description to the client live so it renders as a
|
||||
# collapsible "image description" on the user bubble (not just
|
||||
|
||||
@@ -230,7 +230,7 @@ def analyze_image_with_vl_result(image_path: str) -> dict:
|
||||
last_err = None
|
||||
for i, (_url, _model, _headers) in enumerate([c for c in _vl_candidates if c and c[0] and c[1]]):
|
||||
try:
|
||||
description = llm_call(_url, _model, vl_messages, headers=_headers, timeout=30)
|
||||
description = llm_call(_url, _model, vl_messages, headers=_headers, timeout=120)
|
||||
logger.info("VL analysis complete with model %s", _model)
|
||||
return {"text": description, "model": _model}
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user