Spaces:
Paused
Paused
Upload 2 files
Browse files
app.py
CHANGED
|
@@ -448,7 +448,7 @@ def chat_completions():
|
|
| 448 |
|
| 449 |
try:
|
| 450 |
response = requests.post(url, headers=headers, json=data, stream=True)
|
| 451 |
-
response.raise_for_status()
|
| 452 |
|
| 453 |
if stream:
|
| 454 |
return 1, response
|
|
@@ -524,7 +524,7 @@ def chat_completions():
|
|
| 524 |
continue
|
| 525 |
elif success == 1 and response is None:
|
| 526 |
continue
|
| 527 |
-
elif success == 1 and
|
| 528 |
return Response(
|
| 529 |
stream_with_context(generate_stream(response)),
|
| 530 |
mimetype='text/event-stream'
|
|
@@ -536,18 +536,27 @@ def chat_completions():
|
|
| 536 |
completion_tokens = response.candidates_token_count
|
| 537 |
total_tokens = response.total_token_count
|
| 538 |
finish_reason = response.finish_reason
|
| 539 |
-
|
| 540 |
-
# logger.info(f"AI响应处理成功↓\n{json_dumps}")
|
| 541 |
if text_content == '':
|
| 542 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 543 |
continue
|
|
|
|
| 544 |
if is_thinking and show_thoughts:
|
| 545 |
text_content = response.thoughts + '\n' + text_content
|
| 546 |
-
|
| 547 |
-
|
|
|
|
|
|
|
| 548 |
continue
|
| 549 |
-
|
| 550 |
-
|
|
|
|
| 551 |
continue
|
| 552 |
|
| 553 |
response_data = {
|
|
|
|
| 448 |
|
| 449 |
try:
|
| 450 |
response = requests.post(url, headers=headers, json=data, stream=True)
|
| 451 |
+
response.raise_for_status()
|
| 452 |
|
| 453 |
if stream:
|
| 454 |
return 1, response
|
|
|
|
| 524 |
continue
|
| 525 |
elif success == 1 and response is None:
|
| 526 |
continue
|
| 527 |
+
elif success == 1 and stream:
|
| 528 |
return Response(
|
| 529 |
stream_with_context(generate_stream(response)),
|
| 530 |
mimetype='text/event-stream'
|
|
|
|
| 536 |
completion_tokens = response.candidates_token_count
|
| 537 |
total_tokens = response.total_token_count
|
| 538 |
finish_reason = response.finish_reason
|
| 539 |
+
|
|
|
|
| 540 |
if text_content == '':
|
| 541 |
+
error_message = None
|
| 542 |
+
if response._data and 'error' in response._data:
|
| 543 |
+
error_message = response._data['error'].get('message')
|
| 544 |
+
if error_message:
|
| 545 |
+
logger.error(f"生成内容失败,API 返回错误: {error_message}")
|
| 546 |
+
else:
|
| 547 |
+
logger.error(f"生成内容失败: text_content 为空")
|
| 548 |
continue
|
| 549 |
+
|
| 550 |
if is_thinking and show_thoughts:
|
| 551 |
text_content = response.thoughts + '\n' + text_content
|
| 552 |
+
|
| 553 |
+
except AttributeError as e:
|
| 554 |
+
logger.error(f"处理响应失败,缺少必要的属性: {e}")
|
| 555 |
+
logger.error(f"原始响应: {response._data}")
|
| 556 |
continue
|
| 557 |
+
|
| 558 |
+
except Exception as e:
|
| 559 |
+
logger.error(f"处理响应失败: {e}")
|
| 560 |
continue
|
| 561 |
|
| 562 |
response_data = {
|