-
-
Notifications
You must be signed in to change notification settings - Fork 68
v6.6.1 #19
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
v6.6.1 #19
Changes from all commits
a895149
76c563d
1da03bf
a03d514
3ffd120
d06d0ea
169f429
519da2e
3a81ab2
007572b
f6300c7
21bbcec
6285459
facfe7c
2760989
e79f65f
88bdd25
564bcba
a74ee3f
4ce7c61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -254,7 +254,7 @@ func (e *ClaudeExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.A | |||||
| // If from == to (Claude → Claude), directly forward the SSE stream without translation | ||||||
| if from == to { | ||||||
| scanner := bufio.NewScanner(decodedBody) | ||||||
| scanner.Buffer(nil, 20_971_520) | ||||||
| scanner.Buffer(nil, 52_428_800) // 50MB | ||||||
|
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. The buffer size This comment also applies to
Suggested change
|
||||||
| for scanner.Scan() { | ||||||
| line := scanner.Bytes() | ||||||
| appendAPIResponseChunk(ctx, e.cfg, line) | ||||||
|
|
@@ -277,7 +277,7 @@ func (e *ClaudeExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.A | |||||
|
|
||||||
| // For other formats, use translation | ||||||
| scanner := bufio.NewScanner(decodedBody) | ||||||
| scanner.Buffer(nil, 20_971_520) | ||||||
| scanner.Buffer(nil, 52_428_800) // 50MB | ||||||
| var param any | ||||||
| for scanner.Scan() { | ||||||
| line := scanner.Bytes() | ||||||
|
|
@@ -450,59 +450,15 @@ func extractAndRemoveBetas(body []byte) ([]string, []byte) { | |||||
| return betas, body | ||||||
| } | ||||||
|
|
||||||
| // injectThinkingConfig adds thinking configuration based on metadata or legacy suffixes. | ||||||
| // injectThinkingConfig adds thinking configuration based on metadata using the unified flow. | ||||||
| // It uses util.ResolveClaudeThinkingConfig which internally calls ResolveThinkingConfigFromMetadata | ||||||
| // and NormalizeThinkingBudget, ensuring consistency with other executors like Gemini. | ||||||
| func (e *ClaudeExecutor) injectThinkingConfig(modelName string, metadata map[string]any, body []byte) []byte { | ||||||
| // Only inject if thinking config is not already present | ||||||
| if gjson.GetBytes(body, "thinking").Exists() { | ||||||
| budget, ok := util.ResolveClaudeThinkingConfig(modelName, metadata) | ||||||
| if !ok { | ||||||
| return body | ||||||
| } | ||||||
|
|
||||||
| budgetTokens, ok := resolveClaudeThinkingBudget(modelName, metadata) | ||||||
| if !ok || budgetTokens <= 0 { | ||||||
| return body | ||||||
| } | ||||||
|
|
||||||
| body, _ = sjson.SetBytes(body, "thinking.type", "enabled") | ||||||
| body, _ = sjson.SetBytes(body, "thinking.budget_tokens", budgetTokens) | ||||||
| return body | ||||||
| } | ||||||
|
|
||||||
| func resolveClaudeThinkingBudget(modelName string, metadata map[string]any) (int, bool) { | ||||||
| budget, include, effort, matched := util.ThinkingFromMetadata(metadata) | ||||||
| if matched { | ||||||
| if include != nil && !*include { | ||||||
| return 0, false | ||||||
| } | ||||||
| if budget != nil { | ||||||
| normalized := util.NormalizeThinkingBudget(modelName, *budget) | ||||||
| if normalized > 0 { | ||||||
| return normalized, true | ||||||
| } | ||||||
| return 0, false | ||||||
| } | ||||||
| if effort != nil { | ||||||
| if derived, ok := util.ThinkingEffortToBudget(modelName, *effort); ok && derived > 0 { | ||||||
| return derived, true | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| return claudeBudgetFromSuffix(modelName) | ||||||
| } | ||||||
|
|
||||||
| func claudeBudgetFromSuffix(modelName string) (int, bool) { | ||||||
| lower := strings.ToLower(strings.TrimSpace(modelName)) | ||||||
| switch { | ||||||
| case strings.HasSuffix(lower, "-thinking-low"): | ||||||
| return 1024, true | ||||||
| case strings.HasSuffix(lower, "-thinking-medium"): | ||||||
| return 8192, true | ||||||
| case strings.HasSuffix(lower, "-thinking-high"): | ||||||
| return 24576, true | ||||||
| case strings.HasSuffix(lower, "-thinking"): | ||||||
| return 8192, true | ||||||
| default: | ||||||
| return 0, false | ||||||
| } | ||||||
| return util.ApplyClaudeThinkingConfig(body, budget) | ||||||
| } | ||||||
|
|
||||||
| // ensureMaxTokensForThinking ensures max_tokens > thinking.budget_tokens when thinking is enabled. | ||||||
|
|
||||||
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.
There are multiple instances of
&ThinkingSupport{Levels: []string{"low", "medium", "high"}}and other similarThinkingSupportstructs being created. To improve maintainability and reduce duplication, consider defining these common configurations as package-level constants or variables.For example:
This would apply to several other model definitions in this file as well.