修复了数据库无法读取记忆和知识的问题,以及图片保存问题

This commit is contained in:
SengokuCola
2025-03-12 15:32:25 +08:00
parent aab7fe1c5a
commit 3a61450642
6 changed files with 54 additions and 54 deletions

View File

@@ -88,13 +88,13 @@ def get_cloest_chat_from_db(db, length: int, timestamp: str):
list: 消息记录列表,每个记录包含时间和文本信息
"""
chat_records = []
closest_record = db.db.messages.find_one({"time": {"$lte": timestamp}}, sort=[('time', -1)])
closest_record = db.messages.find_one({"time": {"$lte": timestamp}}, sort=[('time', -1)])
if closest_record:
closest_time = closest_record['time']
chat_id = closest_record['chat_id'] # 获取chat_id
# 获取该时间戳之后的length条消息保持相同的chat_id
chat_records = list(db.db.messages.find(
chat_records = list(db.messages.find(
{
"time": {"$gt": closest_time},
"chat_id": chat_id # 添加chat_id过滤
@@ -128,7 +128,7 @@ async def get_recent_group_messages(db, chat_id:str, limit: int = 12) -> list:
"""
# 从数据库获取最近消息
recent_messages = list(db.db.messages.find(
recent_messages = list(db.messages.find(
{"chat_id": chat_id},
).sort("time", -1).limit(limit))
@@ -162,7 +162,7 @@ async def get_recent_group_messages(db, chat_id:str, limit: int = 12) -> list:
def get_recent_group_detailed_plain_text(db, chat_stream_id: int, limit: int = 12, combine=False):
recent_messages = list(db.db.messages.find(
recent_messages = list(db.messages.find(
{"chat_id": chat_stream_id},
{
"time": 1, # 返回时间字段