Skip to content

Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!

Python

dev: Standardize Pydantic parsing errors log

Clémence Lesné21ea345a37e4
diff --git a/persistence/ai_search.py b/persistence/ai_search.py
index 35a55f3..29aa4d0 100644
--- a/persistence/ai_search.py
+++ b/persistence/ai_search.py
@@ -78,9 +78,8 @@ class AiSearchSearch(ISearch):
if cached:
try:
return TypeAdapter(list[TrainingModel]).validate_json(cached)
- except ValidationError:
- logger.warning(f"Error parsing cached training: {cached}")
- pass
+ except ValidationError as e:
+ logger.debug(f"Parsing error: {e.errors()}")
if cache_only:
return None
@@ -137,14 +136,10 @@ class AiSearchSearch(ISearch):
logger.error(f"Error connecting to AI Search, {e}")
# Update cache
- await self._cache.aset(
- cache_key,
- (
- TypeAdapter(list[TrainingModel]).dump_json(trainings)
- if trainings
- else None
- ),
- )
+ if trainings:
+ await self._cache.aset(
+ cache_key, TypeAdapter(list[TrainingModel]).dump_json(trainings)
+ )
return trainings or None