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

chore: Remove the use of jsonable_encoder

Clémence Lesné0073729cc8f3
diff --git a/main.py b/main.py
index caf233f..6356106 100644
--- a/main.py
+++ b/main.py
@@ -21,7 +21,6 @@ from azure.core.credentials import AzureKeyCredential
from azure.core.messaging import CloudEvent
from azure.eventgrid import EventGridEvent, SystemEventNames
from fastapi import FastAPI, status, Request, HTTPException, BackgroundTasks, Response
-from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse, HTMLResponse
from fastapi.staticfiles import StaticFiles
from jinja2 import Environment, FileSystemLoader, select_autoescape
@@ -138,7 +137,7 @@ async def health_readiness_get() -> JSONResponse:
status_code = status.HTTP_503_SERVICE_UNAVAILABLE
break
return JSONResponse(
- content=jsonable_encoder(readiness),
+ content=readiness.model_dump(mode="json"),
status_code=status_code,
)
diff --git a/persistence/cosmos_db.py b/persistence/cosmos_db.py
index a3e7035..bed7495 100644
--- a/persistence/cosmos_db.py
+++ b/persistence/cosmos_db.py
@@ -2,7 +2,6 @@ from azure.core.exceptions import ServiceResponseError
from azure.cosmos.aio import CosmosClient, ContainerProxy
from azure.cosmos.exceptions import CosmosHttpResponseError
from contextlib import asynccontextmanager
-from fastapi.encoders import jsonable_encoder
from helpers.config import CONFIG
from helpers.config_models.database import CosmosDbModel
from helpers.logging import build_logger
@@ -114,7 +113,7 @@ class CosmosDbStore(IStore):
wait=wait_random_exponential(multiplier=0.5, max=30),
)
async def call_aset(self, call: CallModel) -> bool:
- data = jsonable_encoder(call.model_dump(), exclude_none=True)
+ data = call.model_dump(mode="json", exclude_none=True)
data["id"] = str(call.call_id) # CosmosDB requires an id field
_logger.debug(f"Saving call {call.call_id}: {data}")
try:
diff --git a/persistence/sqlite.py b/persistence/sqlite.py
index 0171a4a..299e058 100644
--- a/persistence/sqlite.py
+++ b/persistence/sqlite.py
@@ -1,6 +1,5 @@
from aiosqlite import connect as sqlite_connect, Connection as SQLiteConnection
from contextlib import asynccontextmanager
-from fastapi.encoders import jsonable_encoder
from helpers.config import CONFIG
from helpers.config_models.database import SqliteModel
from helpers.logging import build_logger
@@ -62,7 +61,7 @@ class SqliteStore(IStore):
async def call_aset(self, call: CallModel) -> bool:
# TODO: Catch exceptions and return False if something goes wrong
- data = jsonable_encoder(call.model_dump(), exclude_none=True)
+ data = call.model_dump(mode="json", exclude_none=True)
_logger.debug(f"Saving call {call.call_id}: {data}")
async with self._use_db() as db:
await db.execute(