Compare commits

..

5 Commits

Author SHA1 Message Date
Nicolas Mowen
bbe18d5d6b Don't show admin action buttons on export card 2025-12-04 10:32:45 -07:00
Nicolas Mowen
b3abede6cb Remove examples 2025-12-04 09:50:25 -07:00
Nicolas Mowen
7544d9caf8 More improvements to prompt 2025-12-04 09:18:29 -07:00
Nicolas Mowen
eb75c76ed4 Formatting and prompt improvements for review summary report 2025-12-04 09:09:06 -07:00
Nicolas Mowen
12e5f274dd Use contextual information from other cameras to inform report summary 2025-12-04 09:00:37 -07:00
3 changed files with 122 additions and 39 deletions

View File

@ -209,10 +209,22 @@ class ReviewDescriptionProcessor(PostProcessorApi):
logger.debug(
f"Found GenAI Review Summary request for {start_ts} to {end_ts}"
)
items: list[dict[str, Any]] = [
r["data"]["metadata"]
# Query all review segments with camera and time information
segments: list[dict[str, Any]] = [
{
"camera": r["camera"].replace("_", " ").title(),
"start_time": r["start_time"],
"end_time": r["end_time"],
"metadata": r["data"]["metadata"],
}
for r in (
ReviewSegment.select(ReviewSegment.data)
ReviewSegment.select(
ReviewSegment.camera,
ReviewSegment.start_time,
ReviewSegment.end_time,
ReviewSegment.data,
)
.where(
(ReviewSegment.data["metadata"].is_null(False))
& (ReviewSegment.start_time < end_ts)
@ -224,21 +236,66 @@ class ReviewDescriptionProcessor(PostProcessorApi):
)
]
if len(items) == 0:
if len(segments) == 0:
logger.debug("No review items with metadata found during time period")
return "No activity was found during this time."
return "No activity was found during this time period."
important_items = list(
filter(
lambda item: item.get("potential_threat_level", 0) > 0
or item.get("other_concerns"),
items,
)
)
# Identify primary items (important items that need review)
primary_segments = [
seg
for seg in segments
if seg["metadata"].get("potential_threat_level", 0) > 0
or seg["metadata"].get("other_concerns")
]
if not important_items:
if not primary_segments:
return "No concerns were found during this time period."
# For each primary segment, find overlapping contextual items from other cameras
all_items_for_summary = []
for primary_seg in primary_segments:
# Add the primary item with marker
primary_item = copy.deepcopy(primary_seg["metadata"])
primary_item["_is_primary"] = True
primary_item["_camera"] = primary_seg["camera"]
all_items_for_summary.append(primary_item)
# Find overlapping contextual items from other cameras
primary_start = primary_seg["start_time"]
primary_end = primary_seg["end_time"]
primary_camera = primary_seg["camera"]
for seg in segments:
seg_camera = seg["camera"]
if seg_camera == primary_camera:
continue
if seg in primary_segments:
continue
seg_start = seg["start_time"]
seg_end = seg["end_time"]
if seg_start < primary_end and primary_start < seg_end:
contextual_item = copy.deepcopy(seg["metadata"])
contextual_item["_is_primary"] = False
contextual_item["_camera"] = seg_camera
contextual_item["_related_to_camera"] = primary_camera
if not any(
item.get("_camera") == seg_camera
and item.get("time") == contextual_item.get("time")
for item in all_items_for_summary
):
all_items_for_summary.append(contextual_item)
logger.debug(
f"Summary includes {len(primary_segments)} primary items and "
f"{len(all_items_for_summary) - len(primary_segments)} contextual items"
)
if self.config.review.genai.debug_save_thumbnails:
Path(
os.path.join(CLIPS_DIR, "genai-requests", f"{start_ts}-{end_ts}")
@ -247,7 +304,7 @@ class ReviewDescriptionProcessor(PostProcessorApi):
return self.genai_client.generate_review_summary(
start_ts,
end_ts,
important_items,
all_items_for_summary,
self.config.review.genai.debug_save_thumbnails,
)
else:

View File

@ -185,44 +185,66 @@ Each line represents a detection state, not necessarily unique individuals. Pare
timeline_summary_prompt = f"""
You are a security officer.
Time range: {time_range}.
Input: JSON list with "title", "scene", "confidence", "potential_threat_level" (1-2), "other_concerns".
Input: JSON list with "title", "scene", "confidence", "potential_threat_level" (0-2), "other_concerns", "_is_primary", "_camera".
Task: Write a concise, human-presentable security report in markdown format.
CRITICAL - Understanding Primary vs Contextual Items:
- Items with "_is_primary": true are events that REQUIRE REVIEW and MUST be included in the report
- Items with "_is_primary": false are additional context from other camera perspectives that overlap in time
- **DO NOT create separate bullet points or sections for contextual items**
- **ONLY use contextual items to enrich and inform the description of primary items**
- The "_camera" field indicates which camera captured each event
- **When a contextual item provides relevant background, you MUST incorporate it directly into the primary event's bullet point**
- Contextual information often explains or de-escalates seemingly suspicious primary events
Rules for the report:
- Title & overview
- Start with:
# Security Summary - {time_range}
- Write a 1-2 sentence situational overview capturing the general pattern of the period.
- Keep the overview high-level; specific details will be in the event bullets below.
- Event details
- Present events in chronological order as a bullet list.
- **If multiple events occur within the same minute or overlapping time range, COMBINE them into a single bullet.**
- Summarize the distinct activities as sub-points under the shared timestamp.
- If no timestamp is given, preserve order but label as Time not specified.
- **ONLY create bullet points for PRIMARY items (_is_primary: true)**
- **Do NOT create sections or bullets for events that don't exist**
- Do NOT create separate bullets for contextual items
- Present primary events in chronological order as a bullet list.
- **CRITICAL: When contextual items overlap with a primary event, you MUST weave that information directly into the same bullet point**
- Format: **[Timestamp]** - [Description incorporating any contextual information]. [Camera info]. (threat level: X)
- If contextual information provides an explanation (e.g., delivery truck person is likely delivery driver), reflect this understanding in your description and potentially adjust the perceived threat level
- If multiple PRIMARY events occur within the same minute, combine them into a single bullet with sub-points.
- Use bold timestamps for clarity.
- Group bullets under subheadings when multiple events fall into the same category (e.g., Vehicle Activity, Porch Activity, Unusual Behavior).
- Camera format: "Camera: [camera name]" or mention contextual cameras inline when relevant
- Group bullets under subheadings ONLY when you have actual PRIMARY events to list (e.g., Porch Activity, Unusual Behavior).
- Threat levels
- Always show the threat level for each event using these labels:
- Show the threat level for PRIMARY events using these labels:
- Threat level 0: "Normal"
- Threat level 1: "Needs review"
- Threat level 2: "Security concern"
- Format as (threat level: Normal), (threat level: Needs review), or (threat level: Security concern).
- If multiple events at the same time share the same threat level, only state it once.
- **When contextual items clearly explain a primary event (e.g., delivery truck explains person at door), you should describe it as normal activity and note the explanation**
- **Your description and tone should reflect the fuller understanding provided by contextual information**
- Example: Primary event says "unidentified person with face covering" but context shows delivery truck describe as "delivery person (truck visible on Front Driveway Cam)" rather than emphasizing suspicious elements
- The stored threat level remains as originally classified, but your narrative should reflect the contextual understanding
- If multiple PRIMARY events at the same time share the same threat level, only state it once.
- Final assessment
- End with a Final Assessment section.
- If all events are threat level 0:
- If all primary events are threat level 0 or explained by contextual items:
Final assessment: Only normal residential activity observed during this period.
- If threat level 1 events are present:
Final assessment: Some activity requires review but no security concerns identified.
- If threat level 2 events are present, clearly summarize them as Security concerns requiring immediate attention.
- Keep this section brief - do not repeat details from the event descriptions above.
- Conciseness
- Do not repeat benign clothing/appearance details unless they distinguish individuals.
- Summarize similar routine events instead of restating full scene descriptions.
- When incorporating contextual information, do so briefly and naturally within the primary event description.
- Avoid lengthy explanatory notes - integrate context seamlessly into the narrative.
"""
for item in segments:

View File

@ -23,6 +23,7 @@ import { useTranslation } from "react-i18next";
import { ImageShadowOverlay } from "../overlay/ImageShadowOverlay";
import BlurredIconButton from "../button/BlurredIconButton";
import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip";
import { useIsAdmin } from "@/hooks/use-is-admin";
type ExportProps = {
className: string;
@ -40,6 +41,7 @@ export default function ExportCard({
onDelete,
}: ExportProps) {
const { t } = useTranslation(["views/exports"]);
const isAdmin = useIsAdmin();
const [hovered, setHovered] = useState(false);
const [loading, setLoading] = useState(
exportedRecording.thumb_path.length > 0,
@ -195,7 +197,7 @@ export default function ExportCard({
</Tooltip>
</a>
)}
{!exportedRecording.in_progress && (
{isAdmin && !exportedRecording.in_progress && (
<Tooltip>
<TooltipTrigger asChild>
<BlurredIconButton
@ -212,6 +214,7 @@ export default function ExportCard({
<TooltipContent>{t("tooltip.editName")}</TooltipContent>
</Tooltip>
)}
{isAdmin && (
<Tooltip>
<TooltipTrigger asChild>
<BlurredIconButton
@ -227,6 +230,7 @@ export default function ExportCard({
</TooltipTrigger>
<TooltipContent>{t("tooltip.deleteExport")}</TooltipContent>
</Tooltip>
)}
</div>
</div>