mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-02-16 17:34:47 -06:00
Add ability to restrict genai to objects and zones at the camera level (#13958)
* Add ability to restrict genai to labels and zones at the camera level * fix comment * clarify docs * use objects instead of labels * docs * object list
This commit is contained in:
parent
e935db5075
commit
4c12673fbb
@ -128,7 +128,7 @@ genai:
|
||||
car: "Label the primary vehicle in these images with just the name of the company if it is a delivery vehicle, or the color make and model."
|
||||
```
|
||||
|
||||
Prompts can also be overriden at the camera level to provide a more detailed prompt to the model about your specific camera, if you desire.
|
||||
Prompts can also be overriden at the camera level to provide a more detailed prompt to the model about your specific camera, if you desire. By default, descriptions will be generated for all tracked objects and all zones. But you can also optionally specify `objects` and `required_zones` to only generate descriptions for certain tracked objects or zones.
|
||||
|
||||
```yaml
|
||||
cameras:
|
||||
@ -138,6 +138,11 @@ cameras:
|
||||
object_prompts:
|
||||
person: "Describe the main person in these images (gender, age, clothing, activity, etc). Do not include where the activity is occurring (sidewalk, concrete, driveway, etc). If delivering a package, include the company the package is from."
|
||||
cat: "Describe the cat in these images (color, size, tail). Indicate whether or not the cat is by the flower pots. If the cat is chasing a mouse, make up a name for the mouse."
|
||||
objects:
|
||||
- person
|
||||
- cat
|
||||
required_zones:
|
||||
- steps
|
||||
```
|
||||
|
||||
### Experiment with prompts
|
||||
|
@ -723,6 +723,12 @@ cameras:
|
||||
# Format: {label}: {prompt}
|
||||
object_prompts:
|
||||
person: "My special person prompt."
|
||||
# Optional: objects to generate descriptions for (default: all objects that are tracked)
|
||||
objects:
|
||||
- person
|
||||
- cat
|
||||
# Optional: Restrict generation to objects that entered any of the listed zones (default: none, all zones qualify)
|
||||
required_zones: []
|
||||
|
||||
# Optional
|
||||
ui:
|
||||
|
@ -810,6 +810,22 @@ class GenAICameraConfig(BaseModel):
|
||||
title="Default caption prompt.",
|
||||
)
|
||||
object_prompts: Dict[str, str] = Field(default={}, title="Object specific prompts.")
|
||||
objects: Union[str, List[str]] = Field(
|
||||
default_factory=list,
|
||||
title="List of objects to run generative AI for.",
|
||||
)
|
||||
required_zones: Union[str, List[str]] = Field(
|
||||
default_factory=list,
|
||||
title="List of required zones to be entered in order to run generative AI.",
|
||||
)
|
||||
|
||||
@field_validator("required_zones", mode="before")
|
||||
@classmethod
|
||||
def validate_required_zones(cls, v):
|
||||
if isinstance(v, str) and "," not in v:
|
||||
return [v]
|
||||
|
||||
return v
|
||||
|
||||
|
||||
class AudioConfig(FrigateBaseModel):
|
||||
|
@ -127,6 +127,14 @@ class EmbeddingMaintainer(threading.Thread):
|
||||
camera_config.genai.enabled
|
||||
and self.genai_client is not None
|
||||
and event.data.get("description") is None
|
||||
and (
|
||||
camera_config.genai.objects is None
|
||||
or event.label in camera_config.genai.objects
|
||||
)
|
||||
and (
|
||||
camera_config.genai.required_zones is None
|
||||
or set(event.zones) & set(camera_config.genai.required_zones)
|
||||
)
|
||||
):
|
||||
# Generate the description. Call happens in a thread since it is network bound.
|
||||
threading.Thread(
|
||||
|
@ -306,6 +306,8 @@ export interface FrigateConfig {
|
||||
model: string;
|
||||
prompt: string;
|
||||
object_prompts: { [key: string]: string };
|
||||
required_zones: string[];
|
||||
objects: string[];
|
||||
};
|
||||
|
||||
go2rtc: {
|
||||
|
Loading…
Reference in New Issue
Block a user