Skip to content

Commit d7f2d45

Browse files
authored
fix: aws claude 4.6 not support context management (#471)
* fix: aws claude 4.6 not support context management * fix: ci lint
1 parent 26f322f commit d7f2d45

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

core/relay/adaptor/anthropic/main.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ func RemoveContextManagenetEdits(
5757
node *ast.Node,
5858
isSupportedEditsType ...func(t string) bool,
5959
) {
60-
editesNode := node.GetByPath("context_management", "edits")
60+
contextManagementNode := node.Get("context_management")
61+
if contextManagementNode.Check() != nil {
62+
return
63+
}
64+
65+
editesNode := contextManagementNode.GetByPath("edits")
6166
if editesNode.Check() != nil {
6267
return
6368
}
@@ -82,6 +87,11 @@ func RemoveContextManagenetEdits(
8287
return true
8388
})
8489

90+
if len(newEdits) == 0 {
91+
_, _ = contextManagementNode.Unset("edits")
92+
return
93+
}
94+
8595
*editesNode = ast.NewArray(newEdits)
8696
}
8797

core/relay/adaptor/aws/claude/adapter.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func fixBetas(model string, betas []string) []string {
8383

8484
var supportedContextManagementEditsType = map[string]struct{}{
8585
"clear_tool_uses_20250919": {},
86+
"clear_thinking_20251015": {},
8687
}
8788

8889
func handleChatCompletionsRequest(meta *meta.Meta, request *http.Request) ([]byte, error) {
@@ -121,10 +122,15 @@ func handleAnthropicRequest(meta *meta.Meta, request *http.Request) ([]byte, err
121122
)
122123
}
123124

124-
anthropic.RemoveContextManagenetEdits(node, func(t string) bool {
125-
_, ok := supportedContextManagementEditsType[t]
126-
return ok
127-
})
125+
if strings.Contains(meta.ActualModel, "4-6") {
126+
_, _ = node.Unset("context_management")
127+
} else {
128+
anthropic.RemoveContextManagenetEdits(node, func(t string) bool {
129+
_, ok := supportedContextManagementEditsType[t]
130+
return ok
131+
})
132+
}
133+
128134
anthropic.RemoveToolsExamples(node)
129135

130136
stream, _ := node.Get("stream").Bool()

0 commit comments

Comments
 (0)