add: 添加命令ai model list的逻辑

This commit is contained in:
taylor
2024-10-13 20:28:30 +08:00
parent 9f9e87eb5c
commit 8c16faa34a
3 changed files with 21 additions and 14 deletions

View File

@@ -9,6 +9,7 @@ from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper
from maubot_llmplus.local_paltform import Ollama, LmStudio from maubot_llmplus.local_paltform import Ollama, LmStudio
from maubot_llmplus.platforms import Platform from maubot_llmplus.platforms import Platform
from maubot_llmplus.plugin import AbsExtraConfigPlugin
from maubot_llmplus.thrid_platform import OpenAi, Anthropic from maubot_llmplus.thrid_platform import OpenAi, Anthropic
""" """
@@ -27,24 +28,13 @@ class Config(BaseProxyConfig):
helper.copy("platforms") helper.copy("platforms")
helper.copy("additional_prompt") helper.copy("additional_prompt")
class AbsAiBotPlugin(Plugin):
default_username: str
user_id: str
def get_bot_name(self) -> str: class AiBotPlugin(AbsExtraConfigPlugin):
return self.config['name'] or \
self.default_username or \
self.user_id
class AiBotPlugin(AbsAiBotPlugin):
async def start(self) -> None: async def start(self) -> None:
await super().start() await super().start()
# 加载并更新配置 # 加载并更新配置
self.config.load_and_update() self.config.load_and_update()
self.default_username = await self.client.get_displayname(self.client.mxid)
self.user_id = self.client.parse_user_id(self.client.mxid)[0]
""" """
判断sender是否是allowed_users中的成员 判断sender是否是allowed_users中的成员
@@ -115,6 +105,7 @@ class AiBotPlugin(AbsAiBotPlugin):
if parent_event.sender == self.client.mxid: if parent_event.sender == self.client.mxid:
return True return True
@event.on(EventType.ROOM_MESSAGE) @event.on(EventType.ROOM_MESSAGE)
async def on_message(self, event: MessageEvent) -> None: async def on_message(self, event: MessageEvent) -> None:
if not await self.should_respond(event): if not await self.should_respond(event):

View File

@@ -8,7 +8,7 @@ from maubot import Plugin
from mautrix.types import MessageEvent, EncryptedEvent from mautrix.types import MessageEvent, EncryptedEvent
from mautrix.util.config import BaseProxyConfig from mautrix.util.config import BaseProxyConfig
from maubot_llmplus.aibot import AbsAiBotPlugin from maubot_llmplus.plugin import AbsExtraConfigPlugin
""" """
AI响应对象 AI响应对象
@@ -62,7 +62,7 @@ class Platform:
async def get_context(plugin: AbsAiBotPlugin, platform: Platform, evt: MessageEvent) -> deque: async def get_context(plugin: AbsExtraConfigPlugin, platform: Platform, evt: MessageEvent) -> deque:
# 创建系统提示词上下文 # 创建系统提示词上下文
system_context = deque() system_context = deque()
# 生成当前时间 # 生成当前时间

16
maubot_llmplus/plugin.py Normal file
View File

@@ -0,0 +1,16 @@
from maubot import Plugin
class AbsExtraConfigPlugin(Plugin):
default_username: str
user_id: 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]
def get_bot_name(self) -> str:
return self.config['name'] or \
self.default_username or \
self.user_id