mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-30 18:47: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(
|
enabled_in_config: Optional[bool] = Field(
|
||||||
default=None, title="Keep track of original state of generative AI."
|
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):
|
class ReviewConfig(FrigateBaseModel):
|
||||||
|
|||||||
@ -112,6 +112,7 @@ class ReviewDescriptionProcessor(PostProcessorApi):
|
|||||||
final_data,
|
final_data,
|
||||||
thumbs,
|
thumbs,
|
||||||
camera_config.review.genai.additional_concerns,
|
camera_config.review.genai.additional_concerns,
|
||||||
|
camera_config.review.genai.preferred_language,
|
||||||
),
|
),
|
||||||
).start()
|
).start()
|
||||||
|
|
||||||
@ -162,6 +163,7 @@ def run_analysis(
|
|||||||
final_data: dict[str, str],
|
final_data: dict[str, str],
|
||||||
thumbs: list[bytes],
|
thumbs: list[bytes],
|
||||||
concerns: list[str],
|
concerns: list[str],
|
||||||
|
preferred_language: str | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
start = datetime.datetime.now().timestamp()
|
start = datetime.datetime.now().timestamp()
|
||||||
metadata = genai_client.generate_review_description(
|
metadata = genai_client.generate_review_description(
|
||||||
@ -174,6 +176,7 @@ def run_analysis(
|
|||||||
},
|
},
|
||||||
thumbs,
|
thumbs,
|
||||||
concerns,
|
concerns,
|
||||||
|
preferred_language,
|
||||||
)
|
)
|
||||||
review_inference_speed.update(datetime.datetime.now().timestamp() - start)
|
review_inference_speed.update(datetime.datetime.now().timestamp() - start)
|
||||||
|
|
||||||
|
|||||||
@ -41,17 +41,23 @@ class GenAIClient:
|
|||||||
review_data: dict[str, Any],
|
review_data: dict[str, Any],
|
||||||
thumbnails: list[bytes],
|
thumbnails: list[bytes],
|
||||||
concerns: list[str],
|
concerns: list[str],
|
||||||
|
preferred_language: str | None,
|
||||||
) -> ReviewMetadata | None:
|
) -> ReviewMetadata | None:
|
||||||
"""Generate a description for the review item activity."""
|
"""Generate a description for the review item activity."""
|
||||||
if concerns:
|
if concerns:
|
||||||
concern_list = "\n - ".join(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:
|
- `other_concerns` (list of strings): Include a list of any of the following concerns that are occurring:
|
||||||
- {concern_list}
|
- {concern_list}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
else:
|
else:
|
||||||
other_concerns = None
|
concern_prompt = ""
|
||||||
|
|
||||||
|
if preferred_language:
|
||||||
|
language_prompt = f"Provide your answer in {preferred_language}"
|
||||||
|
else:
|
||||||
|
language_prompt = ""
|
||||||
|
|
||||||
context_prompt = f"""
|
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.
|
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
|
- 1 = Unusual but not overtly threatening
|
||||||
- 2 = Suspicious or potentially harmful
|
- 2 = Suspicious or potentially harmful
|
||||||
- 3 = Clear and immediate threat
|
- 3 = Clear and immediate threat
|
||||||
{other_concerns}
|
{concern_prompt}
|
||||||
|
|
||||||
**IMPORTANT:**
|
**IMPORTANT:**
|
||||||
- Values must be plain strings, floats, or integers — no nested objects, no extra commentary.
|
- Values must be plain strings, floats, or integers — no nested objects, no extra commentary.
|
||||||
|
{language_prompt}
|
||||||
"""
|
"""
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"Sending {len(thumbnails)} images to create review description on {review_data['camera']}"
|
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 aiAnalysis = useMemo(() => review?.data?.metadata, [review]);
|
||||||
|
|
||||||
const aiThreatLevel = useMemo(() => {
|
const aiThreatLevel = useMemo(() => {
|
||||||
console.log(
|
|
||||||
`${aiAnalysis?.potential_threat_level} || ${aiAnalysis?.other_concerns}`,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!aiAnalysis ||
|
!aiAnalysis ||
|
||||||
(!aiAnalysis.potential_threat_level && !aiAnalysis.other_concerns)
|
(!aiAnalysis.potential_threat_level && !aiAnalysis.other_concerns)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user