From 7a19dd503d02f9324b4abbeb7bc57b4fc6427542 Mon Sep 17 00:00:00 2001 From: Huoyuuu <86390123+Huoyuuu@users.noreply.github.com> Date: Wed, 19 Jun 2024 17:26:06 +0800 Subject: [PATCH] fix: ensure content is string in chatcmpl call method fix: ensure content is string in chatcmpl call method - Ensure user message content is a string instead of an array - Updated `call` method in `chatcmpl.py` to guarantee content is a string - Resolves compatibility issue with the yi-large model --- pkg/provider/modelmgr/apis/chatcmpl.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/provider/modelmgr/apis/chatcmpl.py b/pkg/provider/modelmgr/apis/chatcmpl.py index 028b208e..198a0fa3 100644 --- a/pkg/provider/modelmgr/apis/chatcmpl.py +++ b/pkg/provider/modelmgr/apis/chatcmpl.py @@ -102,9 +102,14 @@ class OpenAIChatCompletions(api.LLMAPIRequester): messages: typing.List[llm_entities.Message], funcs: typing.List[tools_entities.LLMFunction] = None, ) -> llm_entities.Message: - req_messages = [ # req_messages 仅用于类内,外部同步由 query.messages 进行 - m.dict(exclude_none=True) for m in messages - ] + req_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"]]) + req_messages.append(msg_dict) try: return await self._closure(req_messages, model, funcs)