Merge branch 'MaiM-with-u:main-fix' into main-fix

This commit is contained in:
Bakadax
2025-03-22 14:09:35 +09:00
committed by GitHub
31 changed files with 1127 additions and 1770 deletions

View File

@@ -55,9 +55,9 @@ def is_mentioned_bot_in_message(message: MessageRecv) -> bool:
return False
async def get_embedding(text):
async def get_embedding(text, request_type="embedding"):
"""获取文本的embedding向量"""
llm = LLM_request(model=global_config.embedding, request_type="embedding")
llm = LLM_request(model=global_config.embedding, request_type=request_type)
# return llm.get_embedding_sync(text)
return await llm.get_embedding(text)
@@ -76,18 +76,11 @@ def calculate_information_content(text):
def get_closest_chat_from_db(length: int, timestamp: str):
"""从数据库中获取最接近指定时间戳的聊天记录
Args:
length: 要获取的消息数量
timestamp: 时间戳
Returns:
list: 消息记录列表,每个记录包含时间和文本信息
"""
# print(f"获取最接近指定时间戳的聊天记录,长度: {length}, 时间戳: {timestamp}")
# print(f"当前时间: {timestamp},转换后时间: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp))}")
chat_records = []
closest_record = db.messages.find_one({"time": {"$lte": timestamp}}, sort=[("time", -1)])
# print(f"最接近的记录: {closest_record}")
if closest_record:
closest_time = closest_record["time"]
chat_id = closest_record["chat_id"] # 获取chat_id
@@ -102,7 +95,9 @@ def get_closest_chat_from_db(length: int, timestamp: str):
.sort("time", 1)
.limit(length)
)
# print(f"获取到的记录: {chat_records}")
length = len(chat_records)
# print(f"获取到的记录长度: {length}")
# 转换记录格式
formatted_records = []
for record in chat_records:
@@ -335,7 +330,7 @@ def split_into_sentences_w_remove_punctuation(text: str) -> List[str]:
sentence = sentence.replace("", " ").replace(",", " ")
sentences_done.append(sentence)
logger.info(f"处理后的句子: {sentences_done}")
logger.debug(f"处理后的句子: {sentences_done}")
return sentences_done