pull/1432/head
墨梓柒 2025-12-13 15:13:25 +08:00
commit ef377bb0cd
No known key found for this signature in database
GPG Key ID: 4A65B9DBA35F7635
9 changed files with 58 additions and 54 deletions

View File

@ -147,7 +147,7 @@ expression_reflector_manager = ExpressionReflectorManager()
async def _check_tracker_exists(operator_config: str) -> bool:
"""检查指定 Operator 是否已有活跃的 Tracker"""
from src.express.reflect_tracker import reflect_tracker_manager
from src.bw_learner.reflect_tracker import reflect_tracker_manager
chat_manager = get_chat_manager()
chat_stream = None
@ -242,7 +242,7 @@ async def _send_to_operator(operator_config: str, text: str, expr: Expression):
stream_id = chat_stream.stream_id
# 注册 Tracker
from src.express.reflect_tracker import ReflectTracker, reflect_tracker_manager
from src.bw_learner.reflect_tracker import ReflectTracker, reflect_tracker_manager
tracker = ReflectTracker(chat_stream=chat_stream, expression=expr, created_time=time.time())
reflect_tracker_manager.add_tracker(stream_id, tracker)

View File

@ -605,7 +605,18 @@ class HeartFChatting:
self.consecutive_no_reply_count = 0
reason = action_planner_info.reasoning or ""
think_level = action_planner_info.action_data.get("think_level", 1)
# 根据 think_mode 配置决定 think_level 的值
think_mode = global_config.chat.think_mode
if think_mode == "default":
think_level = 0
elif think_mode == "deep":
think_level = 1
elif think_mode == "dynamic":
# dynamic 模式:从 planner 返回的 action_data 中获取
think_level = action_planner_info.action_data.get("think_level", 1)
else:
# 默认使用 default 模式
think_level = 0
# 使用 action_reasoningplanner 的整体思考理由)作为 reply_reason
planner_reasoning = action_planner_info.action_reasoning or reason

View File

@ -47,8 +47,7 @@ reply
2.你可以自然的顺着正在进行的聊天内容进行回复或自然的提出一个问题
3.不要选择回复你自己发送的消息
4.不要单独对表情包进行回复
5.think_level表示思考深度0表示该回复不需要思考和回忆1表示该回复需要进行回忆和思考
{{"action":"reply", "think_level":数值等级(0或1), "target_messamge_id":"消息id(m+数字)"}}
{reply_action_example}
no_reply
动作描述
@ -69,7 +68,7 @@ no_reply
{moderation_prompt}
target_message_id为必填表示触发消息的id
请选择所有符合使用要求的action动作用json格式输出```json包裹如果输出多个json每个json都要单独一行放在同一个```json代码块内你可以重复使用同一个动作或不同动作:
请选择所有符合使用要求的action动作用json格式输出```json包裹如果输出多个json每个json都要单独一行放在同一个```json代码块内:
**示例**
// 理由文本简短
```json
@ -78,43 +77,8 @@ target_message_id为必填表示触发消息的id
```""",
"planner_prompt",
)
Prompt(
"""{time_block}
{name_block}
{chat_context_description}以下是具体的聊天内容
**聊天内容**
{chat_content_block}
**可选的action**
no_reply
动作描述
没有合适的可以使用的动作不使用action
{{"action":"no_reply"}}
{action_options_text}
**你之前的action执行和思考记录**
{actions_before_now_block}
请选择**可选的**且符合使用条件的action并说明触发action的消息id(消息id格式:m+数字)
先输出你的简短的选择思考理由再输出你选择的action理由不要分点精简
**动作选择要求**
请你根据聊天内容,用户的最新消息和以下标准选择合适的动作:
1.思考**所有**的可用的action中的**每个动作**是否符合当下条件如果动作使用条件符合聊天内容就使用
2.如果相同的内容已经被执行请不要重复执行
{moderation_prompt}
请选择所有符合使用要求的action动作用json格式输出```json包裹如果输出多个json每个json都要单独一行放在同一个```json代码块内你可以重复使用同一个动作或不同动作:
**示例**
// 理由文本简短
```json
{{"action":"动作名", "target_message_id":"m123"}}
{{"action":"动作名", "target_message_id":"m456"}}
```""",
"planner_prompt_mentioned",
)
Prompt(
"""
{action_name}
@ -450,6 +414,12 @@ class ActionPlanner:
)
name_block = f"你的名字是{bot_name}{bot_nickname},请注意哪些是你自己的发言。"
# 根据 think_mode 配置决定 reply action 的示例 JSON
if global_config.chat.think_mode == "classic":
reply_action_example = '{{"action":"reply", "target_messamge_id":"消息id(m+数字)"}}'
else:
reply_action_example = '5.think_level表示思考深度0表示该回复不需要思考和回忆1表示该回复需要进行回忆和思考\n{{"action":"reply", "think_level":数值等级(0或1), "target_messamge_id":"消息id(m+数字)"}}'
planner_prompt_template = await global_prompt_manager.get_prompt_async("planner_prompt")
prompt = planner_prompt_template.format(
time_block=time_block,
@ -461,6 +431,7 @@ class ActionPlanner:
name_block=name_block,
interest=interest,
plan_style=global_config.personality.plan_style,
reply_action_example=reply_action_example,
)
return prompt, message_id_list

View File

