Merge pull request #889 from YunZLu/add-check-role

Fix: Add Role Check to Prevent Validation Error
This commit is contained in:
Junyan Qin 2024-09-26 09:31:25 +08:00 committed by GitHub
commit 47e308b99d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -55,6 +55,10 @@ class OpenAIChatCompletions(api.LLMAPIRequester):
) -> llm_entities.Message:
chatcmpl_message = chat_completion.choices[0].message.dict()
# 确保 role 字段存在且不为 None
if 'role' not in chatcmpl_message or chatcmpl_message['role'] is None:
chatcmpl_message['role'] = 'assistant'
message = llm_entities.Message(**chatcmpl_message)
return message