diff --git a/maubot_llmplus/aibot.py b/maubot_llmplus/aibot.py index 1737f5c..fec9ac9 100644 --- a/maubot_llmplus/aibot.py +++ b/maubot_llmplus/aibot.py @@ -12,26 +12,6 @@ from maubot_llmplus.platforms import Platform from maubot_llmplus.plugin import AbsExtraConfigPlugin from maubot_llmplus.thrid_platform import OpenAi, Anthropic -""" -配置文件加载 -""" - - -class Config(BaseProxyConfig): - - def do_update(self, helper: ConfigUpdateHelper) -> None: - helper.copy("allowed_users") - helper.copy("use_platform") - helper.copy("name") - helper.copy("reply_in_thread") - helper.copy("enable_multi_user") - helper.copy("system_prompt") - helper.copy("platforms") - helper.copy("additional_prompt") - - super._cur_model = helper.base['platforms'][helper.base['use_platform']]['model'] - - class AiBotPlugin(AbsExtraConfigPlugin): async def start(self) -> None: diff --git a/maubot_llmplus/platforms.py b/maubot_llmplus/platforms.py index e444378..36df96d 100644 --- a/maubot_llmplus/platforms.py +++ b/maubot_llmplus/platforms.py @@ -6,9 +6,8 @@ from typing import Optional, List, Generator from aiohttp import ClientSession from maubot import Plugin from mautrix.types import MessageEvent, EncryptedEvent -from mautrix.util.config import BaseProxyConfig -from maubot_llmplus.plugin import AbsExtraConfigPlugin +from maubot_llmplus.plugin import AbsExtraConfigPlugin, Config """ AI响应对象 @@ -36,7 +35,7 @@ class Platform: system_prompt: str max_context_messages: int - def __init__(self, config: BaseProxyConfig, http: ClientSession) -> None: + def __init__(self, config: Config, http: ClientSession) -> None: self.http = http self.config = config['platforms'][self.get_type()] self.url = self.config['url'] diff --git a/maubot_llmplus/plugin.py b/maubot_llmplus/plugin.py index 0c1d120..494a902 100644 --- a/maubot_llmplus/plugin.py +++ b/maubot_llmplus/plugin.py @@ -1,4 +1,5 @@ from maubot import Plugin +from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper class AbsExtraConfigPlugin(Plugin): @@ -10,8 +11,28 @@ class AbsExtraConfigPlugin(Plugin): self.default_username = await self.client.get_displayname(self.client.mxid) self.user_id = self.client.parse_user_id(self.client.mxid)[0] - def get_bot_name(self) -> str: return self.config['name'] or \ self.default_username or \ self.user_id + + +""" + 配置文件加载 +""" + + +class Config(BaseProxyConfig): + _cur_model: str + + def do_update(self, helper: ConfigUpdateHelper) -> None: + helper.copy("allowed_users") + helper.copy("use_platform") + helper.copy("name") + helper.copy("reply_in_thread") + helper.copy("enable_multi_user") + helper.copy("system_prompt") + helper.copy("platforms") + helper.copy("additional_prompt") + + self._cur_model = helper.base['platforms'][helper.base['use_platform']]['model']