From 2d04636cfd0f52d6650af7dcfb5835835a5dcf61 Mon Sep 17 00:00:00 2001 From: taylor Date: Mon, 14 Oct 2024 00:49:42 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E6=B7=BB=E5=8A=A0=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maubot_llmplus/aibot.py | 14 ++++++++++++++ maubot_llmplus/plugin.py | 8 +++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/maubot_llmplus/aibot.py b/maubot_llmplus/aibot.py index 23a7758..e22b124 100644 --- a/maubot_llmplus/aibot.py +++ b/maubot_llmplus/aibot.py @@ -172,6 +172,20 @@ class AiBotPlugin(AbsExtraConfigPlugin): await event.reply("\n".join(models), markdown=True) # 如果不是,如果是其他的名称,表示这是一个模型名 + # 如果是use为第二命令,则表示要切换模型 + if argus.startswith('use'): + arg_elements = argus.strip().split(" ", 2) + # 如果命令小于2的个数,就没有写模型名,无法切换 + if len(arg_elements) < 2: + await event.reply("give me a model name after 'use' command", markdown=True) + platform = self.get_ai_platform() + models = platform.list_models() + if f"- {arg_elements[1]}" in models: + self.log.debug(f"switch model: {arg_elements[1]}") + self.model = arg_elements[1] + await event.react("✅") + else: + await event.reply("not found valid model") @classmethod def get_config_class(cls) -> Type[BaseProxyConfig]: diff --git a/maubot_llmplus/plugin.py b/maubot_llmplus/plugin.py index 3b92ad7..122984f 100644 --- a/maubot_llmplus/plugin.py +++ b/maubot_llmplus/plugin.py @@ -5,12 +5,18 @@ class AbsExtraConfigPlugin(Plugin): default_username: str user_id: str + model: str; + async def start(self) -> None: await super().start() self.default_username = await self.client.get_displayname(self.client.mxid) self.user_id = self.client.parse_user_id(self.client.mxid)[0] + self.model = self.config['platform'][self.config['use_platform']]['model'] def get_bot_name(self) -> str: return self.config['name'] or \ self.default_username or \ - self.user_id \ No newline at end of file + self.user_id + + def get_use_model(self) -> str: + return self.model