From 81c2c3c0e5ea8a27629656912b4916b87e6093a1 Mon Sep 17 00:00:00 2001 From: YunZL Date: Mon, 23 Sep 2024 23:25:54 +0800 Subject: [PATCH] Add Role Check to Prevent Validation Error --- pkg/provider/modelmgr/apis/chatcmpl.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/provider/modelmgr/apis/chatcmpl.py b/pkg/provider/modelmgr/apis/chatcmpl.py index 222553a..099eef1 100644 --- a/pkg/provider/modelmgr/apis/chatcmpl.py +++ b/pkg/provider/modelmgr/apis/chatcmpl.py @@ -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