-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Fix/aws header override #3066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Calcium-Ion
merged 8 commits into
QuantumNous:main
from
seefs001:fix/aws-header-override
Mar 2, 2026
Merged
Fix/aws header override #3066
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e5d5d1b
fix: aws claude header override
seefs001 5afa5d2
fill vertex/aws claude metadata
seefs001 4164498
chore: upgrade aws sdk
seefs001 02608b1
fix: merge legacy param overrides with operations when affinity templ…
seefs001 493e568
fix: prepend template operations before channel operations when mergi…
seefs001 decf628
fix: preserve channel scalar overrides while prepending template oper…
seefs001 1d3f770
feat: add clear action for channel param override editor
seefs001 11aec5b
fix: remove metadata
seefs001 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package aws | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "testing" | ||
|
|
||
| "github.com/QuantumNous/new-api/common" | ||
| relaycommon "github.com/QuantumNous/new-api/relay/common" | ||
| "github.com/aws/aws-sdk-go-v2/service/bedrockruntime" | ||
| "github.com/gin-gonic/gin" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestDoAwsClientRequest_AppliesRuntimeHeaderOverrideToAnthropicBeta(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| gin.SetMode(gin.TestMode) | ||
| recorder := httptest.NewRecorder() | ||
| ctx, _ := gin.CreateTestContext(recorder) | ||
| ctx.Request = httptest.NewRequest(http.MethodPost, "/v1/messages", nil) | ||
|
|
||
| info := &relaycommon.RelayInfo{ | ||
| OriginModelName: "claude-3-5-sonnet-20240620", | ||
| IsStream: false, | ||
| UseRuntimeHeadersOverride: true, | ||
| RuntimeHeadersOverride: map[string]any{ | ||
| "anthropic-beta": "computer-use-2025-01-24", | ||
| }, | ||
| ChannelMeta: &relaycommon.ChannelMeta{ | ||
| ApiKey: "access-key|secret-key|us-east-1", | ||
| UpstreamModelName: "claude-3-5-sonnet-20240620", | ||
| }, | ||
| } | ||
|
|
||
| requestBody := bytes.NewBufferString(`{"messages":[{"role":"user","content":"hello"}],"max_tokens":128}`) | ||
| adaptor := &Adaptor{} | ||
|
|
||
| _, err := doAwsClientRequest(ctx, info, adaptor, requestBody) | ||
| require.NoError(t, err) | ||
|
|
||
| awsReq, ok := adaptor.AwsReq.(*bedrockruntime.InvokeModelInput) | ||
| require.True(t, ok) | ||
|
|
||
| var payload map[string]any | ||
| require.NoError(t, common.Unmarshal(awsReq.Body, &payload)) | ||
|
|
||
| anthropicBeta, exists := payload["anthropic_beta"] | ||
| require.True(t, exists) | ||
|
|
||
| values, ok := anthropicBeta.([]any) | ||
| require.True(t, ok) | ||
| require.Equal(t, []any{"computer-use-2025-01-24"}, values) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -436,11 +436,46 @@ func mergeChannelOverride(base map[string]interface{}, tpl map[string]interface{ | |
| } | ||
| out := cloneStringAnyMap(base) | ||
| for k, v := range tpl { | ||
| if strings.EqualFold(strings.TrimSpace(k), "operations") { | ||
| baseOps, hasBaseOps := extractParamOperations(out[k]) | ||
| tplOps, hasTplOps := extractParamOperations(v) | ||
| if hasTplOps { | ||
| if hasBaseOps { | ||
| out[k] = append(tplOps, baseOps...) | ||
| } else { | ||
| out[k] = tplOps | ||
| } | ||
| continue | ||
| } | ||
| } | ||
|
Comment on lines
+439
to
+450
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Normalize the target Line 440 reads 🔧 Proposed fix for k, v := range tpl {
if strings.EqualFold(strings.TrimSpace(k), "operations") {
- baseOps, hasBaseOps := extractParamOperations(out[k])
+ opsKey := "operations"
+ for existingKey := range out {
+ if strings.EqualFold(strings.TrimSpace(existingKey), "operations") {
+ opsKey = existingKey
+ break
+ }
+ }
+ baseOps, hasBaseOps := extractParamOperations(out[opsKey])
tplOps, hasTplOps := extractParamOperations(v)
if hasTplOps {
- if hasBaseOps {
- out[k] = append(tplOps, baseOps...)
- } else {
- out[k] = tplOps
- }
+ mergedOps := tplOps
+ if hasBaseOps {
+ mergedOps = append(tplOps, baseOps...)
+ }
+ out[opsKey] = mergedOps
+ if opsKey != k {
+ delete(out, k)
+ }
continue
}
}
out[k] = v
}🤖 Prompt for AI Agents |
||
| if _, exists := out[k]; exists { | ||
| continue | ||
| } | ||
| out[k] = v | ||
| } | ||
| return out | ||
| } | ||
|
|
||
| func extractParamOperations(value interface{}) ([]interface{}, bool) { | ||
| switch ops := value.(type) { | ||
| case []interface{}: | ||
| if len(ops) == 0 { | ||
| return []interface{}{}, true | ||
| } | ||
| cloned := make([]interface{}, 0, len(ops)) | ||
| cloned = append(cloned, ops...) | ||
| return cloned, true | ||
| case []map[string]interface{}: | ||
| cloned := make([]interface{}, 0, len(ops)) | ||
| for _, op := range ops { | ||
| cloned = append(cloned, op) | ||
| } | ||
| return cloned, true | ||
| default: | ||
| return nil, false | ||
| } | ||
| } | ||
|
|
||
| func appendChannelAffinityTemplateAdminInfo(c *gin.Context, meta channelAffinityMeta) { | ||
| if c == nil { | ||
| return | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
Anthropic Claude API thinking type field specification documentation💡 Result:
thinkingfield (request) — Claude Messages APITo enable extended thinking, include a top-level
thinkingobject in your Messages API request with:type:"enabled"(to turn on extended thinking)budget_tokens: maximum token budget for thinking; must be at least 1024 and (in the normal/non-interleaved case) less thanmax_tokens; the thinking budget counts toward yourmax_tokenslimit. [1][2]To disable:
Verify each finding against the current code and only fix it if needed.
In
@dto/claude.goaround lines 429 - 432, The Thinking struct currently marksthe Type field with
omitempty, which allows omission but the Anthropic ClaudeAPI requires the
typefield; remove theomitemptytag from Thinking.Type inthe Thinking struct definition (or ensure callers always set a valid
"enabled"/"disabled" value before JSON serialization) so the serialized payload
always includes the required
typefield; update any constructors or code pathsthat build Thinking to set a default if necessary.