add: 添加切换模型命令

This commit is contained in:
taylor
2024-10-14 01:00:07 +08:00
parent 79f667aaaa
commit 25f120f18f
3 changed files with 5 additions and 8 deletions

View File

@@ -18,6 +18,7 @@ from maubot_llmplus.thrid_platform import OpenAi, Anthropic
class Config(BaseProxyConfig): class Config(BaseProxyConfig):
def do_update(self, helper: ConfigUpdateHelper) -> None: def do_update(self, helper: ConfigUpdateHelper) -> None:
helper.copy("allowed_users") helper.copy("allowed_users")
helper.copy("use_platform") helper.copy("use_platform")
@@ -27,6 +28,7 @@ class Config(BaseProxyConfig):
helper.copy("system_prompt") helper.copy("system_prompt")
helper.copy("platforms") helper.copy("platforms")
helper.copy("additional_prompt") helper.copy("additional_prompt")
super._cur_model = self['platforms'][self['use_platform']]['model']
class AiBotPlugin(AbsExtraConfigPlugin): class AiBotPlugin(AbsExtraConfigPlugin):
@@ -182,7 +184,7 @@ class AiBotPlugin(AbsExtraConfigPlugin):
models = platform.list_models() models = platform.list_models()
if f"- {arg_elements[1]}" in models: if f"- {arg_elements[1]}" in models:
self.log.debug(f"switch model: {arg_elements[1]}") self.log.debug(f"switch model: {arg_elements[1]}")
self.model = arg_elements[1] self.config._cur_model = arg_elements[1]
await event.react("") await event.react("")
else: else:
await event.reply("not found valid model") await event.reply("not found valid model")

View File

@@ -40,7 +40,7 @@ class Platform:
self.http = http self.http = http
self.config = config['platforms'][self.get_type()] self.config = config['platforms'][self.get_type()]
self.url = self.config['url'] self.url = self.config['url']
self.model = self.config['model'] self.model = config._cur_model
self.max_words = self.config['max_words'] self.max_words = self.config['max_words']
self.api_key = self.config['api_key'] self.api_key = self.config['api_key']
self.max_context_messages = self.config['max_context_messages'] self.max_context_messages = self.config['max_context_messages']

View File

@@ -5,18 +5,13 @@ class AbsExtraConfigPlugin(Plugin):
default_username: str default_username: str
user_id: str user_id: str
model: str;
async def start(self) -> None: async def start(self) -> None:
await super().start() await super().start()
self.default_username = await self.client.get_displayname(self.client.mxid) self.default_username = await self.client.get_displayname(self.client.mxid)
self.user_id = self.client.parse_user_id(self.client.mxid)[0] self.user_id = self.client.parse_user_id(self.client.mxid)[0]
self.model = self.config['platforms'][self.config['use_platform']]['model']
def get_bot_name(self) -> str: def get_bot_name(self) -> str:
return self.config['name'] or \ return self.config['name'] or \
self.default_username or \ self.default_username or \
self.user_id self.user_id
def get_use_model(self) -> str:
return self.model