From 5092a8273928c864d12cd5310a8cdf970249de7e Mon Sep 17 00:00:00 2001 From: Huoyuuu <86390123+Huoyuuu@users.noreply.github.com> Date: Wed, 19 Jun 2024 19:13:00 +0800 Subject: [PATCH] Update chatcmpl.py --- pkg/provider/modelmgr/apis/chatcmpl.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/provider/modelmgr/apis/chatcmpl.py b/pkg/provider/modelmgr/apis/chatcmpl.py index 198a0fa..cc33ad0 100644 --- a/pkg/provider/modelmgr/apis/chatcmpl.py +++ b/pkg/provider/modelmgr/apis/chatcmpl.py @@ -102,13 +102,15 @@ class OpenAIChatCompletions(api.LLMAPIRequester): messages: typing.List[llm_entities.Message], funcs: typing.List[tools_entities.LLMFunction] = None, ) -> llm_entities.Message: - req_messages = [] + req_messages = [] # req_messages 仅用于类内,外部同步由 query.messages 进行 for m in messages: msg_dict = m.dict(exclude_none=True) - if isinstance(msg_dict.get("content"), list): - # 确保content是字符串 - msg_dict["content"] = "".join( - [part["text"] for part in msg_dict["content"]]) + content = msg_dict.get("content") + if isinstance(content, list): + # 检查 content 列表中是否每个部分都是文本 + if all(isinstance(part, dict) and part.get("type") == "text" for part in content): + # 将所有文本部分合并为一个字符串 + msg_dict["content"] = "".join(part["text"] for part in content) req_messages.append(msg_dict) try: