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

perf: Lower serialization size of Pydantic models

Clémence Lesné73499debea30
diff --git a/function_app.py b/function_app.py
index 98bc4ff..091dda2 100644
--- a/function_app.py
+++ b/function_app.py
@@ -125,7 +125,7 @@ async def health_readiness_get(req: func.HttpRequest) -> func.HttpResponse:
status_code = HTTPStatus.SERVICE_UNAVAILABLE
break
return func.HttpResponse(
- body=readiness.model_dump_json(indent=None),
+ body=readiness.model_dump_json(exclude_none=True),
mimetype="application/json",
status_code=status_code,
)
@@ -246,7 +246,7 @@ async def call_get(req: func.HttpRequest) -> func.HttpResponse:
status_code=HTTPStatus.NOT_FOUND,
)
return func.HttpResponse(
- body=call.model_dump_json(indent=None),
+ body=call.model_dump_json(exclude_none=True),
mimetype="application/json",
status_code=HTTPStatus.OK,
)
@@ -276,7 +276,7 @@ async def call_post(req: func.HttpRequest) -> func.HttpResponse:
f"Created call with connection id: {call_connection_properties.call_connection_id}"
)
return func.HttpResponse(
- body=CallGetModel.model_validate(call).model_dump_json(indent=None),
+ body=CallGetModel.model_validate(call).model_dump_json(exclude_none=True),
mimetype="application/json",
status_code=HTTPStatus.CREATED,
)
@@ -578,7 +578,7 @@ def _trigger_trainings_event(
"""
Shortcut to add trainings to the queue.
"""
- trainings.set(call.model_dump_json(indent=None))
+ trainings.set(call.model_dump_json(exclude_none=True))
def _trigger_post_event(
@@ -588,7 +588,7 @@ def _trigger_post_event(
"""
Shortcut to add post-call intelligence to the queue.
"""
- post.set(call.model_dump_json(indent=None))
+ post.set(call.model_dump_json(exclude_none=True))
async def _communicationservices_event_url(
diff --git a/persistence/sqlite.py b/persistence/sqlite.py
index a029eed..31c81aa 100644
--- a/persistence/sqlite.py
+++ b/persistence/sqlite.py
@@ -57,7 +57,7 @@ class SqliteStore(IStore):
async def call_aset(self, call: CallStateModel) -> bool:
# TODO: Catch exceptions and return False if something goes wrong
- data = call.model_dump_json(indent=None, exclude_none=True)
+ data = call.model_dump_json(exclude_none=True)
logger.debug(f"Saving call {call.call_id}: {data}")
async with self._use_db() as db:
await db.execute(