Spaces:
Sleeping
Sleeping
feat: update
Browse files
app.py
CHANGED
|
@@ -13,7 +13,7 @@ API_TOKEN = os.getenv("API_TOKEN")
|
|
| 13 |
|
| 14 |
# 验证必要的环境变量
|
| 15 |
if not API_URL or not API_TOKEN:
|
| 16 |
-
raise ValueError("
|
| 17 |
|
| 18 |
print(f"[INFO] starting:")
|
| 19 |
print(f"[INFO] API_URL: {API_URL[:6]}...{API_URL[-13:]}")
|
|
@@ -63,6 +63,7 @@ def respond(
|
|
| 63 |
print(f"[INFO] reqData: {data}")
|
| 64 |
|
| 65 |
response = ""
|
|
|
|
| 66 |
|
| 67 |
with requests.post(API_URL, headers=headers, json=data, stream=True) as r:
|
| 68 |
for line in r.iter_lines():
|
|
@@ -72,14 +73,18 @@ def respond(
|
|
| 72 |
if 'choices' in json_response and len(json_response['choices']) > 0:
|
| 73 |
token = json_response['choices'][0].get('delta', {}).get('content', '')
|
| 74 |
if token:
|
| 75 |
-
|
| 76 |
-
if
|
| 77 |
-
|
|
|
|
|
|
|
| 78 |
except json.JSONDecodeError:
|
| 79 |
continue
|
| 80 |
|
| 81 |
-
if
|
| 82 |
-
|
|
|
|
|
|
|
| 83 |
|
| 84 |
|
| 85 |
"""
|
|
|
|
| 13 |
|
| 14 |
# 验证必要的环境变量
|
| 15 |
if not API_URL or not API_TOKEN:
|
| 16 |
+
raise ValueError("make sure API_URL & API_TOKEN is right")
|
| 17 |
|
| 18 |
print(f"[INFO] starting:")
|
| 19 |
print(f"[INFO] API_URL: {API_URL[:6]}...{API_URL[-13:]}")
|
|
|
|
| 63 |
print(f"[INFO] reqData: {data}")
|
| 64 |
|
| 65 |
response = ""
|
| 66 |
+
current_response = ""
|
| 67 |
|
| 68 |
with requests.post(API_URL, headers=headers, json=data, stream=True) as r:
|
| 69 |
for line in r.iter_lines():
|
|
|
|
| 73 |
if 'choices' in json_response and len(json_response['choices']) > 0:
|
| 74 |
token = json_response['choices'][0].get('delta', {}).get('content', '')
|
| 75 |
if token:
|
| 76 |
+
current_response += token
|
| 77 |
+
if '**Final Answer**' in current_response:
|
| 78 |
+
final_answer = current_response.split('**Final Answer**')[-1].strip()
|
| 79 |
+
if final_answer:
|
| 80 |
+
yield final_answer
|
| 81 |
except json.JSONDecodeError:
|
| 82 |
continue
|
| 83 |
|
| 84 |
+
if current_response and '**Final Answer**' in current_response:
|
| 85 |
+
final_answer = current_response.split('**Final Answer**')[-1].strip()
|
| 86 |
+
if final_answer:
|
| 87 |
+
yield final_answer
|
| 88 |
|
| 89 |
|
| 90 |
"""
|