Merge branch 'dev' of https://github.com/MaiM-with-u/MaiBot into dev
This commit is contained in:
@@ -66,9 +66,9 @@
|
||||
|
||||
## 💬 讨论
|
||||
|
||||
- [一群](https://qm.qq.com/q/VQ3XZrWgMs) |
|
||||
[四群](https://qm.qq.com/q/wGePTl1UyY) |
|
||||
[二群](https://qm.qq.com/q/RzmCiRtHEW) |
|
||||
- [四群](https://qm.qq.com/q/wGePTl1UyY) |
|
||||
[一群](https://qm.qq.com/q/VQ3XZrWgMs)(已满) |
|
||||
[二群](https://qm.qq.com/q/RzmCiRtHEW)(已满) |
|
||||
[五群](https://qm.qq.com/q/JxvHZnxyec)(已满) |
|
||||
[三群](https://qm.qq.com/q/wlH5eT8OmQ)(已满)
|
||||
|
||||
|
||||
@@ -57,9 +57,9 @@ services:
|
||||
ports:
|
||||
- "8120:8080"
|
||||
volumes:
|
||||
- ./data/MaiMBot/MaiBot.db:/data/MaiBot.db
|
||||
- ./data/MaiMBot:/data/MaiMBot
|
||||
environment:
|
||||
- SQLITE_DATABASE=MaiBot.db # 你的数据库文件
|
||||
- SQLITE_DATABASE=MaiMBot/MaiBot.db # 你的数据库文件
|
||||
networks:
|
||||
- maim_bot
|
||||
networks:
|
||||
|
||||
@@ -131,6 +131,12 @@ class ChatBot:
|
||||
message = MessageRecv(message_data)
|
||||
group_info = message.message_info.group_info
|
||||
user_info = message.message_info.user_info
|
||||
if message.message_info.additional_config:
|
||||
sent_message = message.message_info.additional_config.get("echo", False)
|
||||
if sent_message: # 这一段只是为了在一切处理前劫持上报的自身消息,用于更新message_id,需要ada支持上报事件,实际测试中不会对正常使用造成任何问题
|
||||
await MessageStorage.update_message(message)
|
||||
return
|
||||
|
||||
get_chat_manager().register_message(message)
|
||||
|
||||
# 创建聊天流
|
||||
|
||||
@@ -101,5 +101,33 @@ class MessageStorage:
|
||||
except Exception:
|
||||
logger.exception("删除撤回消息失败")
|
||||
|
||||
# 如果需要其他存储相关的函数,可以在这里添加
|
||||
@staticmethod
|
||||
async def update_message(
|
||||
message: MessageRecv,
|
||||
) -> None: # 用于实时更新数据库的自身发送消息ID,目前能处理text,reply,image和emoji
|
||||
"""更新最新一条匹配消息的message_id"""
|
||||
try:
|
||||
if message.message_segment.type == "notify":
|
||||
mmc_message_id = message.message_segment.data.get("echo")
|
||||
qq_message_id = message.message_segment.data.get("actual_id")
|
||||
else:
|
||||
logger.info(f"更新消息ID错误,seg类型为{message.message_segment.type}")
|
||||
return
|
||||
if not qq_message_id:
|
||||
logger.info("消息不存在message_id,无法更新")
|
||||
return
|
||||
# 查询最新一条匹配消息
|
||||
matched_message = (
|
||||
Messages.select().where((Messages.message_id == mmc_message_id)).order_by(Messages.time.desc()).first()
|
||||
)
|
||||
|
||||
# 如果需要其他存储相关的函数,可以在这里添加
|
||||
if matched_message:
|
||||
# 更新找到的消息记录
|
||||
Messages.update(message_id=qq_message_id).where(Messages.id == matched_message.id).execute()
|
||||
logger.info(f"更新消息ID成功: {matched_message.message_id} -> {qq_message_id}")
|
||||
else:
|
||||
logger.debug("未找到匹配的消息")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"更新消息ID失败: {e}")
|
||||
|
||||
@@ -126,10 +126,9 @@ class PromptBuilder:
|
||||
(chat_stream.user_info.platform, chat_stream.user_info.user_id) if chat_stream.user_info else None,
|
||||
limit=global_config.normal_chat.max_context_size,
|
||||
)
|
||||
elif chat_stream.user_info:
|
||||
who_chat_in_group.append(
|
||||
(chat_stream.user_info.platform, chat_stream.user_info.user_id, chat_stream.user_info.user_nickname)
|
||||
)
|
||||
who_chat_in_group.append(
|
||||
(chat_stream.user_info.platform, chat_stream.user_info.user_id, chat_stream.user_info.user_nickname)
|
||||
)
|
||||
|
||||
relation_prompt = ""
|
||||
if global_config.relationship.enable_relationship:
|
||||
|
||||
@@ -160,8 +160,7 @@ class DefaultReplyer:
|
||||
return None
|
||||
|
||||
async def generate_reply_with_context(
|
||||
self,
|
||||
reply_data: Dict[str, Any],
|
||||
self, reply_data: Dict[str, Any], enable_splitter: bool = True, enable_chinese_typo: bool = True
|
||||
) -> Tuple[bool, Optional[List[str]]]:
|
||||
"""
|
||||
回复器 (Replier): 核心逻辑,负责生成回复文本。
|
||||
@@ -191,7 +190,7 @@ class DefaultReplyer:
|
||||
logger.error(f"{self.log_prefix}LLM 生成失败: {llm_e}")
|
||||
return False, None # LLM 调用失败则无法生成回复
|
||||
|
||||
processed_response = process_llm_response(content)
|
||||
processed_response = process_llm_response(content, enable_splitter, enable_chinese_typo)
|
||||
|
||||
# 5. 处理 LLM 响应
|
||||
if not content:
|
||||
@@ -214,8 +213,7 @@ class DefaultReplyer:
|
||||
return False, None
|
||||
|
||||
async def rewrite_reply_with_context(
|
||||
self,
|
||||
reply_data: Dict[str, Any],
|
||||
self, reply_data: Dict[str, Any], enable_splitter: bool = True, enable_chinese_typo: bool = True
|
||||
) -> Tuple[bool, Optional[List[str]]]:
|
||||
"""
|
||||
表达器 (Expressor): 核心逻辑,负责生成回复文本。
|
||||
@@ -252,7 +250,7 @@ class DefaultReplyer:
|
||||
logger.error(f"{self.log_prefix}LLM 生成失败: {llm_e}")
|
||||
return False, None # LLM 调用失败则无法生成回复
|
||||
|
||||
processed_response = process_llm_response(content)
|
||||
processed_response = process_llm_response(content, enable_splitter, enable_chinese_typo)
|
||||
|
||||
# 5. 处理 LLM 响应
|
||||
if not content:
|
||||
|
||||
@@ -321,7 +321,7 @@ def random_remove_punctuation(text: str) -> str:
|
||||
return result
|
||||
|
||||
|
||||
def process_llm_response(text: str) -> list[str]:
|
||||
def process_llm_response(text: str, enable_splitter: bool = True, enable_chinese_typo: bool = True) -> list[str]:
|
||||
if not global_config.response_post_process.enable_response_post_process:
|
||||
return [text]
|
||||
|
||||
@@ -359,14 +359,14 @@ def process_llm_response(text: str) -> list[str]:
|
||||
word_replace_rate=global_config.chinese_typo.word_replace_rate,
|
||||
)
|
||||
|
||||
if global_config.response_splitter.enable:
|
||||
if global_config.response_splitter.enable and enable_splitter:
|
||||
split_sentences = split_into_sentences_w_remove_punctuation(cleaned_text)
|
||||
else:
|
||||
split_sentences = [cleaned_text]
|
||||
|
||||
sentences = []
|
||||
for sentence in split_sentences:
|
||||
if global_config.chinese_typo.enable:
|
||||
if global_config.chinese_typo.enable and enable_chinese_typo:
|
||||
typoed_text, typo_corrections = typo_generator.create_typo_sentence(sentence)
|
||||
sentences.append(typoed_text)
|
||||
if typo_corrections:
|
||||
|
||||
@@ -73,6 +73,8 @@ async def generate_reply(
|
||||
chat_stream=None,
|
||||
action_data: Dict[str, Any] = None,
|
||||
chat_id: str = None,
|
||||
enable_splitter: bool = True,
|
||||
enable_chinese_typo: bool = True,
|
||||
) -> Tuple[bool, List[Tuple[str, Any]]]:
|
||||
"""生成回复
|
||||
|
||||
@@ -80,6 +82,8 @@ async def generate_reply(
|
||||
chat_stream: 聊天流对象(优先)
|
||||
action_data: 动作数据
|
||||
chat_id: 聊天ID(备用)
|
||||
enable_splitter: 是否启用消息分割器
|
||||
enable_chinese_typo: 是否启用错字生成器
|
||||
|
||||
Returns:
|
||||
Tuple[bool, List[Tuple[str, Any]]]: (是否成功, 回复集合)
|
||||
@@ -95,7 +99,7 @@ async def generate_reply(
|
||||
|
||||
# 调用回复器生成回复
|
||||
success, reply_set = await replyer.generate_reply_with_context(
|
||||
reply_data=action_data or {},
|
||||
reply_data=action_data or {}, enable_splitter=enable_splitter, enable_chinese_typo=enable_chinese_typo
|
||||
)
|
||||
|
||||
if success:
|
||||
@@ -114,6 +118,8 @@ async def rewrite_reply(
|
||||
chat_stream=None,
|
||||
reply_data: Dict[str, Any] = None,
|
||||
chat_id: str = None,
|
||||
enable_splitter: bool = True,
|
||||
enable_chinese_typo: bool = True,
|
||||
) -> Tuple[bool, List[Tuple[str, Any]]]:
|
||||
"""重写回复
|
||||
|
||||
@@ -121,6 +127,8 @@ async def rewrite_reply(
|
||||
chat_stream: 聊天流对象(优先)
|
||||
reply_data: 回复数据
|
||||
chat_id: 聊天ID(备用)
|
||||
enable_splitter: 是否启用消息分割器
|
||||
enable_chinese_typo: 是否启用错字生成器
|
||||
|
||||
Returns:
|
||||
Tuple[bool, List[Tuple[str, Any]]]: (是否成功, 回复集合)
|
||||
@@ -136,7 +144,7 @@ async def rewrite_reply(
|
||||
|
||||
# 调用回复器重写回复
|
||||
success, reply_set = await replyer.rewrite_reply_with_context(
|
||||
reply_data=reply_data or {},
|
||||
reply_data=reply_data or {}, enable_splitter=enable_splitter, enable_chinese_typo=enable_chinese_typo
|
||||
)
|
||||
|
||||
if success:
|
||||
|
||||
@@ -108,6 +108,8 @@ class BaseAction(ABC):
|
||||
# print(self.chat_stream.group_info)
|
||||
if self.chat_stream.group_info:
|
||||
self.is_group = True
|
||||
self.user_id = str(self.chat_stream.user_info.user_id)
|
||||
self.user_nickname = getattr(self.chat_stream.user_info, "user_nickname", None)
|
||||
self.group_id = str(self.chat_stream.group_info.group_id)
|
||||
self.group_name = getattr(self.chat_stream.group_info, "group_name", None)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user