Skip to content

⚡ Bolt: Use AsyncGroq to prevent asyncio event loop blocking#92

Open
Adityasingh-8858 wants to merge 1 commit into
mainfrom
bolt-async-groq-664387477567385875
Open

⚡ Bolt: Use AsyncGroq to prevent asyncio event loop blocking#92
Adityasingh-8858 wants to merge 1 commit into
mainfrom
bolt-async-groq-664387477567385875

Conversation

@Adityasingh-8858
Copy link
Copy Markdown
Collaborator

💡 What
Migrated the synchronous Groq API client to the asynchronous AsyncGroq client in backend/main.py. Added await to network calls within the ai_voice and initiate_transfer async route handlers.

🎯 Why
Using a synchronous network client inside an asynchronous FastAPI endpoint blocks the main asyncio event loop. Under load, this prevents the application from handling other concurrent requests efficiently, severely degrading performance. Moving to an async client eliminates this bottleneck.

📊 Impact
Prevents entire event loop freezes during Groq API latency. Increases concurrent request handling capacity dramatically without adding threads.

🔬 Measurement
Verify by running load tests against the /ai-voice or /initiate-transfer endpoints and monitoring event loop blocking metrics. Also verified by running the existing pytest test suite, which continues to pass.


PR created automatically by Jules for task 664387477567385875 started by @Deepaksingh7238

Migrated Groq to AsyncGroq in the `/ai-voice` and `/initiate-transfer` endpoints.
This unblocks the FastAPI event loop during network I/O, allowing higher concurrency.

Co-authored-by: Deepaksingh7238 <110552872+Deepaksingh7238@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings May 10, 2026 16:19
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates Groq LLM calls in the FastAPI backend from the synchronous Groq client to the asynchronous AsyncGroq client to avoid blocking the asyncio event loop in async route handlers.

Changes:

  • Replaced Groq with AsyncGroq in backend/main.py.
  • Updated Groq chat completion calls in /ai-voice and /initiate-transfer handlers to use await.
  • Added a short Bolt learning note documenting the async-client requirement for FastAPI endpoints.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
backend/main.py Switches Groq client usage to async and awaits network calls in async endpoints.
.jules/bolt.md Documents the rationale and guidance for using async network clients in async FastAPI handlers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread backend/main.py
Comment on lines +10 to 12
from groq import AsyncGroq
from livekit import api
from contextlib import asynccontextmanager
Comment thread backend/main.py
Comment on lines 317 to +320
global groq_client
if groq_client is None:
groq_client = Groq(api_key=GROQ_API_KEY)
chat_completion = groq_client.chat.completions.create(
groq_client = AsyncGroq(api_key=GROQ_API_KEY)
chat_completion = await groq_client.chat.completions.create(
Comment thread backend/main.py
Comment on lines 503 to +505
global groq_client
if groq_client is None:
groq_client = Groq(api_key=GROQ_API_KEY)
groq_client = AsyncGroq(api_key=GROQ_API_KEY)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants