rohannsinghal commited on
Commit
7d26bd9
·
1 Parent(s): f93b510
Files changed (1) hide show
  1. app/main_api.py +31 -10
app/main_api.py CHANGED
@@ -276,17 +276,38 @@ class MultiLLMManager:
276
 
277
  async def _groq_response(self, prompt: str, max_tokens: int) -> str:
278
  key = next(self.groq_keys)
279
- client = groq.Groq(api_key=key)
280
 
281
- response = client.chat.completions.create(
282
- model="llama-3.3-70b-versatile",
283
- messages=[{"role": "user", "content": prompt}],
284
- temperature=0.1,
285
- max_tokens=max_tokens,
286
- top_p=0.9
287
- )
288
- return response.choices[0].message.content.strip()
289
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
290
  async def _openai_response(self, prompt: str, max_tokens: int) -> str:
291
  key = next(self.openai_keys)
292
  openai.api_key = key
 
276
 
277
  async def _groq_response(self, prompt: str, max_tokens: int) -> str:
278
  key = next(self.groq_keys)
 
279
 
280
+ # --- THE FINAL FIX: BYPASS GROQ PROXY BUG ---
281
+ # Create our own clean HTTP client and pass it to Groq
282
+ # This bypasses the internal bug that incorrectly handles proxies in HF Spaces
283
+
284
+ try:
285
+ # Create a clean HTTP client without proxy issues
286
+ clean_http_client = httpx.Client(
287
+ timeout=30.0,
288
+ limits=httpx.Limits(max_keepalive_connections=5, max_connections=10)
289
+ )
290
+
291
+ client = groq.Groq(
292
+ api_key=key,
293
+ http_client=clean_http_client # <-- This bypasses the proxy bug
294
+ )
295
+
296
+ response = client.chat.completions.create(
297
+ model="llama-3.3-70b-versatile", # Updated to latest model
298
+ messages=[{"role": "user", "content": prompt}],
299
+ temperature=0.1,
300
+ max_tokens=max_tokens,
301
+ top_p=0.9
302
+ )
303
+
304
+ return response.choices[0].message.content.strip()
305
+
306
+ except Exception as e:
307
+ logger.error(f"Groq response error: {e}")
308
+ raise e # Let the parent handle fallback
309
+
310
+
311
  async def _openai_response(self, prompt: str, max_tokens: int) -> str:
312
  key = next(self.openai_keys)
313
  openai.api_key = key