diff --git a/relay/channel/claude/adaptor.go b/relay/channel/claude/adaptor.go index b9173af..a1b26a8 100644 --- a/relay/channel/claude/adaptor.go +++ b/relay/channel/claude/adaptor.go @@ -50,11 +50,18 @@ func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) { func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Request, info *relaycommon.RelayInfo) error { channel.SetupApiRequestHeader(info, c, req) req.Header.Set("x-api-key", info.ApiKey) + anthropicVersion := c.Request.Header.Get("anthropic-version") if anthropicVersion == "" { anthropicVersion = "2023-06-01" } req.Header.Set("anthropic-version", anthropicVersion) + + anthropicBeta := c.Request.Header.Get("anthropic-beta") + if "" != anthropicBeta { + req.Header.Set("anthropic-beta", anthropicBeta) + } + return nil } diff --git a/relay/channel/claude/dto.go b/relay/channel/claude/dto.go index 8f289e3..35b08a4 100644 --- a/relay/channel/claude/dto.go +++ b/relay/channel/claude/dto.go @@ -31,9 +31,13 @@ type ClaudeMessage struct { } type Tool struct { - Name string `json:"name"` - Description string `json:"description,omitempty"` - InputSchema map[string]interface{} `json:"input_schema"` + Name string `json:"name"` + Description any `json:"description,omitempty"` + InputSchema map[string]interface{} `json:"input_schema,omitempty"` + Type any `json:"type,omitempty"` + DisplayHeightPx int `json:"display_height_px,omitempty"` + DisplayWidthPx int `json:"display_width_px,omitempty"` + DisplayNumber int `json:"display_number,omitempty"` } type InputSchema struct { diff --git a/relay/channel/claude/relay-claude.go b/relay/channel/claude/relay-claude.go index 34c0283..b2ab4e6 100644 --- a/relay/channel/claude/relay-claude.go +++ b/relay/channel/claude/relay-claude.go @@ -63,23 +63,44 @@ func RequestOpenAI2ClaudeMessage(textRequest dto.GeneralOpenAIRequest) (*ClaudeR claudeTools := make([]Tool, 0, len(textRequest.Tools)) for _, tool := range textRequest.Tools { - if params, ok := tool.Function.Parameters.(map[string]any); ok { - claudeTool := Tool{ - Name: tool.Function.Name, - Description: tool.Function.Description, - } - claudeTool.InputSchema = make(map[string]interface{}) - claudeTool.InputSchema["type"] = params["type"].(string) - claudeTool.InputSchema["properties"] = params["properties"] - claudeTool.InputSchema["required"] = params["required"] - for s, a := range params { - if s == "type" || s == "properties" || s == "required" { - continue - } - claudeTool.InputSchema[s] = a - } - claudeTools = append(claudeTools, claudeTool) + claudeTool := Tool{ + Name: tool.Function.Name, + Description: tool.Function.Description, + Type: tool.Type, } + + if "function" != tool.Type { + claudeTool.Description = nil + } + + if params, ok := tool.Function.Parameters.(map[string]any); ok { + if "function" == tool.Type { + claudeTool.Type = nil + + claudeTool.InputSchema = make(map[string]interface{}) + claudeTool.InputSchema["type"] = params["type"].(string) + claudeTool.InputSchema["properties"] = params["properties"] + claudeTool.InputSchema["required"] = params["required"] + for s, a := range params { + if s == "type" || s == "properties" || s == "required" { + continue + } + claudeTool.InputSchema[s] = a + } + } else { + if val, ok := params["display_height_px"]; ok { + claudeTool.DisplayHeightPx = int(val.(float64)) + } + if val, ok := params["display_width_px"]; ok { + claudeTool.DisplayWidthPx = int(val.(float64)) + } + if val, ok := params["display_number"]; ok { + claudeTool.DisplayNumber = int(val.(float64)) + } + } + } + + claudeTools = append(claudeTools, claudeTool) } claudeRequest := ClaudeRequest{ @@ -91,6 +112,7 @@ func RequestOpenAI2ClaudeMessage(textRequest dto.GeneralOpenAIRequest) (*ClaudeR TopK: textRequest.TopK, Stream: textRequest.Stream, Tools: claudeTools, + ToolChoice: textRequest.ToolChoice, } if claudeRequest.MaxTokens == 0 { claudeRequest.MaxTokens = 4096