process_messages
This commit is contained in:
parent
0478163b2d
commit
2c4a839cef
@ -847,10 +847,23 @@ def process_messages(messages: List[Message], language: Optional[str] = None) ->
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if current_tag == "TOOL_RESPONSE":
|
if current_tag == "TOOL_RESPONSE":
|
||||||
# 统计 [TOOL_RESPONSE] 后面的文字长度,超过1000字符就丢弃
|
# 统计 [TOOL_RESPONSE] 后面的文字长度,超过500字就截取
|
||||||
if len(text) <= 1000:
|
if len(text) <= 500:
|
||||||
filtered_content += f"[TOOL_RESPONSE]\n{text}\n"
|
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":
|
elif current_tag == "TOOL_CALL":
|
||||||
filtered_content += f"[TOOL_CALL]\n{text}\n"
|
filtered_content += f"[TOOL_CALL]\n{text}\n"
|
||||||
elif current_tag == "ANSWER":
|
elif current_tag == "ANSWER":
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user