mirror of
https://github.com/Zippland/Bubbles.git
synced 2026-01-19 01:21:15 +08:00
history search
This commit is contained in:
@@ -241,6 +241,14 @@ def handle_chitchat(ctx: 'MessageContext', match: Optional[Match]) -> bool:
|
||||
context_window = arguments.get("context_window", 5)
|
||||
max_results = arguments.get("max_results", 20)
|
||||
|
||||
print(f"[search_chat_history] chat_id={chat_id}, keywords={deduped_keywords}, "
|
||||
f"context_window={context_window}, max_results={max_results}")
|
||||
if ctx.logger:
|
||||
ctx.logger.info(
|
||||
f"[search_chat_history] keywords={deduped_keywords}, "
|
||||
f"context_window={context_window}, max_results={max_results}"
|
||||
)
|
||||
|
||||
search_results = message_summary.search_messages_with_context(
|
||||
chat_id=chat_id,
|
||||
keywords=deduped_keywords,
|
||||
@@ -254,6 +262,10 @@ def handle_chitchat(ctx: 'MessageContext', match: Optional[Match]) -> bool:
|
||||
"keywords": deduped_keywords
|
||||
}
|
||||
|
||||
print(f"[search_chat_history] returned_groups={len(search_results)}")
|
||||
if ctx.logger:
|
||||
ctx.logger.info(f"[search_chat_history] returned_groups={len(search_results)}")
|
||||
|
||||
if not search_results:
|
||||
response_payload["notice"] = "No messages matched the provided keywords."
|
||||
|
||||
|
||||
@@ -9,12 +9,15 @@ import sqlite3 # 添加sqlite3模块
|
||||
import os # 用于处理文件路径
|
||||
from function.func_xml_process import XmlProcessor # 导入XmlProcessor
|
||||
|
||||
MAX_DB_HISTORY_LIMIT = 10000
|
||||
|
||||
|
||||
class MessageSummary:
|
||||
"""消息总结功能类 (使用SQLite持久化)
|
||||
用于记录、管理和生成聊天历史消息的总结
|
||||
"""
|
||||
|
||||
def __init__(self, max_history=200, db_path="data/message_history.db"): # 默认max_history 改为 200
|
||||
def __init__(self, max_history=MAX_DB_HISTORY_LIMIT, db_path="data/message_history.db"):
|
||||
"""初始化消息总结功能
|
||||
|
||||
Args:
|
||||
@@ -22,7 +25,21 @@ class MessageSummary:
|
||||
db_path: SQLite数据库文件路径
|
||||
"""
|
||||
self.LOG = logging.getLogger("MessageSummary")
|
||||
self.max_history = max_history # 使用传入的 max_history
|
||||
try:
|
||||
parsed_history_limit = int(max_history)
|
||||
except (TypeError, ValueError):
|
||||
parsed_history_limit = MAX_DB_HISTORY_LIMIT
|
||||
|
||||
if parsed_history_limit <= 0:
|
||||
parsed_history_limit = MAX_DB_HISTORY_LIMIT
|
||||
|
||||
if parsed_history_limit > MAX_DB_HISTORY_LIMIT:
|
||||
self.LOG.warning(
|
||||
f"传入的 max_history={parsed_history_limit} 超过上限,将截断为 {MAX_DB_HISTORY_LIMIT}"
|
||||
)
|
||||
parsed_history_limit = MAX_DB_HISTORY_LIMIT
|
||||
|
||||
self.max_history = parsed_history_limit
|
||||
self.db_path = db_path
|
||||
|
||||
# 实例化XML处理器用于提取引用消息
|
||||
|
||||
Reference in New Issue
Block a user