mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-07-03 18:41:14 +03:00
Compare commits
3 Commits
e281736773
...
56bb87c248
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
56bb87c248 | ||
|
|
32e433cafc | ||
|
|
8ea5eb6bd1 |
@ -5,6 +5,7 @@ import json
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
from typing import Any, AsyncGenerator, Callable, Optional
|
||||
|
||||
import numpy as np
|
||||
@ -50,6 +51,10 @@ def register_genai_provider(key: GenAIProviderEnum) -> Callable:
|
||||
class GenAIClient:
|
||||
"""Generative AI client for Frigate."""
|
||||
|
||||
# Minimum seconds between re-initialization attempts when the provider was
|
||||
# offline at startup
|
||||
REINIT_INTERVAL = 60.0
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
genai_config: GenAIConfig,
|
||||
@ -60,6 +65,34 @@ class GenAIClient:
|
||||
self.timeout = timeout
|
||||
self.validate_model = validate_model
|
||||
self.provider = self._init_provider()
|
||||
self._last_init_attempt = time.monotonic()
|
||||
|
||||
def ensure_provider(self) -> bool:
|
||||
"""Ensure a provider is available, retrying initialization if needed.
|
||||
|
||||
Providers can fail to initialize at startup when their backing service
|
||||
isn't online yet (common when both are started together). This retries
|
||||
``_init_provider`` lazily — throttled to ``REINIT_INTERVAL`` — so the
|
||||
client recovers on its own once the service is reachable, without a
|
||||
config reload.
|
||||
|
||||
Returns True if a provider is available.
|
||||
"""
|
||||
if self.provider is not None:
|
||||
return True
|
||||
|
||||
now = time.monotonic()
|
||||
if now - self._last_init_attempt < self.REINIT_INTERVAL:
|
||||
return False
|
||||
|
||||
self._last_init_attempt = now
|
||||
self.provider = self._init_provider()
|
||||
if self.provider is not None:
|
||||
logger.info(
|
||||
"GenAI provider %s is now available",
|
||||
self.genai_config.provider,
|
||||
)
|
||||
return self.provider is not None
|
||||
|
||||
def generate_review_description(
|
||||
self,
|
||||
|
||||
@ -62,7 +62,9 @@ class GenAIClientManager:
|
||||
def _get_client(self, name: str) -> "Optional[GenAIClient]":
|
||||
"""Return the client for *name*, creating it on first access."""
|
||||
if name in self._clients:
|
||||
return self._clients[name]
|
||||
client = self._clients[name]
|
||||
client.ensure_provider()
|
||||
return client
|
||||
|
||||
from frigate.genai import PROVIDERS
|
||||
|
||||
@ -78,7 +80,7 @@ class GenAIClientManager:
|
||||
return None
|
||||
|
||||
try:
|
||||
client: "GenAIClient" = provider_cls(genai_cfg)
|
||||
client = provider_cls(genai_cfg)
|
||||
except Exception as e:
|
||||
logger.exception(
|
||||
"Failed to create GenAI client for provider %s: %s",
|
||||
|
||||
18
web/package-lock.json
generated
18
web/package-lock.json
generated
@ -49,7 +49,7 @@
|
||||
"framer-motion": "^12.38.0",
|
||||
"hls.js": "^1.6.15",
|
||||
"i18next": "^24.2.0",
|
||||
"i18next-http-backend": "^3.0.1",
|
||||
"i18next-http-backend": "^3.0.5",
|
||||
"idb-keyval": "^6.2.1",
|
||||
"immer": "^10.1.1",
|
||||
"js-yaml": "^4.1.1",
|
||||
@ -7013,12 +7013,12 @@
|
||||
}
|
||||
},
|
||||
"node_modules/cross-fetch": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-4.0.0.tgz",
|
||||
"integrity": "sha512-e4a5N8lVvuLgAWgnCrLr2PP0YyDOTHa9H/Rj54dirp61qXnNq46m82bRhNqIA5VccJtWBvPTFRV3TtvHUKPB1g==",
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-4.1.0.tgz",
|
||||
"integrity": "sha512-uKm5PU+MHTootlWEY+mZ4vvXoCn4fLQxT9dSc1sXVMSFkINTJVN8cAQROpwcKm8bJ/c7rgZVIBWzH5T78sNZZw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"node-fetch": "^2.6.12"
|
||||
"node-fetch": "^2.7.0"
|
||||
}
|
||||
},
|
||||
"node_modules/cross-spawn": {
|
||||
@ -8876,12 +8876,12 @@
|
||||
}
|
||||
},
|
||||
"node_modules/i18next-http-backend": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/i18next-http-backend/-/i18next-http-backend-3.0.1.tgz",
|
||||
"integrity": "sha512-XT2lYSkbAtDE55c6m7CtKxxrsfuRQO3rUfHzj8ZyRtY9CkIX3aRGwXGTkUhpGWce+J8n7sfu3J0f2wTzo7Lw0A==",
|
||||
"version": "3.0.5",
|
||||
"resolved": "https://registry.npmjs.org/i18next-http-backend/-/i18next-http-backend-3.0.5.tgz",
|
||||
"integrity": "sha512-QaWHnsxieEDcqKe+vo/RFqpiIFRi/KBqlOSPcUlvinBaISCeiTRCbtrazHAjtHtsLC66oDsROAH8frWkQzfMMQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"cross-fetch": "4.0.0"
|
||||
"cross-fetch": "4.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/i18next-resources-for-ts": {
|
||||
|
||||
@ -63,7 +63,7 @@
|
||||
"framer-motion": "^12.38.0",
|
||||
"hls.js": "^1.6.15",
|
||||
"i18next": "^24.2.0",
|
||||
"i18next-http-backend": "^3.0.1",
|
||||
"i18next-http-backend": "^3.0.5",
|
||||
"idb-keyval": "^6.2.1",
|
||||
"immer": "^10.1.1",
|
||||
"js-yaml": "^4.1.1",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user