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 1/5] 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 @@ async def call( 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) 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 2/5] 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 198a0fa3..cc33ad0d 100644 --- a/pkg/provider/modelmgr/apis/chatcmpl.py +++ b/pkg/provider/modelmgr/apis/chatcmpl.py @@ -102,13 +102,15 @@ async def call( 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: From 39ce5646f6e0e1c2298a0b82209826a20a22797a Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Mon, 24 Jun 2024 17:04:50 +0800 Subject: [PATCH 3/5] =?UTF-8?q?perf:=20content=E5=85=83=E7=B4=A0=E6=8B=BC?= =?UTF-8?q?=E6=8E=A5=E6=97=B6=E4=BD=BF=E7=94=A8=E6=8D=A2=E8=A1=8C=E7=AC=A6?= =?UTF-8?q?=E9=97=B4=E9=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/provider/modelmgr/apis/chatcmpl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/provider/modelmgr/apis/chatcmpl.py b/pkg/provider/modelmgr/apis/chatcmpl.py index cc33ad0d..3f1cfb32 100644 --- a/pkg/provider/modelmgr/apis/chatcmpl.py +++ b/pkg/provider/modelmgr/apis/chatcmpl.py @@ -110,7 +110,7 @@ async def call( # 检查 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) + msg_dict["content"] = "\n".join(part["text"] for part in content) req_messages.append(msg_dict) try: From 4ffa773facd578ed9b75630b9014415c0b1d1c84 Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Wed, 26 Jun 2024 10:15:21 +0800 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20=E5=89=8D=E7=BC=80=E5=93=8D=E5=BA=94?= =?UTF-8?q?=E6=97=B6=E5=9B=BE=E7=89=87=E8=A2=AB=E9=94=99=E8=AF=AF=E5=9C=B0?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E4=B8=BA=E6=96=87=E5=AD=97=20(#820)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/pipeline/resprule/rules/prefix.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/pipeline/resprule/rules/prefix.py b/pkg/pipeline/resprule/rules/prefix.py index 99dcd4f9..98b50321 100644 --- a/pkg/pipeline/resprule/rules/prefix.py +++ b/pkg/pipeline/resprule/rules/prefix.py @@ -20,11 +20,14 @@ async def match( for prefix in prefixes: if message_text.startswith(prefix): + # 查找第一个plain元素 + for me in message_chain: + if isinstance(me, mirai.Plain): + me.text = me.text[len(prefix):] + return entities.RuleJudgeResult( matching=True, - replacement=mirai.MessageChain([ - mirai.Plain(message_text[len(prefix):]) - ]), + replacement=message_chain, ) return entities.RuleJudgeResult( From ec8bd4922efb4d9886ab46863aea5c7cc5dcaf8b Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Wed, 26 Jun 2024 10:37:08 +0800 Subject: [PATCH 5/5] =?UTF-8?q?fix:=20=E9=94=99=E8=AF=AF=E5=9C=B0resprule?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=80=BB=E8=BE=91=20(#810)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/pipeline/resprule/resprule.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/pipeline/resprule/resprule.py b/pkg/pipeline/resprule/resprule.py index fce0c4ec..b7fdb372 100644 --- a/pkg/pipeline/resprule/resprule.py +++ b/pkg/pipeline/resprule/resprule.py @@ -44,8 +44,8 @@ async def process(self, query: core_entities.Query, stage_inst_name: str) -> ent use_rule = rules['default'] - if str(query.launcher_id) in use_rule: - use_rule = use_rule[str(query.launcher_id)] + if str(query.launcher_id) in rules: + use_rule = rules[str(query.launcher_id)] for rule_matcher in self.rule_matchers: # 任意一个匹配就放行 res = await rule_matcher.match(str(query.message_chain), query.message_chain, use_rule, query)