process_messages

This commit is contained in:
朱潮 2025-11-10 17:54:35 +08:00
parent 0478163b2d
commit 2c4a839cef

View File

@ -847,10 +847,23 @@ def process_messages(messages: List[Message], language: Optional[str] = None) ->
continue
if current_tag == "TOOL_RESPONSE":
# 统计 [TOOL_RESPONSE] 后面的文字长度,超过1000字符就丢弃
if len(text) <= 1000:
# 统计 [TOOL_RESPONSE] 后面的文字长度,超过500字就截取
if len(text) <= 500:
filtered_content += f"[TOOL_RESPONSE]\n{text}\n"
# 如果超过1000字符直接丢弃这块内容
else:
# 截取前中后3段内容每段250字
first_part = text[:250]
middle_start = len(text) // 2 - 125
middle_part = text[middle_start:middle_start + 250]
last_part = text[-250:]
# 计算省略的字数
omitted_count = len(text) - 750
omitted_text = f"...此处省略{omitted_count}字..."
# 拼接内容
truncated_text = f"{first_part}\n{omitted_text}\n{middle_part}\n{omitted_text}\n{last_part}"
filtered_content += f"[TOOL_RESPONSE]\n{truncated_text}\n"
elif current_tag == "TOOL_CALL":
filtered_content += f"[TOOL_CALL]\n{text}\n"
elif current_tag == "ANSWER":