mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-09-08 17:11:19 +08:00
feat(translator): prioritize service tier for fast responses in Claude requests
- Updated `codex_claude_request` to set the service tier as "priority" when `speed` is "fast". - Enhanced request template generation logic to reflect dynamic service tier evaluation. Closes: #4349
This commit is contained in:
@@ -340,7 +340,11 @@ func ConvertClaudeRequestToCodex(modelName string, inputRawJSON []byte, _ bool)
|
||||
}
|
||||
template, _ = sjson.SetBytes(template, "reasoning.effort", reasoningEffort)
|
||||
template, _ = sjson.SetBytes(template, "reasoning.summary", "auto")
|
||||
if serviceTier := normalizeCodexServiceTier(rootResult.Get("service_tier")); serviceTier != "" {
|
||||
serviceTier := normalizeCodexServiceTier(rootResult.Get("service_tier"))
|
||||
if speed := rootResult.Get("speed"); speed.Type == gjson.String && speed.String() == "fast" {
|
||||
serviceTier = "priority"
|
||||
}
|
||||
if serviceTier != "" {
|
||||
template, _ = sjson.SetBytes(template, "service_tier", serviceTier)
|
||||
}
|
||||
template, _ = sjson.SetBytes(template, "stream", true)
|
||||
|
||||
@@ -187,6 +187,7 @@ func TestConvertClaudeRequestToCodex_ServiceTier(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
serviceTierJSON string
|
||||
speedJSON string
|
||||
want string
|
||||
wantExists bool
|
||||
}{
|
||||
@@ -197,7 +198,7 @@ func TestConvertClaudeRequestToCodex_ServiceTier(t *testing.T) {
|
||||
wantExists: true,
|
||||
},
|
||||
{
|
||||
name: "Fast normalizes to priority",
|
||||
name: "Fast tier normalizes to priority",
|
||||
serviceTierJSON: `"fast"`,
|
||||
want: "priority",
|
||||
wantExists: true,
|
||||
@@ -210,17 +211,43 @@ func TestConvertClaudeRequestToCodex_ServiceTier(t *testing.T) {
|
||||
name: "Non-string tier is omitted",
|
||||
serviceTierJSON: `true`,
|
||||
},
|
||||
{
|
||||
name: "Fast speed maps to priority",
|
||||
speedJSON: `"fast"`,
|
||||
want: "priority",
|
||||
wantExists: true,
|
||||
},
|
||||
{
|
||||
name: "Standard speed is omitted",
|
||||
speedJSON: `"standard"`,
|
||||
},
|
||||
{
|
||||
name: "Non-string speed is omitted",
|
||||
speedJSON: `true`,
|
||||
},
|
||||
{
|
||||
name: "Fast speed overrides unsupported Anthropic tier",
|
||||
serviceTierJSON: `"auto"`,
|
||||
speedJSON: `"fast"`,
|
||||
want: "priority",
|
||||
wantExists: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
inputJSON := `{
|
||||
inputJSON := []byte(`{
|
||||
"model": "gpt-5.4",
|
||||
"service_tier": ` + tt.serviceTierJSON + `,
|
||||
"messages": [{"role": "user", "content": "Reply with OK"}]
|
||||
}`
|
||||
}`)
|
||||
if tt.serviceTierJSON != "" {
|
||||
inputJSON, _ = sjson.SetRawBytes(inputJSON, "service_tier", []byte(tt.serviceTierJSON))
|
||||
}
|
||||
if tt.speedJSON != "" {
|
||||
inputJSON, _ = sjson.SetRawBytes(inputJSON, "speed", []byte(tt.speedJSON))
|
||||
}
|
||||
|
||||
result := ConvertClaudeRequestToCodex("gpt-5.4", []byte(inputJSON), false)
|
||||
result := ConvertClaudeRequestToCodex("gpt-5.4", inputJSON, false)
|
||||
serviceTierResult := gjson.GetBytes(result, "service_tier")
|
||||
if serviceTierResult.Exists() != tt.wantExists {
|
||||
t.Fatalf("service_tier exists = %v, want %v. Output: %s", serviceTierResult.Exists(), tt.wantExists, string(result))
|
||||
|
||||
Reference in New Issue
Block a user