Co-Authored-By: dulicon <57261058+dulicon@users.noreply.github.com>
This commit is contained in:
Timothy Jaeryang Baek 2025-04-10 20:01:07 -07:00
parent a47a958edd
commit 1921420319

View file

@ -1660,14 +1660,27 @@ async def process_chat_response(
) )
if tool_call_index is not None: if tool_call_index is not None:
if ( # Check if the tool call already exists
len(response_tool_calls) current_response_tool_call = None
<= tool_call_index for (
): response_tool_call
) in response_tool_calls:
if (
response_tool_call.get("index")
== tool_call_index
):
current_response_tool_call = (
response_tool_call
)
break
if current_response_tool_call is None:
# Add the new tool call
response_tool_calls.append( response_tool_calls.append(
delta_tool_call delta_tool_call
) )
else: else:
# Update the existing tool call
delta_name = delta_tool_call.get( delta_name = delta_tool_call.get(
"function", {} "function", {}
).get("name") ).get("name")
@ -1678,16 +1691,14 @@ async def process_chat_response(
) )
if delta_name: if delta_name:
response_tool_calls[ current_response_tool_call[
tool_call_index "function"
]["function"][ ]["name"] += delta_name
"name"
] += delta_name
if delta_arguments: if delta_arguments:
response_tool_calls[ current_response_tool_call[
tool_call_index "function"
]["function"][ ][
"arguments" "arguments"
] += delta_arguments ] += delta_arguments