Spaces:
Running
Running
update
Browse files
app.py
CHANGED
|
@@ -62,15 +62,18 @@ def respond(
|
|
| 62 |
print(f"[INFO] modelParam: temperature={temperature}, top_p={top_p}")
|
| 63 |
print(f"[INFO] reqData: {data}")
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
|
| 76 |
"""
|
|
|
|
| 62 |
print(f"[INFO] modelParam: temperature={temperature}, top_p={top_p}")
|
| 63 |
print(f"[INFO] reqData: {data}")
|
| 64 |
|
| 65 |
+
try:
|
| 66 |
+
with requests.post(API_URL, headers=headers, json=data) as r:
|
| 67 |
+
if r.status_code == 200:
|
| 68 |
+
json_response = r.json()
|
| 69 |
+
if 'choices' in json_response and len(json_response['choices']) > 0:
|
| 70 |
+
response = json_response['choices'][0].get('message', {}).get('content', '')
|
| 71 |
+
if response:
|
| 72 |
+
return response
|
| 73 |
+
return "Service temporarily unavailable"
|
| 74 |
+
except Exception as e:
|
| 75 |
+
print(f"[ERROR] Request error: {e}")
|
| 76 |
+
return "Service error occurred"
|
| 77 |
|
| 78 |
|
| 79 |
"""
|