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:
|
||||
"""Extract valid event metadata."""
|
||||
event_dict = model_to_dict(event)
|
||||
return {
|
||||
k: ",".join(str(x) for x in v) if isinstance(v, list) else v
|
||||
for k, v in event_dict.items()
|
||||
if k not in ["id", "thumbnail"]
|
||||
and v is not None
|
||||
and (
|
||||
isinstance(v, (str, int, float, bool))
|
||||
or (isinstance(v, list) and len(v) > 0)
|
||||
)
|
||||
} | {
|
||||
k: v
|
||||
for k, v in event_dict["data"].items()
|
||||
if k not in ["description"]
|
||||
and v is not None
|
||||
and isinstance(v, (str, int, float, bool))
|
||||
}
|
||||
return (
|
||||
{
|
||||
k: v
|
||||
for k, v in event_dict.items()
|
||||
if k not in ["id", "thumbnail"]
|
||||
and v is not None
|
||||
and isinstance(v, (str, int, float, bool))
|
||||
}
|
||||
| {
|
||||
k: v
|
||||
for k, v in event_dict["data"].items()
|
||||
if k not in ["description"]
|
||||
and v is not None
|
||||
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:
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
from typing import Optional
|
||||
|
||||
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.genai import GenAIClient, register_genai_provider
|
||||
@ -39,7 +39,7 @@ class GeminiClient(GenAIClient):
|
||||
timeout=self.timeout,
|
||||
),
|
||||
)
|
||||
except DeadlineExceeded:
|
||||
except GoogleAPICallError:
|
||||
return None
|
||||
try:
|
||||
description = response.text.strip()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user