modify process_messages
This commit is contained in:
parent
38d22ff92e
commit
b000fe6b6d
@ -198,8 +198,7 @@ def process_messages(messages: List[Dict], language: Optional[str] = None) -> Li
|
||||
elif current_tag == "ANSWER":
|
||||
# 所有ASSISTANT消息都保留ANSWER数据
|
||||
filtered_content += f"[ANSWER]\n{text}\n"
|
||||
else:
|
||||
# 第一个标签之前的内容
|
||||
elif current_tag != "THINK":
|
||||
filtered_content += text + "\n"
|
||||
else: # 标签
|
||||
current_tag = parts[i]
|
||||
@ -239,7 +238,7 @@ def process_messages(messages: List[Dict], language: Optional[str] = None) -> Li
|
||||
function_name = lines[0].strip() if lines else ""
|
||||
response_content = lines[1].strip() if len(lines) > 1 else ""
|
||||
|
||||
tool_responses.append({
|
||||
final_messages.append({
|
||||
"role": FUNCTION,
|
||||
"name": function_name,
|
||||
"content": response_content
|
||||
@ -250,31 +249,21 @@ def process_messages(messages: List[Dict], language: Optional[str] = None) -> Li
|
||||
function_name = lines[0].strip() if lines else ""
|
||||
arguments = lines[1].strip() if len(lines) > 1 else ""
|
||||
|
||||
function_calls.append({
|
||||
"name": function_name,
|
||||
"arguments": arguments
|
||||
final_messages.append({
|
||||
"role": ASSISTANT,
|
||||
"content": "",
|
||||
"function_call": {
|
||||
"name": function_name,
|
||||
"arguments": arguments
|
||||
}
|
||||
})
|
||||
elif current_tag != "THINK":
|
||||
final_messages.append({
|
||||
"role": ASSISTANT,
|
||||
"content": text
|
||||
})
|
||||
elif current_tag == "ANSWER":
|
||||
assistant_content += text + "\n"
|
||||
else:
|
||||
# 第一个标签之前的内容也属于 assistant
|
||||
assistant_content += text + "\n"
|
||||
else: # 标签
|
||||
current_tag = parts[i]
|
||||
|
||||
# 添加 assistant 消息(如果有内容)
|
||||
if assistant_content.strip() or function_calls:
|
||||
assistant_msg = {"role": ASSISTANT}
|
||||
if assistant_content.strip():
|
||||
assistant_msg["content"] = assistant_content.strip()
|
||||
|
||||
# 如果有多个 function_call,只取第一个(兼容原有逻辑)
|
||||
# if function_calls:
|
||||
# assistant_msg["function_call"] = function_calls[0]
|
||||
final_messages.append(assistant_msg)
|
||||
|
||||
# 添加所有 tool_responses 作为 function 消息
|
||||
# final_messages.extend(tool_responses)
|
||||
else:
|
||||
# 非 assistant 消息或不包含 [TOOL_RESPONSE] 的消息直接添加
|
||||
final_messages.append(msg)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user