Spaces:
Sleeping
Sleeping
update
Browse files
app.py
CHANGED
|
@@ -48,7 +48,7 @@ def respond(
|
|
| 48 |
|
| 49 |
data = {
|
| 50 |
"model": "/data/DMind-1-mini",
|
| 51 |
-
"stream": False,
|
| 52 |
"messages": messages,
|
| 53 |
"temperature": temperature,
|
| 54 |
"top_p": top_p,
|
|
@@ -64,25 +64,16 @@ def respond(
|
|
| 64 |
|
| 65 |
try:
|
| 66 |
with requests.post(API_URL, headers=headers, json=data) as r:
|
| 67 |
-
if r.status_code
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
else:
|
| 78 |
-
print("[ERROR] No cleaned content found in API response")
|
| 79 |
-
return "No content in the response after cleaning"
|
| 80 |
-
else:
|
| 81 |
-
print("[ERROR] No choices found in API response")
|
| 82 |
-
return "No choices in the response"
|
| 83 |
-
else:
|
| 84 |
-
print(f"[ERROR] Unexpected status code: {r.status_code}")
|
| 85 |
-
return "Unexpected status code from API"
|
| 86 |
except Exception as e:
|
| 87 |
print(f"[ERROR] Request error: {e}")
|
| 88 |
return "Service error occurred"
|
|
|
|
| 48 |
|
| 49 |
data = {
|
| 50 |
"model": "/data/DMind-1-mini",
|
| 51 |
+
"stream": False,
|
| 52 |
"messages": messages,
|
| 53 |
"temperature": temperature,
|
| 54 |
"top_p": top_p,
|
|
|
|
| 64 |
|
| 65 |
try:
|
| 66 |
with requests.post(API_URL, headers=headers, json=data) as r:
|
| 67 |
+
if r.status_code != 200:
|
| 68 |
+
print(f"[ERROR] API Error: {r.status_code} - {r.text}")
|
| 69 |
+
return "Service error"
|
| 70 |
+
json_response = r.json()
|
| 71 |
+
print(f"[DEBUG] API Response: {json.dumps(json_response, indent=2)}")
|
| 72 |
+
if 'choices' in json_response and len(json_response['choices']) > 0:
|
| 73 |
+
response = json_response['choices'][0].get('message', {}).get('content', '')
|
| 74 |
+
if response:
|
| 75 |
+
return response
|
| 76 |
+
return "No response from model"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
except Exception as e:
|
| 78 |
print(f"[ERROR] Request error: {e}")
|
| 79 |
return "Service error occurred"
|