From 8d719ec9cbd73da60fea0f21da6891763def72b8 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Sat, 9 Aug 2025 06:11:41 -0600 Subject: [PATCH] Send review update to dispatcher --- frigate/comms/dispatcher.py | 5 ++++ frigate/const.py | 1 + .../post/review_descriptions.py | 26 +++++++++++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/frigate/comms/dispatcher.py b/frigate/comms/dispatcher.py index dfd85301a..27855a575 100644 --- a/frigate/comms/dispatcher.py +++ b/frigate/comms/dispatcher.py @@ -26,6 +26,7 @@ from frigate.const import ( UPDATE_EMBEDDINGS_REINDEX_PROGRESS, UPDATE_EVENT_DESCRIPTION, UPDATE_MODEL_STATE, + UPDATE_REVIEW_DESCRIPTION, UPSERT_REVIEW_SEGMENT, ) from frigate.models import Event, Previews, Recordings, ReviewSegment @@ -149,6 +150,9 @@ class Dispatcher: ), ) + def handle_update_review_description() -> None: + logger.info(f"received review genai data {payload}") + def handle_update_model_state() -> None: if payload: model = payload["model"] @@ -232,6 +236,7 @@ class Dispatcher: CLEAR_ONGOING_REVIEW_SEGMENTS: handle_clear_ongoing_review_segments, UPDATE_CAMERA_ACTIVITY: handle_update_camera_activity, UPDATE_EVENT_DESCRIPTION: handle_update_event_description, + UPDATE_REVIEW_DESCRIPTION: handle_update_review_description, UPDATE_MODEL_STATE: handle_update_model_state, UPDATE_EMBEDDINGS_REINDEX_PROGRESS: handle_update_embeddings_reindex_progress, UPDATE_BIRDSEYE_LAYOUT: handle_update_birdseye_layout, diff --git a/frigate/const.py b/frigate/const.py index f02dab1dc..67f2fd907 100644 --- a/frigate/const.py +++ b/frigate/const.py @@ -111,6 +111,7 @@ UPSERT_REVIEW_SEGMENT = "upsert_review_segment" CLEAR_ONGOING_REVIEW_SEGMENTS = "clear_ongoing_review_segments" UPDATE_CAMERA_ACTIVITY = "update_camera_activity" UPDATE_EVENT_DESCRIPTION = "update_event_description" +UPDATE_REVIEW_DESCRIPTION = "update_review_description" UPDATE_MODEL_STATE = "update_model_state" UPDATE_EMBEDDINGS_REINDEX_PROGRESS = "handle_embeddings_reindex_progress" UPDATE_BIRDSEYE_LAYOUT = "update_birdseye_layout" diff --git a/frigate/data_processing/post/review_descriptions.py b/frigate/data_processing/post/review_descriptions.py index 0c21e100c..f9f359df4 100644 --- a/frigate/data_processing/post/review_descriptions.py +++ b/frigate/data_processing/post/review_descriptions.py @@ -10,19 +10,29 @@ from pathlib import Path import cv2 +from frigate.comms.inter_process import InterProcessRequestor from frigate.config import FrigateConfig -from frigate.const import CLIPS_DIR +from frigate.const import CLIPS_DIR, UPDATE_REVIEW_DESCRIPTION from frigate.data_processing.types import PostProcessDataEnum from frigate.genai import GenAIClient from ..post.api import PostProcessorApi +from ..types import DataProcessorMetrics logger = logging.getLogger(__name__) class ReviewDescriptionProcessor(PostProcessorApi): - def __init__(self, config: FrigateConfig, metrics, client: GenAIClient): + def __init__( + self, + config: FrigateConfig, + requestor: InterProcessRequestor, + metrics: DataProcessorMetrics, + client: GenAIClient, + ): super().__init__(config, metrics, None) + self.requestor = requestor + self.metrics = metrics self.tracked_review_items: dict[str, list[tuple[int, bytes]]] = {} self.genai_client = client @@ -108,6 +118,7 @@ class ReviewDescriptionProcessor(PostProcessorApi): @staticmethod def run_analysis( + requestor: InterProcessRequestor, genai_client: GenAIClient, camera: str, final_data: dict[str, str], @@ -126,3 +137,14 @@ def run_analysis( if not metadata: return None + + prev_data = copy.deepcopy(final_data) + final_data["data"]["metadata"] = metadata.model_dump_json() + requestor.send_data( + UPDATE_REVIEW_DESCRIPTION, + { + "type": "end", + "before": {k: v for k, v in prev_data.items()}, + "after": {k: v for k, v in final_data.items()}, + }, + )