mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-07-16 00:41:14 +03:00
Improve chat handling
This commit is contained in:
parent
5b74148e86
commit
7b0c036e8a
@ -398,12 +398,32 @@ async def _execute_get_live_context(
|
|||||||
# be injected as a user message (images can't be in tool results)
|
# be injected as a user message (images can't be in tool results)
|
||||||
result["_image_url"] = image_url
|
result["_image_url"] = image_url
|
||||||
elif genai_manager.vision_client is not None:
|
elif genai_manager.vision_client is not None:
|
||||||
# Separate vision provider — have it describe the image
|
# Separate vision provider — have it describe the image,
|
||||||
|
# providing detection context so it knows what to focus on
|
||||||
frame_bytes = _decode_data_url(image_url)
|
frame_bytes = _decode_data_url(image_url)
|
||||||
if frame_bytes:
|
if frame_bytes:
|
||||||
|
detections = result.get("detections", [])
|
||||||
|
if detections:
|
||||||
|
detection_lines = []
|
||||||
|
for d in detections:
|
||||||
|
parts = [d.get("label", "unknown")]
|
||||||
|
if d.get("sub_label"):
|
||||||
|
parts.append(f"({d['sub_label']})")
|
||||||
|
if d.get("zones"):
|
||||||
|
parts.append(f"in {', '.join(d['zones'])}")
|
||||||
|
detection_lines.append(" ".join(parts))
|
||||||
|
context = (
|
||||||
|
"The following objects are currently being tracked: "
|
||||||
|
+ "; ".join(detection_lines)
|
||||||
|
+ "."
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
context = "No objects are currently being tracked."
|
||||||
|
|
||||||
description = genai_manager.vision_client._send(
|
description = genai_manager.vision_client._send(
|
||||||
"Describe what you see in this security camera image. "
|
f"Describe what you see in this security camera image. "
|
||||||
"Focus on people, vehicles, animals, and any notable activity.",
|
f"{context} Focus on the scene, any visible activity, "
|
||||||
|
f"and details about the tracked objects.",
|
||||||
[frame_bytes],
|
[frame_bytes],
|
||||||
)
|
)
|
||||||
if description:
|
if description:
|
||||||
@ -426,8 +446,8 @@ async def _get_live_frame_image_url(
|
|||||||
"""
|
"""
|
||||||
Fetch the current live frame for a camera as a base64 data URL.
|
Fetch the current live frame for a camera as a base64 data URL.
|
||||||
|
|
||||||
Returns None if the frame cannot be retrieved. Used when include_live_image
|
Returns None if the frame cannot be retrieved. Used by get_live_context
|
||||||
is set to attach the image to the first user message.
|
to attach the live image to the conversation.
|
||||||
"""
|
"""
|
||||||
if (
|
if (
|
||||||
camera not in allowed_cameras
|
camera not in allowed_cameras
|
||||||
@ -442,12 +462,12 @@ async def _get_live_frame_image_url(
|
|||||||
if frame is None:
|
if frame is None:
|
||||||
return None
|
return None
|
||||||
height, width = frame.shape[:2]
|
height, width = frame.shape[:2]
|
||||||
max_dimension = 1024
|
target_height = 480
|
||||||
if height > max_dimension or width > max_dimension:
|
if height > target_height:
|
||||||
scale = max_dimension / max(height, width)
|
scale = target_height / height
|
||||||
frame = cv2.resize(
|
frame = cv2.resize(
|
||||||
frame,
|
frame,
|
||||||
(int(width * scale), int(height * scale)),
|
(int(width * scale), target_height),
|
||||||
interpolation=cv2.INTER_AREA,
|
interpolation=cv2.INTER_AREA,
|
||||||
)
|
)
|
||||||
_, img_encoded = cv2.imencode(".jpg", frame, [cv2.IMWRITE_JPEG_QUALITY, 85])
|
_, img_encoded = cv2.imencode(".jpg", frame, [cv2.IMWRITE_JPEG_QUALITY, 85])
|
||||||
@ -719,7 +739,13 @@ async def chat_completion(
|
|||||||
if camera_config.friendly_name
|
if camera_config.friendly_name
|
||||||
else camera_id.replace("_", " ").title()
|
else camera_id.replace("_", " ").title()
|
||||||
)
|
)
|
||||||
cameras_info.append(f" - {friendly_name} (ID: {camera_id})")
|
zone_names = list(camera_config.zones.keys())
|
||||||
|
if zone_names:
|
||||||
|
cameras_info.append(
|
||||||
|
f" - {friendly_name} (ID: {camera_id}, zones: {', '.join(zone_names)})"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
cameras_info.append(f" - {friendly_name} (ID: {camera_id})")
|
||||||
|
|
||||||
cameras_section = ""
|
cameras_section = ""
|
||||||
if cameras_info:
|
if cameras_info:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user