feat: fix a tool calling issue with claude and update the oauth version (could change with newer claude code versions)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
55d5e89246
commit
08e5ca9eb1
2 changed files with 25 additions and 7 deletions
|
|
@ -486,8 +486,10 @@ func (al *AgentLoop) runLLMIteration(ctx context.Context, messages []providers.M
|
|||
for _, tc := range response.ToolCalls {
|
||||
argumentsJSON, _ := json.Marshal(tc.Arguments)
|
||||
assistantMsg.ToolCalls = append(assistantMsg.ToolCalls, providers.ToolCall{
|
||||
ID: tc.ID,
|
||||
Type: "function",
|
||||
ID: tc.ID,
|
||||
Type: "function",
|
||||
Name: tc.Name,
|
||||
Arguments: tc.Arguments,
|
||||
Function: &providers.FunctionCall{
|
||||
Name: tc.Name,
|
||||
Arguments: string(argumentsJSON),
|
||||
|
|
|
|||
|
|
@ -4,22 +4,38 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/anthropics/anthropic-sdk-go"
|
||||
"github.com/anthropics/anthropic-sdk-go/option"
|
||||
"github.com/sipeed/picoclaw/pkg/auth"
|
||||
)
|
||||
|
||||
// Would change with newer versions
|
||||
const oauthBetaHeader = "oauth-2025-04-20"
|
||||
|
||||
type ClaudeProvider struct {
|
||||
client *anthropic.Client
|
||||
tokenSource func() (string, error)
|
||||
}
|
||||
|
||||
func NewClaudeProvider(token string) *ClaudeProvider {
|
||||
client := anthropic.NewClient(
|
||||
option.WithAuthToken(token),
|
||||
func claudeClientOptions(token string) []option.RequestOption {
|
||||
opts := []option.RequestOption{
|
||||
option.WithBaseURL("https://api.anthropic.com"),
|
||||
)
|
||||
}
|
||||
if strings.HasPrefix(strings.TrimSpace(token), "sk-ant-oat") {
|
||||
opts = append(opts,
|
||||
option.WithAuthToken(token),
|
||||
option.WithHeader("anthropic-beta", oauthBetaHeader),
|
||||
)
|
||||
} else {
|
||||
opts = append(opts, option.WithAPIKey(token))
|
||||
}
|
||||
return opts
|
||||
}
|
||||
|
||||
func NewClaudeProvider(token string) *ClaudeProvider {
|
||||
client := anthropic.NewClient(claudeClientOptions(token)...)
|
||||
return &ClaudeProvider{client: &client}
|
||||
}
|
||||
|
||||
|
|
@ -36,7 +52,7 @@ func (p *ClaudeProvider) Chat(ctx context.Context, messages []Message, tools []T
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("refreshing token: %w", err)
|
||||
}
|
||||
opts = append(opts, option.WithAuthToken(tok))
|
||||
opts = append(opts, claudeClientOptions(tok)...)
|
||||
}
|
||||
|
||||
params, err := buildClaudeParams(messages, tools, model, options)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue