[fix] 修复一些偶现的bug

This commit is contained in:
Wizerd
2023-12-15 15:52:32 +08:00
parent dce4f0ecb5
commit 1b31f74143
2 changed files with 11 additions and 3 deletions

View File

@@ -8,6 +8,10 @@
# 更新日志 # 更新日志
### 0.0.11
- 修复一些偶现的bug
### 0.0.10 ### 0.0.10
- 已支持非流式响应 - 已支持非流式响应

10
main.py
View File

@@ -26,8 +26,8 @@ BASE_URL = os.getenv('BASE_URL', '')
PROXY_API_PREFIX = os.getenv('PROXY_API_PREFIX', '') PROXY_API_PREFIX = os.getenv('PROXY_API_PREFIX', '')
UPLOAD_BASE_URL = os.getenv('UPLOAD_BASE_URL', '') UPLOAD_BASE_URL = os.getenv('UPLOAD_BASE_URL', '')
VERSION = '0.0.10' VERSION = '0.0.11'
UPDATE_INFO = '支持非流式响应' UPDATE_INFO = '修复一些偶现的bug'
with app.app_context(): with app.app_context():
# 输出版本信息 # 输出版本信息
@@ -379,6 +379,10 @@ def chat_completions():
data_json = json.loads(complete_data.replace('data: ', '')) data_json = json.loads(complete_data.replace('data: ', ''))
# print(f"data_json: {data_json}") # print(f"data_json: {data_json}")
message = data_json.get("message", {}) message = data_json.get("message", {})
if message == {} or message == None:
print(f"message 为空: data_json: {data_json}")
message_status = message.get("status") message_status = message.get("status")
content = message.get("content", {}) content = message.get("content", {})
role = message.get("author", {}).get("role") role = message.get("author", {}).get("role")
@@ -633,7 +637,7 @@ def chat_completions():
# 累积 new_text # 累积 new_text
all_new_text += ''.join("```\n" + error_message + "\n```") all_new_text += ''.join("```\n" + error_message + "\n```")
yield 'data: ' + json.dumps(error_data) + '\n\n' yield 'data: ' + json.dumps(error_data) + '\n\n'
except json.JSONDecodeError: except:
# print("JSON 解析错误") # print("JSON 解析错误")
print(f"[{datetime.now()}] 发送最后的数据: {buffer}") print(f"[{datetime.now()}] 发送最后的数据: {buffer}")
yield buffer yield buffer