mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-12 22:25:24 +03:00
fix api error in gemini and metadata for embeddings
This commit is contained in:
parent
89937e24c1
commit
ece7d5ab26
@ -23,22 +23,32 @@ logger = logging.getLogger(__name__)
|
|||||||
def get_metadata(event: Event) -> dict:
|
def get_metadata(event: Event) -> dict:
|
||||||
"""Extract valid event metadata."""
|
"""Extract valid event metadata."""
|
||||||
event_dict = model_to_dict(event)
|
event_dict = model_to_dict(event)
|
||||||
return {
|
return (
|
||||||
k: ",".join(str(x) for x in v) if isinstance(v, list) else v
|
{
|
||||||
for k, v in event_dict.items()
|
k: v
|
||||||
if k not in ["id", "thumbnail"]
|
for k, v in event_dict.items()
|
||||||
and v is not None
|
if k not in ["id", "thumbnail"]
|
||||||
and (
|
and v is not None
|
||||||
isinstance(v, (str, int, float, bool))
|
and isinstance(v, (str, int, float, bool))
|
||||||
or (isinstance(v, list) and len(v) > 0)
|
}
|
||||||
)
|
| {
|
||||||
} | {
|
k: v
|
||||||
k: v
|
for k, v in event_dict["data"].items()
|
||||||
for k, v in event_dict["data"].items()
|
if k not in ["description"]
|
||||||
if k not in ["description"]
|
and v is not None
|
||||||
and v is not None
|
and isinstance(v, (str, int, float, bool))
|
||||||
and isinstance(v, (str, int, float, bool))
|
}
|
||||||
}
|
| {
|
||||||
|
# Metadata search doesn't support $contains
|
||||||
|
# and an event can have multiple zones, so
|
||||||
|
# we need to create a key for each zone
|
||||||
|
f"{k}_{x}": True
|
||||||
|
for k, v in event_dict.items()
|
||||||
|
if isinstance(v, list) and len(v) > 0
|
||||||
|
for x in v
|
||||||
|
if isinstance(x, str)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Embeddings:
|
class Embeddings:
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import google.generativeai as genai
|
import google.generativeai as genai
|
||||||
from google.api_core.exceptions import DeadlineExceeded
|
from google.api_core.exceptions import GoogleAPICallError
|
||||||
|
|
||||||
from frigate.config import GenAIProviderEnum
|
from frigate.config import GenAIProviderEnum
|
||||||
from frigate.genai import GenAIClient, register_genai_provider
|
from frigate.genai import GenAIClient, register_genai_provider
|
||||||
@ -39,7 +39,7 @@ class GeminiClient(GenAIClient):
|
|||||||
timeout=self.timeout,
|
timeout=self.timeout,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
except DeadlineExceeded:
|
except GoogleAPICallError:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
description = response.text.strip()
|
description = response.text.strip()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user