feat: support final answer and add log
Browse files
app.py
CHANGED
@@ -59,15 +59,24 @@ def respond(
|
|
59 |
|
60 |
try:
|
61 |
with requests.post(API_URL, headers=headers, json=data) as r:
|
|
|
62 |
if r.status_code == 200:
|
63 |
json_response = r.json()
|
|
|
64 |
if 'choices' in json_response and len(json_response['choices']) > 0:
|
65 |
content = json_response['choices'][0].get('message', {}).get('content', '')
|
|
|
66 |
if content:
|
67 |
if '<think>' in content and '</think>' in content:
|
68 |
content = content.split('</think>')[-1].strip()
|
69 |
-
|
|
|
|
|
70 |
return content
|
|
|
|
|
|
|
|
|
71 |
return "Service temporarily unavailable"
|
72 |
except Exception as e:
|
73 |
print(f"[ERROR] Request error: {e}")
|
|
|
59 |
|
60 |
try:
|
61 |
with requests.post(API_URL, headers=headers, json=data) as r:
|
62 |
+
print(f"[INFO] response status: {r.status_code}")
|
63 |
if r.status_code == 200:
|
64 |
json_response = r.json()
|
65 |
+
print(f"[INFO] response json: {json_response}")
|
66 |
if 'choices' in json_response and len(json_response['choices']) > 0:
|
67 |
content = json_response['choices'][0].get('message', {}).get('content', '')
|
68 |
+
print(f"[INFO] response content: {content}")
|
69 |
if content:
|
70 |
if '<think>' in content and '</think>' in content:
|
71 |
content = content.split('</think>')[-1].strip()
|
72 |
+
if '**Final Answer**' in content:
|
73 |
+
content = content.split('**Final Answer**')[-1].strip()
|
74 |
+
print(f"[INFO] final response: {content}")
|
75 |
return content
|
76 |
+
else:
|
77 |
+
print(f"[ERROR] No choices in response: {json_response}")
|
78 |
+
else:
|
79 |
+
print(f"[ERROR] Bad status code: {r.status_code}, response: {r.text}")
|
80 |
return "Service temporarily unavailable"
|
81 |
except Exception as e:
|
82 |
print(f"[ERROR] Request error: {e}")
|