mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 11:14:04 +00:00
Fix tool call coalescing
The previous code seemed to assume that the tool call index property started at 0, but Anthropic sometimes returns them starting at 1. This was causing an extra null-ish tool call to be materialized.
This commit is contained in:
parent
0f301a120f
commit
b4df896ac9
1 changed files with 4 additions and 1 deletions
|
@ -5094,7 +5094,7 @@ def stream_chunk_builder(
|
|||
name = None
|
||||
type = None
|
||||
tool_calls_list = []
|
||||
prev_index = 0
|
||||
prev_index = None
|
||||
prev_id = None
|
||||
curr_id = None
|
||||
curr_index = 0
|
||||
|
@ -5120,6 +5120,8 @@ def stream_chunk_builder(
|
|||
name = tool_calls[0].function.name
|
||||
if tool_calls[0].type:
|
||||
type = tool_calls[0].type
|
||||
if prev_index is None:
|
||||
prev_index = curr_index
|
||||
if curr_index != prev_index: # new tool call
|
||||
combined_arguments = "".join(argument_list)
|
||||
tool_calls_list.append(
|
||||
|
@ -5138,6 +5140,7 @@ def stream_chunk_builder(
|
|||
tool_calls_list.append(
|
||||
{
|
||||
"id": id,
|
||||
"index": curr_index,
|
||||
"function": {"arguments": combined_arguments, "name": name},
|
||||
"type": type,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue