Add live context tool to LLM (#21754)

* Add live context tool

* Improve handling of images in request

* Improve prompt caching
This commit is contained in:
Nicolas Mowen
2026-02-26 21:27:56 -07:00
parent fa0feebd03
commit a4362caa0a
4 changed files with 188 additions and 5 deletions
+3 -2
View File
@@ -69,7 +69,7 @@ class GenAIClient:
return "\n- (No objects detected)"
context_prompt = f"""
Your task is to analyze the sequence of images ({len(thumbnails)} total) taken in chronological order from the perspective of the {review_data["camera"]} security camera.
Your task is to analyze a sequence of images taken in chronological order from a security camera.
## Normal Activity Patterns for This Property
@@ -108,7 +108,8 @@ Your response MUST be a flat JSON object with:
## Sequence Details
- Frame 1 = earliest, Frame {len(thumbnails)} = latest
- Camera: {review_data["camera"]}
- Total frames: {len(thumbnails)} (Frame 1 = earliest, Frame {len(thumbnails)} = latest)
- Activity started at {review_data["start"]} and lasted {review_data["duration"]} seconds
- Zones involved: {", ".join(review_data["zones"]) if review_data["zones"] else "None"}
+8 -1
View File
@@ -216,7 +216,14 @@ class LlamaCppClient(GenAIClient):
"finish_reason": "error",
}
except requests.exceptions.RequestException as e:
logger.warning("llama.cpp returned an error: %s", str(e))
error_detail = str(e)
if hasattr(e, "response") and e.response is not None:
try:
error_body = e.response.text
error_detail = f"{str(e)} - Response: {error_body[:500]}"
except Exception:
pass
logger.warning("llama.cpp returned an error: %s", error_detail)
return {
"content": None,
"tool_calls": None,