Add error logging to genai clients (#13943)

This commit is contained in:
Josh Hawkins 2024-09-24 15:04:35 -05:00 committed by GitHub
parent 4c4b884f8e
commit 8c540d7210
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 3 deletions

View File

@ -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()

View File

@ -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

View File

@ -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()