fix: merge consecutive tool_calls into single assistant message for Crof/OpenAI-compat

This commit is contained in:
admin
2026-05-19 19:48:40 +04:00
Unverified
parent 13a12d0763
commit 389866a2c6
2 changed files with 13 additions and 7 deletions

Binary file not shown.

View File

@@ -148,8 +148,19 @@ def oa_input_to_messages(input_data):
if isinstance(input_data, str):
msgs.append({"role": "user", "content": input_data})
elif isinstance(input_data, list):
pending_tool_calls = []
for item in input_data:
t = item.get("type")
if t == "function_call":
pending_tool_calls.append(
{"id": item.get("call_id", item.get("id", uid("tc"))),
"type": "function",
"function": {"name": item.get("name", ""),
"arguments": item.get("arguments", "{}")}})
continue
if pending_tool_calls:
msgs.append({"role": "assistant", "content": None, "tool_calls": pending_tool_calls})
pending_tool_calls = []
if t == "message":
role = item.get("role", "user")
if role == "developer":
@@ -167,16 +178,11 @@ def oa_input_to_messages(input_data):
break
if text is not None:
msgs.append({"role": role, "content": text})
elif t == "function_call":
msgs.append({"role": "assistant", "content": None, "tool_calls": [
{"id": item.get("call_id", item.get("id", uid("tc"))),
"type": "function",
"function": {"name": item.get("name", ""),
"arguments": item.get("arguments", "{}")}}
]})
elif t == "function_call_output":
msgs.append({"role": "tool", "tool_call_id": item.get("id", ""),
"content": item.get("output", "")})
if pending_tool_calls:
msgs.append({"role": "assistant", "content": None, "tool_calls": pending_tool_calls})
return msgs
def oa_convert_tools(tools):