mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
Add error logging to genai clients (#13943)
This commit is contained in:
parent
4c4b884f8e
commit
8c540d7210
@ -1,5 +1,6 @@
|
||||
"""Gemini Provider for Frigate AI."""
|
||||
|
||||
import logging
|
||||
from typing import Optional
|
||||
|
||||
import google.generativeai as genai
|
||||
@ -8,6 +9,8 @@ from google.api_core.exceptions import GoogleAPICallError
|
||||
from frigate.config import GenAIProviderEnum
|
||||
from frigate.genai import GenAIClient, register_genai_provider
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@register_genai_provider(GenAIProviderEnum.gemini)
|
||||
class GeminiClient(GenAIClient):
|
||||
@ -39,7 +42,8 @@ class GeminiClient(GenAIClient):
|
||||
timeout=self.timeout,
|
||||
),
|
||||
)
|
||||
except GoogleAPICallError:
|
||||
except GoogleAPICallError as e:
|
||||
logger.warning("Gemini returned an error: %s", str(e))
|
||||
return None
|
||||
try:
|
||||
description = response.text.strip()
|
||||
|
@ -37,5 +37,6 @@ class OllamaClient(GenAIClient):
|
||||
images=images,
|
||||
)
|
||||
return result["response"].strip()
|
||||
except (TimeoutException, ResponseError):
|
||||
except (TimeoutException, ResponseError) as e:
|
||||
logger.warning("Ollama returned an error: %s", str(e))
|
||||
return None
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""OpenAI Provider for Frigate AI."""
|
||||
|
||||
import base64
|
||||
import logging
|
||||
from typing import Optional
|
||||
|
||||
from httpx import TimeoutException
|
||||
@ -9,6 +10,8 @@ from openai import OpenAI
|
||||
from frigate.config import GenAIProviderEnum
|
||||
from frigate.genai import GenAIClient, register_genai_provider
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@register_genai_provider(GenAIProviderEnum.openai)
|
||||
class OpenAIClient(GenAIClient):
|
||||
@ -44,7 +47,8 @@ class OpenAIClient(GenAIClient):
|
||||
],
|
||||
timeout=self.timeout,
|
||||
)
|
||||
except TimeoutException:
|
||||
except TimeoutException as e:
|
||||
logger.warning("OpenAI returned an error: %s", str(e))
|
||||
return None
|
||||
if len(result.choices) > 0:
|
||||
return result.choices[0].message.content.strip()
|
||||
|
Loading…
Reference in New Issue
Block a user