diff --git a/backend/app/services/gemini_service.py b/backend/app/services/gemini_service.py index 4401541..d15c659 100755 --- a/backend/app/services/gemini_service.py +++ b/backend/app/services/gemini_service.py @@ -11,11 +11,10 @@ from app.models.schemas import SubReview, RagStatus # Configure logging logger = logging.getLogger(__name__) -# Timeout (seconds) for each Gemini API call. -# Set at the HTTP client level so the network connection is actually closed -# on timeout — asyncio.wait_for alone cannot cancel SDK-internal retries. -_PRIMARY_TIMEOUT = 45 -_FALLBACK_TIMEOUT = 150 +# Timeout for each Gemini API call. +# google-genai http_options 'timeout' is in MILLISECONDS. +_PRIMARY_TIMEOUT_MS = 45_000 # 45 seconds +_FALLBACK_TIMEOUT_MS = 150_000 # 150 seconds class GeminiService: @@ -30,13 +29,14 @@ class GeminiService: """ # Two separate clients with different HTTP-level timeouts so the # network connection is torn down when the deadline is reached. + # Note: google-genai http_options 'timeout' is in milliseconds. self.primary_client = genai.Client( api_key=api_key, - http_options={"timeout": _PRIMARY_TIMEOUT}, + http_options={"timeout": _PRIMARY_TIMEOUT_MS}, ) self.fallback_client = genai.Client( api_key=api_key, - http_options={"timeout": _FALLBACK_TIMEOUT}, + http_options={"timeout": _FALLBACK_TIMEOUT_MS}, ) self.model = "gemini-3.1-pro-preview" self.fallback_model = "gemini-3-flash-preview"