mirror of https://github.com/Mai-with-u/MaiBot.git
继续继续
parent
a9179856eb
commit
5bb1f4ae4d
|
|
@ -17,9 +17,8 @@ memory_graph.gml
|
||||||
config/bot_config_dev.toml
|
config/bot_config_dev.toml
|
||||||
config/bot_config.toml
|
config/bot_config.toml
|
||||||
config/bot_config.toml.bak
|
config/bot_config.toml.bak
|
||||||
config/actions.py
|
|
||||||
config/__init__.py
|
|
||||||
src/plugins/remote/client_uuid.json
|
src/plugins/remote/client_uuid.json
|
||||||
|
src/plugins/action_executer/actions.py
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,11 @@ def update_config():
|
||||||
old_config_path = config_dir / "bot_config.toml"
|
old_config_path = config_dir / "bot_config.toml"
|
||||||
new_config_path = config_dir / "bot_config.toml"
|
new_config_path = config_dir / "bot_config.toml"
|
||||||
action_template_path = template_dir / "actions_template.py"
|
action_template_path = template_dir / "actions_template.py"
|
||||||
action_config_path = config_dir / "actions.py"
|
action_config_path = root_dir / "src" / "plugins" / "action_executer" / "actions.py"
|
||||||
|
|
||||||
# 如果config里没有actions.py就复制一份过来
|
# 如果action_executer里没有actions.py就复制一份过来
|
||||||
if not action_config_path.exists():
|
if not action_config_path.exists():
|
||||||
shutil.copy(action_template_path, action_config_path)
|
shutil.copy(action_template_path, action_config_path)
|
||||||
Path('config/__init__.py').touch()
|
|
||||||
|
|
||||||
# 读取旧配置文件
|
# 读取旧配置文件
|
||||||
old_config = {}
|
old_config = {}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
from src.common.logger import get_module_logger
|
||||||
|
logger = get_module_logger("action_executer")
|
||||||
|
|
||||||
class ResponseAction:
|
class ResponseAction:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.tags = []
|
self.tags = []
|
||||||
|
|
@ -5,6 +8,7 @@ class ResponseAction:
|
||||||
|
|
||||||
def parse_action(self, msg: str, action: str) -> str:
|
def parse_action(self, msg: str, action: str) -> str:
|
||||||
if action in msg:
|
if action in msg:
|
||||||
|
logger.info(f"从消息中解析到{action}标签")
|
||||||
self.tags.append(action)
|
self.tags.append(action)
|
||||||
return msg.replace(action, '')
|
return msg.replace(action, '')
|
||||||
return msg
|
return msg
|
||||||
|
|
@ -20,14 +24,14 @@ class ResponseAction:
|
||||||
raise TypeError
|
raise TypeError
|
||||||
|
|
||||||
|
|
||||||
|
from .actions import usable_action_description
|
||||||
|
|
||||||
from ....config.actions import usable_action_description
|
|
||||||
|
|
||||||
extern_prompt = f"""
|
extern_prompt = f"""
|
||||||
`<UseableAction>`
|
`<UseableAction>`
|
||||||
{'\n'.join(usable_action_description)}
|
{usable_action_description}
|
||||||
`</UseableAction>`
|
`</UseableAction>`
|
||||||
你可以使用**`<UseableAction>`**中给出的标签来执行特定动作,请参考对应部分的描述。
|
你可以使用**`<UseableAction>`**中给出的标签来执行特定动作,请参考对应部分的描述。
|
||||||
注意,标签一定是以“[内容]”形式输出的,你可以在一次响应中执行多个动作。
|
注意,标签一定是以“[内容]”形式输出的,你可以在一次响应中执行多个动作。
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
logger.info("成功加载可用动作")
|
||||||
|
|
@ -191,10 +191,10 @@ class ChatBot:
|
||||||
willing_manager.change_reply_willing_not_sent(chat)
|
willing_manager.change_reply_willing_not_sent(chat)
|
||||||
|
|
||||||
# print(f"response: {response}")
|
# print(f"response: {response}")
|
||||||
response_action = None
|
response_actions = None
|
||||||
if global_config.enable_action_execute:
|
if global_config.enable_action_execute:
|
||||||
from ..action_executer.action_executer import ResponseAction
|
from ..action_executer.action_executer import ResponseAction
|
||||||
from ....config.actions import usable_action
|
from ..action_executer.actions import usable_action
|
||||||
if isinstance(response, ResponseAction):
|
if isinstance(response, ResponseAction):
|
||||||
response_actions = response.tags
|
response_actions = response.tags
|
||||||
response = response.msgs
|
response = response.msgs
|
||||||
|
|
@ -229,9 +229,10 @@ class ChatBot:
|
||||||
return
|
return
|
||||||
|
|
||||||
# 清理掉思考消息后开始做发送前处理
|
# 清理掉思考消息后开始做发送前处理
|
||||||
if global_config.enable_action_execute:
|
if global_config.enable_action_execute and response_actions:
|
||||||
for action in response_action:
|
for action in response_actions:
|
||||||
await response = usable_action[action](response)
|
response = usable_action[action](response)
|
||||||
|
logger.info(f"正在处理{action}")
|
||||||
|
|
||||||
# 记录开始思考的时间,避免从思考到回复的时间太久
|
# 记录开始思考的时间,避免从思考到回复的时间太久
|
||||||
thinking_start_time = thinking_message.thinking_start_time
|
thinking_start_time = thinking_message.thinking_start_time
|
||||||
|
|
|
||||||
|
|
@ -70,15 +70,15 @@ class ResponseGenerator:
|
||||||
|
|
||||||
if global_config.enable_action_execute:
|
if global_config.enable_action_execute:
|
||||||
from ..action_executer.action_executer import ResponseAction
|
from ..action_executer.action_executer import ResponseAction
|
||||||
from ....config.actions import usable_action
|
from ..action_executer.actions import usable_action
|
||||||
actions = ResponseAction()
|
actions = ResponseAction()
|
||||||
|
logger.info(f"{global_config.BOT_NICKNAME}的原始回复是:{model_response}")
|
||||||
for action in usable_action:
|
for action in usable_action:
|
||||||
model_response = actions.parse_action(model_response, action)
|
model_response = actions.parse_action(model_response, action)
|
||||||
if not actions.empty():
|
if not actions.empty():
|
||||||
actions.msgs = await self._process_response(model_response)
|
actions.msgs = await self._process_response(model_response)
|
||||||
if actions.msgs:
|
if actions.msgs:
|
||||||
return actions, raw_content
|
return actions, raw_content
|
||||||
return None, raw_content
|
|
||||||
|
|
||||||
if model_response:
|
if model_response:
|
||||||
logger.info(f"{global_config.BOT_NICKNAME}的回复是:{model_response}")
|
logger.info(f"{global_config.BOT_NICKNAME}的回复是:{model_response}")
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,17 @@
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from ..chat.config import global_config
|
||||||
|
from src.common.logger import get_module_logger
|
||||||
|
logger = get_module_logger("Actions")
|
||||||
|
|
||||||
# 示例函数
|
# 示例函数
|
||||||
async def refuse_response(response: list[str]) -> list[str]:
|
def refuse_response(response: list[str]) -> list[str]:
|
||||||
|
logger.info(f"{global_config.BOT_NICKNAME}认为不需要进行回复。")
|
||||||
return []
|
return []
|
||||||
async def ping_response(response: list[str]) -> list[str]:
|
|
||||||
|
def ping_response(response: list[str]) -> list[str]:
|
||||||
|
logger.info(f"{global_config.BOT_NICKNAME}认为这是测试是否在线。")
|
||||||
return [f"Pong! at {time.asctime()}."]
|
return [f"Pong! at {time.asctime()}."]
|
||||||
|
|
||||||
# 可用函数表 注意每个函数都应该接收一个list[str](输入的响应), 输出一个list[str](输出的响应)
|
# 可用函数表 注意每个函数都应该接收一个list[str](输入的响应), 输出一个list[str](输出的响应)
|
||||||
|
|
@ -15,7 +22,7 @@ usable_action: dict[str, Callable[[list[str]], list[str]]] = {
|
||||||
"[refuse]" : refuse_response,
|
"[refuse]" : refuse_response,
|
||||||
}
|
}
|
||||||
|
|
||||||
usable_action_description = [
|
usable_action_description = """
|
||||||
"[ping]: 此标签**仅**用于用户确认系统是否在线,输出此标签会**导致消息被替换为**`Pong! at %当前时间%`"
|
[ping]: 此标签**仅在用户输入--Ping时**使用,输出此标签会**导致消息被替换为**`Pong! at %当前时间%`;
|
||||||
"[refuse]: 此标签用于标识认为无需回复的情况,输出此标签会**使得消息不被发送**。",
|
[refuse]: 此标签用于标识认为无需回复的情况,输出此标签会**使得消息不被发送**;
|
||||||
]
|
"""
|
||||||
|
|
@ -135,6 +135,7 @@ enable = true
|
||||||
enable_friend_chat = false # 是否启用好友聊天
|
enable_friend_chat = false # 是否启用好友聊天
|
||||||
enable_think_flow = false # 是否启用思维流 注意:可能会消耗大量token,请谨慎开启
|
enable_think_flow = false # 是否启用思维流 注意:可能会消耗大量token,请谨慎开启
|
||||||
#思维流适合搭配低能耗普通模型使用,例如qwen2.5 32b
|
#思维流适合搭配低能耗普通模型使用,例如qwen2.5 32b
|
||||||
|
enable_action_execute = false # 是否启用动作执行器
|
||||||
|
|
||||||
#下面的模型若使用硅基流动则不需要更改,使用ds官方则改成.env.prod自定义的宏,使用自定义模型则选择定位相似的模型自己填写
|
#下面的模型若使用硅基流动则不需要更改,使用ds官方则改成.env.prod自定义的宏,使用自定义模型则选择定位相似的模型自己填写
|
||||||
#推理模型
|
#推理模型
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue