Skip to content

Open source alternatives to paid SaaS apps: Notion, Slack, Auth0, Vercel and more. Curated list with licenses and GitHub stars.

Schedule AI response thread-safely on the main event loop

Jaya Prasad Kavuru5d2ce124ae33
diff --git a/ai_agents/AI-Voice-Agent/server/main.py b/ai_agents/AI-Voice-Agent/server/main.py
index aabca52..24f3b57 100644
--- a/ai_agents/AI-Voice-Agent/server/main.py
+++ b/ai_agents/AI-Voice-Agent/server/main.py
@@ -287,7 +287,7 @@ async def websocket_endpoint(websocket: WebSocket):
)
# Spawn processing task
- asyncio.create_task(process_ai_response(utterance))
+ asyncio.run_coroutine_threadsafe(process_ai_response(utterance), loop)
def on_metadata(self, metadata, **kwargs):
print(f"Deepgram Metadata: {metadata}")
@@ -319,7 +319,7 @@ async def websocket_endpoint(websocket: WebSocket):
)
# Spawn processing task
- asyncio.create_task(process_ai_response(utterance))
+ asyncio.run_coroutine_threadsafe(process_ai_response(utterance), loop)
def on_close(self, close, **kwargs):
print("Deepgram Connection Closed")