mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-27 17:17:40 +03:00
Add preferred language config
This commit is contained in:
parent
c1599e39c0
commit
acfbd5d76d
@ -80,6 +80,10 @@ class GenAIReviewConfig(FrigateBaseModel):
|
||||
enabled_in_config: Optional[bool] = Field(
|
||||
default=None, title="Keep track of original state of generative AI."
|
||||
)
|
||||
preferred_language: str | None = Field(
|
||||
title="Preferred language for GenAI Response",
|
||||
default=None,
|
||||
)
|
||||
|
||||
|
||||
class ReviewConfig(FrigateBaseModel):
|
||||
|
||||
@ -112,6 +112,7 @@ class ReviewDescriptionProcessor(PostProcessorApi):
|
||||
final_data,
|
||||
thumbs,
|
||||
camera_config.review.genai.additional_concerns,
|
||||
camera_config.review.genai.preferred_language,
|
||||
),
|
||||
).start()
|
||||
|
||||
@ -162,6 +163,7 @@ def run_analysis(
|
||||
final_data: dict[str, str],
|
||||
thumbs: list[bytes],
|
||||
concerns: list[str],
|
||||
preferred_language: str | None,
|
||||
) -> None:
|
||||
start = datetime.datetime.now().timestamp()
|
||||
metadata = genai_client.generate_review_description(
|
||||
@ -174,6 +176,7 @@ def run_analysis(
|
||||
},
|
||||
thumbs,
|
||||
concerns,
|
||||
preferred_language,
|
||||
)
|
||||
review_inference_speed.update(datetime.datetime.now().timestamp() - start)
|
||||
|
||||
|
||||
@ -41,17 +41,23 @@ class GenAIClient:
|
||||
review_data: dict[str, Any],
|
||||
thumbnails: list[bytes],
|
||||
concerns: list[str],
|
||||
preferred_language: str | None,
|
||||
) -> ReviewMetadata | None:
|
||||
"""Generate a description for the review item activity."""
|
||||
if concerns:
|
||||
concern_list = "\n - ".join(concerns)
|
||||
other_concerns = f"""
|
||||
concern_prompt = f"""
|
||||
- `other_concerns` (list of strings): Include a list of any of the following concerns that are occurring:
|
||||
- {concern_list}
|
||||
"""
|
||||
|
||||
else:
|
||||
other_concerns = None
|
||||
concern_prompt = ""
|
||||
|
||||
if preferred_language:
|
||||
language_prompt = f"Provide your answer in {preferred_language}"
|
||||
else:
|
||||
language_prompt = ""
|
||||
|
||||
context_prompt = f"""
|
||||
Please analyze the image(s), which are in chronological order, strictly from the perspective of the {review_data["camera"].replace("_", " ")} security camera.
|
||||
@ -80,10 +86,11 @@ Your response **MUST** be a flat JSON object with:
|
||||
- 1 = Unusual but not overtly threatening
|
||||
- 2 = Suspicious or potentially harmful
|
||||
- 3 = Clear and immediate threat
|
||||
{other_concerns}
|
||||
{concern_prompt}
|
||||
|
||||
**IMPORTANT:**
|
||||
- Values must be plain strings, floats, or integers — no nested objects, no extra commentary.
|
||||
{language_prompt}
|
||||
"""
|
||||
logger.debug(
|
||||
f"Sending {len(thumbnails)} images to create review description on {review_data['camera']}"
|
||||
|
||||
@ -76,10 +76,6 @@ export default function ReviewDetailDialog({
|
||||
const aiAnalysis = useMemo(() => review?.data?.metadata, [review]);
|
||||
|
||||
const aiThreatLevel = useMemo(() => {
|
||||
console.log(
|
||||
`${aiAnalysis?.potential_threat_level} || ${aiAnalysis?.other_concerns}`,
|
||||
);
|
||||
|
||||
if (
|
||||
!aiAnalysis ||
|
||||
(!aiAnalysis.potential_threat_level && !aiAnalysis.other_concerns)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user