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: Limit task memory overflow for OpenAI

Clémence Lesnée83e7d28749c
diff --git a/helpers/llm_worker.py b/helpers/llm_worker.py
index 3c9542f..3df73ce 100644
--- a/helpers/llm_worker.py
+++ b/helpers/llm_worker.py
@@ -265,8 +265,11 @@ async def _use_oai() -> AsyncGenerator[AsyncAzureOpenAI, None]:
else None
),
)
- yield client
- await client.close()
+
+ try:
+ yield client, model, context
+ finally:
+ await client.close()
@asynccontextmanager
@@ -279,5 +282,8 @@ async def _use_contentsafety() -> AsyncGenerator[ContentSafetyClient, None]:
CONFIG.content_safety.access_key.get_secret_value()
),
)
- yield client
- await client.close()
+
+ try:
+ yield client
+ finally:
+ await client.close()