diff --git a/backend/app/services/llm_service.py b/backend/app/services/llm_service.py index c72df529..98a67224 100755 --- a/backend/app/services/llm_service.py +++ b/backend/app/services/llm_service.py @@ -36,8 +36,17 @@ def get_gemini_client(): Creating a new client per call avoids event loop mismatch issues that occur when caching clients in ASGI environments where requests may come on different event loops. The overhead is minimal compared to the LLM API call. + + Force httpx transport to avoid aiohttp AssertionError (connector is None) + that occurs when aiohttp is installed in the environment via other packages. """ - return genai.Client(api_key=GEMINI_API_KEY) + from google.genai import types as genai_types + return genai.Client( + api_key=GEMINI_API_KEY, + http_options=genai_types.HttpOptions( + httpx_async_client=httpx.AsyncClient(timeout=600.0) + ) + ) def get_openai_client():