|
@@ -3,6 +3,7 @@ package aws
|
|
|
import (
|
|
import (
|
|
|
"fmt"
|
|
"fmt"
|
|
|
"net/http"
|
|
"net/http"
|
|
|
|
|
+ "strings"
|
|
|
|
|
|
|
|
"github.com/aws/aws-sdk-go-v2/aws"
|
|
"github.com/aws/aws-sdk-go-v2/aws"
|
|
|
"github.com/aws/aws-sdk-go-v2/service/bedrockruntime"
|
|
"github.com/aws/aws-sdk-go-v2/service/bedrockruntime"
|
|
@@ -27,7 +28,8 @@ const (
|
|
|
type Adaptor struct{}
|
|
type Adaptor struct{}
|
|
|
|
|
|
|
|
type Request struct {
|
|
type Request struct {
|
|
|
- AnthropicVersion string `json:"anthropic_version"`
|
|
|
|
|
|
|
+ AnthropicBeta []string `json:"anthropic_beta,omitempty"`
|
|
|
|
|
+ AnthropicVersion string `json:"anthropic_version"`
|
|
|
*relaymodel.ClaudeRequest
|
|
*relaymodel.ClaudeRequest
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -62,6 +64,10 @@ func (a *Adaptor) ConvertRequest(
|
|
|
}, nil
|
|
}, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+var supportedContextManagementEditsType = map[string]struct{}{
|
|
|
|
|
+ "clear_tool_uses_20250919": {},
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func handleChatCompletionsRequest(meta *meta.Meta, request *http.Request) ([]byte, error) {
|
|
func handleChatCompletionsRequest(meta *meta.Meta, request *http.Request) ([]byte, error) {
|
|
|
claudeReq, err := anthropic.OpenAIConvertRequest(meta, request)
|
|
claudeReq, err := anthropic.OpenAIConvertRequest(meta, request)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -78,6 +84,10 @@ func handleChatCompletionsRequest(meta *meta.Meta, request *http.Request) ([]byt
|
|
|
ClaudeRequest: claudeReq,
|
|
ClaudeRequest: claudeReq,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if betas := request.Header.Get(anthropic.AnthropicBeta); betas != "" {
|
|
|
|
|
+ req.AnthropicBeta = strings.Split(betas, ",")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return sonic.Marshal(req)
|
|
return sonic.Marshal(req)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -87,6 +97,33 @@ func handleAnthropicRequest(meta *meta.Meta, request *http.Request) ([]byte, err
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if betas := request.Header.Get(anthropic.AnthropicBeta); betas != "" {
|
|
|
|
|
+ node.SetAny("anthropic_beta", strings.Split(betas, ","))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ editesNode := node.GetByPath("context_management", "edits")
|
|
|
|
|
+ if editesNode.Check() == nil {
|
|
|
|
|
+ nodeLen, _ := editesNode.Len()
|
|
|
|
|
+ newEdits := make([]ast.Node, 0, nodeLen)
|
|
|
|
|
+ _ = editesNode.
|
|
|
|
|
+ ForEach(func(path ast.Sequence, node *ast.Node) bool {
|
|
|
|
|
+ t, err := node.Get("type").String()
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return true
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if _, ok := supportedContextManagementEditsType[t]; !ok {
|
|
|
|
|
+ return true
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ newEdits = append(newEdits, *node)
|
|
|
|
|
+
|
|
|
|
|
+ return true
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ *editesNode = ast.NewArray(newEdits)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
stream, _ := node.Get("stream").Bool()
|
|
stream, _ := node.Get("stream").Bool()
|
|
|
meta.Set("stream", stream)
|
|
meta.Set("stream", stream)
|
|
|
|
|
|