update: backend logic changes

This commit is contained in:
root 2026-01-29 11:49:48 +00:00
parent 76de5cf496
commit 1a04e92482
2 changed files with 22 additions and 5 deletions

View File

@ -58,11 +58,15 @@ async def chat_with_ai(request: ChatRequest, background_tasks: BackgroundTasks =
tools.append(types.Tool(google_search=types.GoogleSearch())) 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." 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( # Build config - only set system_instruction if it has content
tools=tools if tools else None, config_params = {
temperature=0.1, "tools": tools if tools else None,
system_instruction=final_system_prompt "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() start_time = time.time()

View File

@ -22,6 +22,19 @@ def get_genai_client() -> genai.Client:
api_key = os.getenv('GEMINI_API_KEY') api_key = os.getenv('GEMINI_API_KEY')
if not api_key: if not api_key:
raise ValueError("GEMINI_API_KEY environment variable is not set") 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) _client = genai.Client(api_key=api_key)
return _client return _client