fix(anthropic): skip tool calls with empty names to prevent API errors (#1739)
When building parameters for Anthropic API calls, tool calls with empty names would cause 400 Bad Request errors with the message: 'tool_use.name: String should have at least 1 character' This fix adds a check to skip tool calls that have empty names, preventing the API error and allowing the conversation to continue normally. Fixes #1658
This commit is contained in:
parent
12f4029610
commit
54654d2794
1 changed files with 4 additions and 0 deletions
|
|
@ -180,6 +180,10 @@ func buildParams(
|
||||||
blocks = append(blocks, anthropic.NewTextBlock(msg.Content))
|
blocks = append(blocks, anthropic.NewTextBlock(msg.Content))
|
||||||
}
|
}
|
||||||
for _, tc := range msg.ToolCalls {
|
for _, tc := range msg.ToolCalls {
|
||||||
|
// Skip tool calls with empty names to avoid API errors
|
||||||
|
if tc.Name == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
args := tc.Arguments
|
args := tc.Arguments
|
||||||
if args == nil && tc.Function != nil && tc.Function.Arguments != "" {
|
if args == nil && tc.Function != nil && tc.Function.Arguments != "" {
|
||||||
if err := json.Unmarshal([]byte(tc.Function.Arguments), &args); err != nil {
|
if err := json.Unmarshal([]byte(tc.Function.Arguments), &args); err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue