From 11a1e86774d60e60f387389f7f218fbcd5839c05 Mon Sep 17 00:00:00 2001 From: taylor <=> Date: Tue, 12 Nov 2024 11:03:40 +0800 Subject: [PATCH] =?UTF-8?q?update:=20xai=E5=A2=9E=E5=8A=A0max=5Ftokens,max?= =?UTF-8?q?=5Fwords=E7=AD=89=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maubot_llmplus/aibot.py | 2 +- maubot_llmplus/platforms.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/maubot_llmplus/aibot.py b/maubot_llmplus/aibot.py index a69cbc5..aee3cc4 100644 --- a/maubot_llmplus/aibot.py +++ b/maubot_llmplus/aibot.py @@ -222,7 +222,7 @@ class AiBotPlugin(AbsExtraConfigPlugin): self.config.cur_model = self.config['platforms'][argus.split("#")[0]]['model'] await event.react("✅") # 如果是openai或者是claude - elif argus == 'openai' or argus == 'anthropic': + elif argus == 'openai' or argus == 'anthropic' or argus == 'xai': if argus == self.config.cur_platform: await event.reply(f"current ai platform has be {argus}") pass diff --git a/maubot_llmplus/platforms.py b/maubot_llmplus/platforms.py index 0cfe375..f9fe1f6 100644 --- a/maubot_llmplus/platforms.py +++ b/maubot_llmplus/platforms.py @@ -97,7 +97,7 @@ async def get_system_context(plugin: AbsExtraConfigPlugin, platform: Platform, e """ 获取聊天信息上下文 """ -async def get_chat_context(system_context: deque, plugin: AbsExtraConfigPlugin, platform: Platform, evt: MessageEvent) -> deque: +async def get_chat_context(system_context: deque, plugin: AbsExtraConfigPlugin, platform: Platform, evt: MessageEvent, hasAssistant: bool=True) -> deque: # 用户历史聊天上下文 chat_context = deque() # 计算系统提示词单词数 @@ -111,8 +111,16 @@ async def get_chat_context(system_context: deque, plugin: AbsExtraConfigPlugin, except (KeyError, AttributeError): continue + # 如果没有assistant的角色,那么如果当前的对话消息是机器人的,忽略不要 + if not hasAssistant: + if plugin.client.mxid == next_event.sender: + continue + else : + role = 'user' + else : + role = 'assistant' if plugin.client.mxid == next_event.sender else 'user' + # 如果当前的这条历史消息是机器人自己的,那么角色就要设置为assistant - role = 'assistant' if plugin.client.mxid == next_event.sender else 'user' message = next_event['content']['body'] user = '' # 如果是允许多用户使用,那么就需要在每个历史消息前加上用户名