@ -16,7 +16,8 @@ def init_replyer_prompt():
{planner_reasoning}
{identity}
{chat_prompt}你正在群里聊天,现在请你读读之前的聊天记录然后给出日常且口语化的回复
尽量简短一些{keywords_reaction_prompt}请注意把握聊天内容不要回复的太有条理
尽量简短一些{keywords_reaction_prompt}
请注意把握聊天内容不要回复的太有条理
{reply_style}
请注意不要输出多余内容(包括不必要的前后缀冒号括号表情包at或 @等 )只输出发言内容就好
现在你说""",
@ -35,8 +36,9 @@ def init_replyer_prompt():
{reply_target_block}
{planner_reasoning}
{identity}
{chat_prompt}你正在群里聊天,现在请你读读之前的聊天记录把握当前的话题然后给出回复
{keywords_reaction_prompt}请注意把握聊天内容
{chat_prompt}你正在群里聊天,现在请你读读之前的聊天记录把握当前的话题然后给出口语化回复
{keywords_reaction_prompt}
请注意把握聊天内容
{reply_style}
请注意不要输出多余内容(包括不必要的前后缀冒号括号at或 @等 )只输出发言内容就好
现在你说""",

View File

@ -108,6 +108,14 @@ class ChatConfig(ConfigBase):
时间区间支持跨夜例如 "23:00-02:00"
"""
think_mode: Literal["classic", "deep", "dynamic"] = "classic"
"""
思考模式配置
- classic: 默认think_level为0轻量回复不需要思考和回忆
- deep: 默认think_level为1深度回复需要进行回忆和思考
- dynamic: think_level由planner动态给出根据planner返回的think_level决定
"""
def _parse_stream_config_to_chat_id(self, stream_config_str: str) -> Optional[str]:
"""与 ChatStream.get_stream_id 一致地从 "platform:id:type" 生成 chat_id。"""
try:

View File

@ -98,7 +98,10 @@ def _convert_messages(
content: List[Part] = []
for item in message.content:
if isinstance(item, tuple):
image_format = "jpeg" if item[0].lower() == "jpg" else item[0].lower()
image_format = item[0].lower()
# 规范 JPEG MIME 类型后缀,统一使用 image/jpeg
if image_format in ("jpg", "jpeg"):
image_format = "jpeg"
content.append(Part.from_bytes(data=base64.b64decode(item[1]), mime_type=f"image/{image_format}"))
elif isinstance(item, str):
content.append(Part.from_text(text=item))

View File

@ -61,10 +61,16 @@ def _convert_messages(messages: list[Message]) -> list[ChatCompletionMessagePara
content = []
for item in message.content:
if isinstance(item, tuple):
image_format = item[0].lower()
# 规范 JPEG MIME 类型后缀,统一使用 image/jpeg
if image_format in ("jpg", "jpeg"):
mime_suffix = "jpeg"
else:
mime_suffix = image_format
content.append(
{
"type": "image_url",
"image_url": {"url": f"data:image/{item[0].lower()};base64,{item[1]}"},
"image_url": {"url": f"data:image/{mime_suffix};base64,{item[1]}"},
}
)
elif isinstance(item, str):

View File

@ -47,7 +47,7 @@ class EmojiAction(BaseAction):
try:
# 1. 获取发送表情的原因
# reason = self.action_data.get("reason", "表达当前情绪")
reason = self.reasoning
reason = self.action_reasoning
# 2. 随机获取20个表情包
sampled_emojis = await emoji_api.get_random(30)

View File

@ -1,5 +1,5 @@
[inner]
version = "7.1.5"
version = "7.1.6"
#----以下是给开发人员阅读的,如果你只是部署了麦麦,不需要阅读----
# 如果你想要修改配置文件请递增version的值
@ -22,10 +22,10 @@ alias_names = ["麦叠", "牢麦"] # 麦麦的别名
[personality]
# 建议120字以内描述人格特质 和 身份特征
personality = "是一个女大学生,现在在读大二,会刷贴吧。"
personality = "是一个大二在读女大学生,现在正在上网和群友聊天,有时有点攻击性,有时比较温柔"
# アイデンティティがない 生まれないらららら
# 描述麦麦说话的表达风格,表达习惯,如要修改,可以酌情新增内容
reply_style = "请回复的平淡一些,简短一些,说中文,不要刻意突出自身学科背景。可以参考贴吧,知乎和微博的回复风格。"
# 描述麦麦说话的表达风格,表达习惯,如要修改,可以酌情新增内容建议1-2行
reply_style = "请不要刻意突出自身学科背景。可以参考贴吧,知乎和微博的回复风格。"
# 麦麦的说话规则,行为风格:
plan_style = """
@ -34,7 +34,7 @@ plan_style = """
3.
4.
5.
6."""
6."""
# 麦麦识图规则,不建议修改
visual_style = "请用中文描述这张图片的内容。如果有文字请把文字描述概括出来请留意其主题直观感受输出为一段平文本最多30字请注意不要分点就输出一段文本"
@ -55,6 +55,8 @@ states = [
# 替换概率每次构建人格时替换personality的概率0.0-1.0
state_probability = 0.3
[expression]
# 表达学习配置
learning_list = [ # 表达学习配置列表,支持按聊天流配置
@ -89,6 +91,7 @@ talk_value = 1 # 聊天频率越小越沉默范围0-1
mentioned_bot_reply = true # 是否启用提及必回复
max_context_size = 30 # 上下文长度
planner_smooth = 3 # 规划器平滑增大数值会减小planner负荷略微降低反应速度推荐1-50为关闭必须大于等于0
think_mode = "dynamic" # 思考模式可选classic默认浅度思考和回复、deep会进行比较长的深度回复、dynamic动态选择两种模式
enable_talk_value_rules = true # 是否启用动态发言频率规则