From 143bab87f15dd162d5526ea006d0522de986e488 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Sat, 9 Nov 2024 07:48:53 -0600 Subject: [PATCH] Genai bugfix (#14880) * Fix genai init when disabled at global level * use genai config for class init --- frigate/embeddings/maintainer.py | 2 +- frigate/genai/__init__.py | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/frigate/embeddings/maintainer.py b/frigate/embeddings/maintainer.py index 1578a0fe3..12c8bac72 100644 --- a/frigate/embeddings/maintainer.py +++ b/frigate/embeddings/maintainer.py @@ -62,7 +62,7 @@ class EmbeddingMaintainer(threading.Thread): self.requestor = InterProcessRequestor() self.stop_event = stop_event self.tracked_events = {} - self.genai_client = get_genai_client(config.genai) + self.genai_client = get_genai_client(config) def run(self) -> None: """Maintain a SQLite-vec database for semantic search.""" diff --git a/frigate/genai/__init__.py b/frigate/genai/__init__.py index 74fae9fea..ebbea7476 100644 --- a/frigate/genai/__init__.py +++ b/frigate/genai/__init__.py @@ -6,7 +6,7 @@ from typing import Optional from playhouse.shortcuts import model_to_dict -from frigate.config import CameraConfig, GenAIConfig, GenAIProviderEnum +from frigate.config import CameraConfig, FrigateConfig, GenAIConfig, GenAIProviderEnum from frigate.models import Event PROVIDERS = {} @@ -52,12 +52,19 @@ class GenAIClient: return None -def get_genai_client(genai_config: GenAIConfig) -> Optional[GenAIClient]: +def get_genai_client(config: FrigateConfig) -> Optional[GenAIClient]: """Get the GenAI client.""" - load_providers() - provider = PROVIDERS.get(genai_config.provider) - if provider: - return provider(genai_config) + genai_config = config.genai + genai_cameras = [ + c for c in config.cameras.values() if c.enabled and c.genai.enabled + ] + + if genai_cameras: + load_providers() + provider = PROVIDERS.get(genai_config.provider) + if provider: + return provider(genai_config) + return None