fix genai and classification error paths (#25077)

- Catch all httpx errors in the Ollama plugin so a dropped connection no longer ends the embeddings thread
- Strip only a trailing /v1 from the llama.cpp base_url
- Cap the timestamp top-up loop in state example generation, which looped forever on zero-length review items
- Run state example generation in a thread under the example collection lock
- Stage example frames in a system temp dir so a leftover dataset/temp folder can't become a training class
- Report face training success only after the image is written, and return 404 when the event has no face attributes or snapshot
- Move VLM watch setup inside the runner's try block, build the runner before claiming the watch slot, bound max_duration_minutes, and reject non-string labels and zones from the chat tool
This commit is contained in:
Josh Hawkins
2026-11-24 06:18:02 -07:00
committed by GitHub
parent 08d693964b
commit 8b8cede583
10 changed files with 201 additions and 123 deletions
+8 -2
View File
@@ -14,7 +14,7 @@ import cv2
import numpy as np
from fastapi import APIRouter, Body, Depends, HTTPException, Request
from fastapi.responses import JSONResponse, StreamingResponse
from pydantic import BaseModel
from pydantic import BaseModel, Field
from frigate.api.auth import (
allow_any_authenticated,
@@ -56,6 +56,7 @@ from frigate.genai.utils import (
)
from frigate.jobs.export import ExportQueueFullError, start_export_job
from frigate.jobs.vlm_watch import (
MAX_WATCH_MINUTES,
VLMWatchJob,
get_vlm_watch_job,
start_vlm_watch_job,
@@ -88,7 +89,7 @@ class VLMMonitorRequest(BaseModel):
camera: str
condition: str
max_duration_minutes: int = 60
max_duration_minutes: int = Field(default=60, ge=1, le=MAX_WATCH_MINUTES)
labels: list[str] = []
zones: list[str] = []
@@ -1030,12 +1031,17 @@ async def _execute_start_camera_watch(
camera = arguments.get("camera", "").strip()
condition = arguments.get("condition", "").strip()
max_duration_minutes = int(arguments.get("max_duration_minutes", 60))
max_duration_minutes = max(1, min(MAX_WATCH_MINUTES, max_duration_minutes))
labels = arguments.get("labels") or []
zones = arguments.get("zones") or []
if not camera or not condition:
return {"error": "camera and condition are required."}
for value in (labels, zones):
if not isinstance(value, list) or not all(isinstance(v, str) for v in value):
return {"error": "labels and zones must be lists of strings."}
config = request.app.frigate_config
if camera not in config.cameras:
return {"error": f"Camera '{camera}' not found."}
+24 -19
View File
@@ -216,26 +216,28 @@ def train_face(request: Request, name: str, body: dict = None):
status_code=404,
)
snapshot = get_event_snapshot(event)
face_box = event.data["attributes"][0]["box"]
detect_config: DetectConfig = request.app.frigate_config.cameras[
event.camera
].detect
attributes = (event.data or {}).get("attributes") or []
snapshot = get_event_snapshot(event) if attributes else None
success = False
# crop onto the face box minus the bounding box itself
x1 = int(face_box[0] * detect_config.width) + 2
y1 = int(face_box[1] * detect_config.height) + 2
x2 = x1 + int(face_box[2] * detect_config.width) - 4
y2 = y1 + int(face_box[3] * detect_config.height) - 4
face = snapshot[y1:y2, x1:x2]
success = True
if snapshot is not None:
face_box = attributes[0]["box"]
detect_config: DetectConfig = request.app.frigate_config.cameras[
event.camera
].detect
if face.size > 0:
try:
cv2.imwrite(os.path.join(new_file_folder, new_name), face)
success = True
except Exception:
pass
# crop onto the face box minus the bounding box itself
x1 = int(face_box[0] * detect_config.width) + 2
y1 = int(face_box[1] * detect_config.height) + 2
x2 = x1 + int(face_box[2] * detect_config.width) - 4
y2 = y1 + int(face_box[3] * detect_config.height) - 4
face = snapshot[y1:y2, x1:x2]
if face.size > 0:
try:
success = cv2.imwrite(os.path.join(new_file_folder, new_name), face)
except cv2.error:
logger.exception("Failed to save face image for %s", event_id)
if not success:
return JSONResponse(
@@ -1273,7 +1275,10 @@ async def generate_state_examples(request: Request, body: GenerateStateExamplesB
if camera_name in request.app.frigate_config.cameras
}
collect_state_classification_examples(model_name, cameras_normalized)
async with example_collection_lock:
await asyncio.to_thread(
collect_state_classification_examples, model_name, cameras_normalized
)
return JSONResponse(
content={"success": True, "message": "Example generation completed"},