From 1a04e924827f81fab7ceb4c9923eb2b597def1d7 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 29 Jan 2026 11:49:48 +0000 Subject: [PATCH] update: backend logic changes --- backend/app/api/chat_routes.py | 14 +++++++++----- backend/app/services/analysis_service.py | 13 +++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/backend/app/api/chat_routes.py b/backend/app/api/chat_routes.py index b640446..68de157 100644 --- a/backend/app/api/chat_routes.py +++ b/backend/app/api/chat_routes.py @@ -58,11 +58,15 @@ async def chat_with_ai(request: ChatRequest, background_tasks: BackgroundTasks = tools.append(types.Tool(google_search=types.GoogleSearch())) final_system_prompt += "\n\n[SYSTEM INSTRUCTION] You have access to Google Search. You MUST use it to verify any data or find the latest information before answering. Do not rely solely on your internal knowledge." - config = types.GenerateContentConfig( - tools=tools if tools else None, - temperature=0.1, - system_instruction=final_system_prompt - ) + # Build config - only set system_instruction if it has content + config_params = { + "tools": tools if tools else None, + "temperature": 0.1 + } + if final_system_prompt and final_system_prompt.strip(): + config_params["system_instruction"] = final_system_prompt + + config = types.GenerateContentConfig(**config_params) start_time = time.time() diff --git a/backend/app/services/analysis_service.py b/backend/app/services/analysis_service.py index e711ca1..1cd254b 100644 --- a/backend/app/services/analysis_service.py +++ b/backend/app/services/analysis_service.py @@ -22,6 +22,19 @@ def get_genai_client() -> genai.Client: api_key = os.getenv('GEMINI_API_KEY') if not api_key: raise ValueError("GEMINI_API_KEY environment variable is not set") + + # Configure httpx proxy globally by monkey-patching + import httpx + proxy_url = os.getenv('https_proxy') or os.getenv('HTTPS_PROXY') + if proxy_url: + # Monkey-patch httpx to use proxy with SSL verification disabled + original_init = httpx.Client.__init__ + def patched_init(self, **kwargs): + kwargs.setdefault('proxy', proxy_url) + kwargs.setdefault('verify', False) + return original_init(self, **kwargs) + httpx.Client.__init__ = patched_init + _client = genai.Client(api_key=api_key) return _client