From b1be64bcf36b55c3981b0bbe2e00e16fda4e19d6 Mon Sep 17 00:00:00 2001 From: "1808837298@qq.com" <1808837298@qq.com> Date: Mon, 3 Mar 2025 20:06:08 +0800 Subject: [PATCH] fix: vertex claude --- relay/channel/aws/dto.go | 2 +- relay/channel/claude/dto.go | 2 +- relay/channel/vertex/adaptor.go | 8 +------- relay/channel/vertex/dto.go | 28 ++++++++++++++++++++++++---- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/relay/channel/aws/dto.go b/relay/channel/aws/dto.go index e87ed6ec..3b615134 100644 --- a/relay/channel/aws/dto.go +++ b/relay/channel/aws/dto.go @@ -14,7 +14,7 @@ type AwsClaudeRequest struct { TopP float64 `json:"top_p,omitempty"` TopK int `json:"top_k,omitempty"` StopSequences []string `json:"stop_sequences,omitempty"` - Tools []claude.Tool `json:"tools,omitempty"` + Tools any `json:"tools,omitempty"` ToolChoice any `json:"tool_choice,omitempty"` Thinking *claude.Thinking `json:"thinking,omitempty"` } diff --git a/relay/channel/claude/dto.go b/relay/channel/claude/dto.go index 90f06b26..9532ca74 100644 --- a/relay/channel/claude/dto.go +++ b/relay/channel/claude/dto.go @@ -58,7 +58,7 @@ type ClaudeRequest struct { TopK int `json:"top_k,omitempty"` //ClaudeMetadata `json:"metadata,omitempty"` Stream bool `json:"stream,omitempty"` - Tools []Tool `json:"tools,omitempty"` + Tools any `json:"tools,omitempty"` ToolChoice any `json:"tool_choice,omitempty"` Thinking *Thinking `json:"thinking,omitempty"` } diff --git a/relay/channel/vertex/adaptor.go b/relay/channel/vertex/adaptor.go index 0d8ccef1..fd592cc0 100644 --- a/relay/channel/vertex/adaptor.go +++ b/relay/channel/vertex/adaptor.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "github.com/gin-gonic/gin" - "github.com/jinzhu/copier" "io" "net/http" "one-api/dto" @@ -127,12 +126,7 @@ func (a *Adaptor) ConvertRequest(c *gin.Context, info *relaycommon.RelayInfo, re if err != nil { return nil, err } - vertexClaudeReq := &VertexAIClaudeRequest{ - AnthropicVersion: anthropicVersion, - } - if err = copier.Copy(vertexClaudeReq, claudeReq); err != nil { - return nil, errors.New("failed to copy claude request") - } + vertexClaudeReq := copyRequest(claudeReq, anthropicVersion) c.Set("request_model", claudeReq.Model) return vertexClaudeReq, nil } else if a.RequestMode == RequestModeGemini { diff --git a/relay/channel/vertex/dto.go b/relay/channel/vertex/dto.go index 3889c343..4ba570de 100644 --- a/relay/channel/vertex/dto.go +++ b/relay/channel/vertex/dto.go @@ -1,17 +1,37 @@ package vertex -import "one-api/relay/channel/claude" +import ( + "one-api/relay/channel/claude" +) type VertexAIClaudeRequest struct { AnthropicVersion string `json:"anthropic_version"` Messages []claude.ClaudeMessage `json:"messages"` - System string `json:"system,omitempty"` - MaxTokens int `json:"max_tokens,omitempty"` + System any `json:"system,omitempty"` + MaxTokens uint `json:"max_tokens,omitempty"` StopSequences []string `json:"stop_sequences,omitempty"` Stream bool `json:"stream,omitempty"` Temperature *float64 `json:"temperature,omitempty"` TopP float64 `json:"top_p,omitempty"` TopK int `json:"top_k,omitempty"` - Tools []claude.Tool `json:"tools,omitempty"` + Tools any `json:"tools,omitempty"` ToolChoice any `json:"tool_choice,omitempty"` + Thinking *claude.Thinking `json:"thinking,omitempty"` +} + +func copyRequest(req *claude.ClaudeRequest, version string) *VertexAIClaudeRequest { + return &VertexAIClaudeRequest{ + AnthropicVersion: version, + System: req.System, + Messages: req.Messages, + MaxTokens: req.MaxTokens, + Stream: req.Stream, + Temperature: req.Temperature, + TopP: req.TopP, + TopK: req.TopK, + StopSequences: req.StopSequences, + Tools: req.Tools, + ToolChoice: req.ToolChoice, + Thinking: req.Thinking, + } }