Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions streamaccumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,14 @@ func (cc *ChatCompletion) accumulateDelta(chunk ChatCompletionChunk) bool {
for j := range delta.Delta.ToolCalls {
deltaTool := &delta.Delta.ToolCalls[j]

choice.Message.ToolCalls = expandToFit(choice.Message.ToolCalls, int(deltaTool.Index))
tool := &choice.Message.ToolCalls[deltaTool.Index]
// Handle negative tool call indices (sometimes -1 from Bedrock)
toolIndex := int(deltaTool.Index)
if toolIndex < 0 {
toolIndex = 0 // Default to 0 for negative indices
}

choice.Message.ToolCalls = expandToFit(choice.Message.ToolCalls, toolIndex)
tool := &choice.Message.ToolCalls[toolIndex]

if deltaTool.ID != "" {
tool.ID = deltaTool.ID
Expand Down