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

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

View File

@@ -27,11 +27,18 @@ class Config(BaseProxyConfig):
helper.copy("platforms")
helper.copy("additional_prompt")
class AiBotPlugin(Plugin):
class AbsAiBotPlugin(Plugin):
default_username: str
user_id: str
def get_bot_name(self) -> str:
return self.config['name'] or \
self.default_username or \
self.user_id
class AiBotPlugin(AbsAiBotPlugin):
async def start(self) -> None:
await super().start()
# 加载并更新配置
@@ -69,11 +76,6 @@ class AiBotPlugin(Plugin):
5. 在thread中
"""
def get_bot_name(self, config: BaseProxyConfig):
return config['name'] or \
self.default_username or \
self.user_id
async def should_respond(self, event: MessageEvent) -> bool:
# 发送者是机器人本身, 返回False
if event.sender == self.client.mxid:
@@ -94,7 +96,7 @@ class AiBotPlugin(Plugin):
return False
# 检查是否发送消息中有带上机器人的别名
if re.search("(^|\\s)(@)?" + self.get_bot_name(self.config) + "([ :,.!?]|$)", event.content.body, re.IGNORECASE):
if re.search("(^|\\s)(@)?" + self.get_bot_name() + "([ :,.!?]|$)", event.content.body, re.IGNORECASE):
return True
# 当聊天室只有两个人并且其中一个是机器人时

View File

@@ -8,6 +8,8 @@ from maubot import Plugin
from mautrix.types import MessageEvent, EncryptedEvent
from mautrix.util.config import BaseProxyConfig
from maubot_llmplus.aibot import AbsAiBotPlugin
"""
AI响应对象
"""
@@ -60,14 +62,14 @@ class Platform:
async def get_context(plugin: Plugin, platform: Platform, evt: MessageEvent) -> deque:
async def get_context(plugin: AbsAiBotPlugin, platform: Platform, evt: MessageEvent) -> deque:
# 创建系统提示词上下文
system_context = deque()
# 生成当前时间
timestamp = datetime.today().strftime('%Y-%m-%d %H:%M:%S')
# 加入系统提示词
system_prompt = {"role": "system",
"content": plugin.config['system_prompt'].format(name=plugin.name, timestamp=timestamp)}
"content": plugin.config['system_prompt'].format(name=plugin.get_bot_name(), timestamp=timestamp)}
if plugin.config['enable_multi_user']:
system_prompt["content"] += """
User messages are in the context of multiperson chatrooms.