Refactor ChunkToolCall handling in Anthropic provider
- Clean up the code for sending the initial ChunkToolCall, improving readability and maintaining alignment with OpenAI's format for tool name resolution. - Ensure that the chunk count is incremented after sending the tool call data, enhancing the message handling process in the streamWithRetry function.
This commit is contained in:
parent
a8fc21d070
commit
8a3dd148c7
1 changed files with 15 additions and 15 deletions
|
|
@ -363,22 +363,22 @@ func (p *Provider) streamWithRetry(ctx *context.Context, messages []context.Mess
|
||||||
}
|
}
|
||||||
startToolCallMessage(msgTracker, toolCallInfo, handler)
|
startToolCallMessage(msgTracker, toolCallInfo, handler)
|
||||||
|
|
||||||
// Send initial ChunkToolCall with id and function name
|
// Send initial ChunkToolCall with id and function name
|
||||||
// to match OpenAI format so CUI can resolve tool name from stored chunks
|
// to match OpenAI format so CUI can resolve tool name from stored chunks
|
||||||
if handler != nil {
|
if handler != nil {
|
||||||
toolCallData, _ := jsoniter.Marshal([]map[string]interface{}{
|
toolCallData, _ := jsoniter.Marshal([]map[string]interface{}{
|
||||||
{
|
{
|
||||||
"index": event.Index,
|
"index": event.Index,
|
||||||
"id": event.ContentBlock.ID,
|
"id": event.ContentBlock.ID,
|
||||||
"type": "function",
|
"type": "function",
|
||||||
"function": map[string]interface{}{
|
"function": map[string]interface{}{
|
||||||
"name": event.ContentBlock.Name,
|
"name": event.ContentBlock.Name,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
})
|
||||||
})
|
handler(message.ChunkToolCall, toolCallData)
|
||||||
handler(message.ChunkToolCall, toolCallData)
|
incrementChunk(msgTracker)
|
||||||
incrementChunk(msgTracker)
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue