mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-10-19 13:12:48 +03:00
CI / AMD64 Build (push) Canceled after 0s
CI / AMD64 Smoke Test (push) Canceled after 0s
CI / ARM Build (push) Canceled after 0s
CI / Jetson Jetpack 6 (push) Canceled after 0s
CI / AMD64 Extra Build (push) Canceled after 0s
CI / ARM Extra Build (push) Canceled after 0s
CI / Synaptics Build (push) Canceled after 0s
CI / Assemble and push default build (push) Canceled after 0s
go2rtc's create_config.py imported frigate.config.env, which ran the frigate.config package init and loaded every detector plugin. Since the onnxruntime 1.30 bump, importing onnxruntime takes about 5s on some hosts, so go2rtc started after Frigate's cameras and every ffmpeg process failed to connect to the restream until it came up. The env helpers now live in frigate.util.env, so go2rtc's config script no longer imports onnxruntime.
95 lines
3.1 KiB
Python
95 lines
3.1 KiB
Python
from enum import Enum
|
|
from typing import Any, Self
|
|
|
|
from pydantic import Field, model_validator
|
|
|
|
from frigate.util.env import EnvString
|
|
|
|
from ..base import FrigateBaseModel
|
|
|
|
__all__ = ["GenAIConfig", "GenAIProviderEnum", "GenAIRoleEnum"]
|
|
|
|
|
|
class GenAIProviderEnum(str, Enum):
|
|
openai = "openai"
|
|
azure_openai = "azure_openai"
|
|
gemini = "gemini"
|
|
ollama = "ollama"
|
|
llamacpp = "llamacpp"
|
|
|
|
|
|
class GenAIRoleEnum(str, Enum):
|
|
chat = "chat"
|
|
descriptions = "descriptions"
|
|
embeddings = "embeddings"
|
|
transcribe = "transcribe"
|
|
|
|
|
|
# Providers that can accept audio input for the transcribe role. Ollama has no
|
|
# audio input support, so claiming the role there would fail at request time.
|
|
TRANSCRIBE_CAPABLE_PROVIDERS = {
|
|
GenAIProviderEnum.openai,
|
|
GenAIProviderEnum.azure_openai,
|
|
GenAIProviderEnum.gemini,
|
|
GenAIProviderEnum.llamacpp,
|
|
}
|
|
|
|
|
|
class GenAIConfig(FrigateBaseModel):
|
|
"""Primary GenAI Config to define GenAI Provider."""
|
|
|
|
api_key: EnvString | None = Field(
|
|
default=None,
|
|
title="API key",
|
|
description="API key required by some providers (can also be set via environment variables).",
|
|
)
|
|
base_url: str | None = Field(
|
|
default=None,
|
|
title="Base URL",
|
|
description="Base URL for self-hosted or compatible providers (for example an Ollama instance).",
|
|
)
|
|
model: str = Field(
|
|
default="",
|
|
title="Model",
|
|
description="The model to use from the provider for generating descriptions or summaries.",
|
|
)
|
|
provider: GenAIProviderEnum = Field(
|
|
title="Provider",
|
|
description="The GenAI provider to use (for example: ollama, gemini, openai).",
|
|
)
|
|
roles: list[GenAIRoleEnum] = Field(
|
|
default_factory=lambda: [
|
|
GenAIRoleEnum.embeddings,
|
|
GenAIRoleEnum.descriptions,
|
|
GenAIRoleEnum.chat,
|
|
],
|
|
title="Roles",
|
|
description="GenAI roles (chat, descriptions, embeddings, transcribe); one provider per role. Only chat, descriptions, and embeddings are granted by default; transcribe must be listed explicitly.",
|
|
)
|
|
provider_options: dict[str, Any] = Field(
|
|
default={},
|
|
title="Provider options",
|
|
description="Additional provider-specific options to pass to the GenAI client.",
|
|
json_schema_extra={"additionalProperties": {}},
|
|
)
|
|
runtime_options: dict[str, Any] = Field(
|
|
default={},
|
|
title="Runtime options",
|
|
description="Runtime options passed to the provider for each inference call.",
|
|
json_schema_extra={"additionalProperties": {}},
|
|
)
|
|
|
|
@model_validator(mode="after")
|
|
def validate_transcribe_provider(self) -> Self:
|
|
"""Reject the transcribe role on providers that cannot accept audio input."""
|
|
if (
|
|
GenAIRoleEnum.transcribe in self.roles
|
|
and self.provider not in TRANSCRIBE_CAPABLE_PROVIDERS
|
|
):
|
|
raise ValueError(
|
|
f"GenAI provider '{self.provider.value}' does not support audio input "
|
|
"and cannot be given the 'transcribe' role."
|
|
)
|
|
|
|
return self
|