feat: enable using GenAI for cameras with GenAI disabled from the API (#18616)

This commit is contained in:
FL42 2025-06-07 20:43:29 +02:00 committed by GitHub
parent ab7b12da54
commit 76201c0c7f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 19 additions and 8 deletions

View File

@ -9,7 +9,7 @@ Requests for a description are sent off automatically to your AI provider at the
## Configuration
Generative AI can be enabled for all cameras or only for specific cameras. There are currently 3 native providers available to integrate with Frigate. Other providers that support the OpenAI standard API can also be used. See the OpenAI section below.
Generative AI can be enabled for all cameras or only for specific cameras. If GenAI is disabled for a camera, you can still manually generate descriptions for events using the HTTP API. There are currently 3 native providers available to integrate with Frigate. Other providers that support the OpenAI standard API can also be used. See the OpenAI section below.
To use Generative AI, you must define a single provider at the global level of your Frigate configuration. If the provider you choose requires an API key, you may either directly paste it in your configuration, or store it in an environment variable prefixed with `FRIGATE_`.

View File

@ -1,9 +1,13 @@
from typing import Optional
from pydantic import BaseModel
from pydantic import BaseModel, Field
from frigate.events.types import RegenerateDescriptionEnum
class RegenerateQueryParameters(BaseModel):
source: Optional[RegenerateDescriptionEnum] = RegenerateDescriptionEnum.thumbnails
force: Optional[bool] = Field(
default=False,
description="Force (re)generating the description even if GenAI is disabled for this camera.",
)

View File

@ -1225,9 +1225,10 @@ def regenerate_description(
camera_config = request.app.frigate_config.cameras[event.camera]
if camera_config.genai.enabled:
if camera_config.genai.enabled or params.force:
request.app.event_metadata_updater.publish(
EventMetadataTypeEnum.regenerate_description, (event.id, params.source)
EventMetadataTypeEnum.regenerate_description,
(event.id, params.source, params.force),
)
return JSONResponse(

View File

@ -473,11 +473,11 @@ class EmbeddingMaintainer(threading.Thread):
if topic is None:
return
event_id, source = payload
event_id, source, force = payload
if event_id:
self.handle_regenerate_description(
event_id, RegenerateDescriptionEnum(source)
event_id, RegenerateDescriptionEnum(source), force
)
def _process_frame_updates(self) -> None:
@ -678,15 +678,21 @@ class EmbeddingMaintainer(threading.Thread):
except Exception:
return None
def handle_regenerate_description(self, event_id: str, source: str) -> None:
def handle_regenerate_description(
self, event_id: str, source: str, force: bool
) -> None:
try:
event: Event = Event.get(Event.id == event_id)
except DoesNotExist:
logger.error(f"Event {event_id} not found for description regeneration")
return
if self.genai_client is None:
logger.error("GenAI not enabled")
return
camera_config = self.config.cameras[event.camera]
if not camera_config.genai.enabled or self.genai_client is None:
if not camera_config.genai.enabled and not force:
logger.error(f"GenAI not enabled for camera {event.camera}")
return