2024-09-28 22:21:42 +03:00
|
|
|
from enum import Enum
|
2025-08-13 18:28:01 +03:00
|
|
|
from typing import Any, Optional
|
2024-09-28 22:21:42 +03:00
|
|
|
|
2025-08-09 01:33:11 +03:00
|
|
|
from pydantic import Field
|
2024-09-28 22:21:42 +03:00
|
|
|
|
|
|
|
|
from ..base import FrigateBaseModel
|
|
|
|
|
from ..env import EnvString
|
|
|
|
|
|
2026-02-27 18:35:33 +03:00
|
|
|
__all__ = ["GenAIConfig", "GenAIProviderEnum", "GenAIRoleEnum"]
|
2024-09-28 22:21:42 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class GenAIProviderEnum(str, Enum):
|
|
|
|
|
openai = "openai"
|
2024-10-01 22:57:40 +03:00
|
|
|
azure_openai = "azure_openai"
|
2024-09-28 22:21:42 +03:00
|
|
|
gemini = "gemini"
|
|
|
|
|
ollama = "ollama"
|
2026-01-18 16:34:30 +03:00
|
|
|
llamacpp = "llamacpp"
|
2024-09-28 22:21:42 +03:00
|
|
|
|
|
|
|
|
|
2026-02-27 18:35:33 +03:00
|
|
|
class GenAIRoleEnum(str, Enum):
|
2026-04-04 02:13:52 +03:00
|
|
|
chat = "chat"
|
|
|
|
|
descriptions = "descriptions"
|
2026-02-27 18:35:33 +03:00
|
|
|
embeddings = "embeddings"
|
|
|
|
|
|
|
|
|
|
|
2024-09-28 22:21:42 +03:00
|
|
|
class GenAIConfig(FrigateBaseModel):
|
2025-08-09 01:33:11 +03:00
|
|
|
"""Primary GenAI Config to define GenAI Provider."""
|
2024-09-28 22:21:42 +03:00
|
|
|
|
2026-02-27 18:35:33 +03:00
|
|
|
api_key: Optional[EnvString] = Field(
|
|
|
|
|
default=None,
|
|
|
|
|
title="API key",
|
|
|
|
|
description="API key required by some providers (can also be set via environment variables).",
|
|
|
|
|
)
|
|
|
|
|
base_url: Optional[str] = Field(
|
|
|
|
|
default=None,
|
|
|
|
|
title="Base URL",
|
|
|
|
|
description="Base URL for self-hosted or compatible providers (for example an Ollama instance).",
|
|
|
|
|
)
|
|
|
|
|
model: str = Field(
|
|
|
|
|
default="gpt-4o",
|
|
|
|
|
title="Model",
|
|
|
|
|
description="The model to use from the provider for generating descriptions or summaries.",
|
|
|
|
|
)
|
|
|
|
|
provider: GenAIProviderEnum | None = Field(
|
|
|
|
|
default=None,
|
|
|
|
|
title="Provider",
|
|
|
|
|
description="The GenAI provider to use (for example: ollama, gemini, openai).",
|
|
|
|
|
)
|
|
|
|
|
roles: list[GenAIRoleEnum] = Field(
|
|
|
|
|
default_factory=lambda: [
|
|
|
|
|
GenAIRoleEnum.embeddings,
|
2026-04-04 02:13:52 +03:00
|
|
|
GenAIRoleEnum.descriptions,
|
|
|
|
|
GenAIRoleEnum.chat,
|
2026-02-27 18:35:33 +03:00
|
|
|
],
|
|
|
|
|
title="Roles",
|
2026-04-04 02:13:52 +03:00
|
|
|
description="GenAI roles (chat, descriptions, embeddings); one provider per role.",
|
2026-02-27 18:35:33 +03:00
|
|
|
)
|
2025-08-13 18:28:01 +03:00
|
|
|
provider_options: dict[str, Any] = Field(
|
2026-02-27 18:35:33 +03:00
|
|
|
default={},
|
|
|
|
|
title="Provider options",
|
|
|
|
|
description="Additional provider-specific options to pass to the GenAI client.",
|
2026-04-04 15:54:51 +03:00
|
|
|
json_schema_extra={"additionalProperties": {}},
|
2026-02-27 18:35:33 +03:00
|
|
|
)
|
|
|
|
|
runtime_options: dict[str, Any] = Field(
|
|
|
|
|
default={},
|
|
|
|
|
title="Runtime options",
|
|
|
|
|
description="Runtime options passed to the provider for each inference call.",
|
2026-04-04 15:54:51 +03:00
|
|
|
json_schema_extra={"additionalProperties": {}},
|
2025-08-13 18:28:01 +03:00
|
|
|
)
|