Update multi_inference.py
Browse files- multi_inference.py +11 -2
multi_inference.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
# multi_inference.py (Groq
|
2 |
|
3 |
import requests
|
4 |
|
@@ -22,11 +22,20 @@ def try_groq(prompt):
|
|
22 |
}
|
23 |
|
24 |
res = requests.post(url, headers=headers, json=data)
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
if "choices" in result:
|
28 |
return result["choices"][0]["message"]["content"]
|
|
|
29 |
return f"[ERROR] Groq: {result.get('error', {}).get('message', 'Unknown error')}"
|
|
|
30 |
except Exception as e:
|
31 |
return f"[ERROR] Groq Exception: {str(e)}"
|
32 |
|
|
|
1 |
+
# multi_inference.py (Groq-only version with error handling)
|
2 |
|
3 |
import requests
|
4 |
|
|
|
22 |
}
|
23 |
|
24 |
res = requests.post(url, headers=headers, json=data)
|
25 |
+
|
26 |
+
if res.status_code != 200:
|
27 |
+
return f"[ERROR] Groq HTTP {res.status_code}: {res.text}"
|
28 |
+
|
29 |
+
try:
|
30 |
+
result = res.json()
|
31 |
+
except Exception:
|
32 |
+
return "[ERROR] Groq returned invalid JSON"
|
33 |
|
34 |
if "choices" in result:
|
35 |
return result["choices"][0]["message"]["content"]
|
36 |
+
|
37 |
return f"[ERROR] Groq: {result.get('error', {}).get('message', 'Unknown error')}"
|
38 |
+
|
39 |
except Exception as e:
|
40 |
return f"[ERROR] Groq Exception: {str(e)}"
|
41 |
|