Update app.py
Browse files
app.py
CHANGED
@@ -444,16 +444,18 @@ def handsome_chat_completions():
|
|
444 |
chunk_json = json.loads(chunk.decode("utf-8").lstrip("data: ").strip())
|
445 |
if "choices" in chunk_json and len(chunk_json["choices"]) > 0:
|
446 |
delta = chunk_json["choices"][0].get("delta", {})
|
447 |
-
|
448 |
-
|
|
|
449 |
formatted_reasoning = f"```Thinking\n{reasoning_content_accumulated}\n```"
|
450 |
yield f"data: {json.dumps({'choices': [{'delta': {'content': formatted_reasoning}, 'index': 0, 'finish_reason': None}]})}\n\n"
|
451 |
reasoning_content_accumulated = ""
|
452 |
-
|
453 |
-
|
|
|
454 |
yield f"data: {json.dumps({'choices': [{'delta': {'content': content_accumulated}, 'index': 0, 'finish_reason': None}]})}\n\n"
|
455 |
content_accumulated = ""
|
456 |
-
|
457 |
except (KeyError, ValueError, json.JSONDecodeError) as e:
|
458 |
logging.error(f"解析流式响应单行 JSON 失败: {e}, 行内容: {chunk.decode('utf-8')}")
|
459 |
continue
|
|
|
444 |
chunk_json = json.loads(chunk.decode("utf-8").lstrip("data: ").strip())
|
445 |
if "choices" in chunk_json and len(chunk_json["choices"]) > 0:
|
446 |
delta = chunk_json["choices"][0].get("delta", {})
|
447 |
+
|
448 |
+
if delta.get("reasoning_content") is not None:
|
449 |
+
reasoning_content_accumulated += delta.get("reasoning_content", "")
|
450 |
formatted_reasoning = f"```Thinking\n{reasoning_content_accumulated}\n```"
|
451 |
yield f"data: {json.dumps({'choices': [{'delta': {'content': formatted_reasoning}, 'index': 0, 'finish_reason': None}]})}\n\n"
|
452 |
reasoning_content_accumulated = ""
|
453 |
+
|
454 |
+
if delta.get("content") is not None:
|
455 |
+
content_accumulated += delta.get("content", "")
|
456 |
yield f"data: {json.dumps({'choices': [{'delta': {'content': content_accumulated}, 'index': 0, 'finish_reason': None}]})}\n\n"
|
457 |
content_accumulated = ""
|
458 |
+
|
459 |
except (KeyError, ValueError, json.JSONDecodeError) as e:
|
460 |
logging.error(f"解析流式响应单行 JSON 失败: {e}, 行内容: {chunk.decode('utf-8')}")
|
461 |
continue
|