mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-14 12:02:27 +08:00
Merge pull request #7811 from kingsleydon/fix/codex-service-tiers-null-fallback
fix(codex): never advertise null service_tiers in models manifest
This commit is contained in:
@@ -21,6 +21,9 @@ func applyCodexToolCapabilities(dst, src map[string]json.RawMessage, overwrite b
|
||||
if len(value) == 0 {
|
||||
continue
|
||||
}
|
||||
if field == "service_tiers" && bytes.Equal(value, []byte("null")) {
|
||||
value = []byte("[]")
|
||||
}
|
||||
// These Codex fields are nullable booleans or strings, never arbitrary objects.
|
||||
if !bytes.Equal(value, []byte("null")) {
|
||||
if field == "service_tiers" {
|
||||
@@ -278,8 +281,11 @@ func intersectUpstreamModelMetadata(modelID string, candidates []UpstreamModelMe
|
||||
result.CodexToolCapabilities[field] = value
|
||||
} else if declared {
|
||||
fallback := json.RawMessage("null")
|
||||
if field == "supports_search_tool" || field == "use_responses_lite" {
|
||||
switch field {
|
||||
case "supports_search_tool", "use_responses_lite":
|
||||
fallback = json.RawMessage("false")
|
||||
case "service_tiers":
|
||||
fallback = json.RawMessage("[]")
|
||||
}
|
||||
result.CodexToolCapabilities[field] = fallback
|
||||
}
|
||||
|
||||
@@ -108,6 +108,41 @@ func TestAstraCodexToolCapabilitiesUseAccountScopeAndSharedDeclarations(t *testi
|
||||
require.Equal(t, "3000", model["comp_hash"])
|
||||
}
|
||||
|
||||
func TestCodexToolCapabilitiesNeverAdvertiseNullServiceTiers(t *testing.T) {
|
||||
newAccount := func(id int64, tiers string) Account {
|
||||
account := Account{ID: id, Platform: PlatformOpenAI, Type: AccountTypeAPIKey, Credentials: map[string]any{
|
||||
"base_url": "https://relay.example/v1", "model_mapping": map[string]any{"gpt-6-sol": "gpt-6-sol"},
|
||||
}}
|
||||
if tiers != "" {
|
||||
account.SetUpstreamModelMetadataSnapshot(UpstreamModelMetadataSnapshot{Models: map[string]UpstreamModelMetadata{
|
||||
"gpt-6-sol": {CodexToolCapabilities: map[string]json.RawMessage{"service_tiers": json.RawMessage(tiers)}},
|
||||
}})
|
||||
}
|
||||
return account
|
||||
}
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
accounts []Account
|
||||
}{
|
||||
{"conflicting peer tiers", []Account{newAccount(1, `[{"id":"priority"}]`), newAccount(2, `[]`)}},
|
||||
{"undeclared peer tiers", []Account{newAccount(1, `[{"id":"priority"}]`), newAccount(2, "")}},
|
||||
{"explicit null tiers", []Account{newAccount(1, "null")}},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
body, err := buildCodexModelsManifestForAccounts(PlatformOpenAI, []string{"gpt-6-sol"}, tt.accounts, nil, nil, true)
|
||||
require.NoError(t, err)
|
||||
model := decodeCodexManifestModels(t, body)[0]
|
||||
require.Equal(t, []any{}, model["service_tiers"])
|
||||
})
|
||||
}
|
||||
|
||||
merged := intersectUpstreamModelMetadata("gpt-6-sol", []UpstreamModelMetadata{
|
||||
{CodexToolCapabilities: map[string]json.RawMessage{"service_tiers": json.RawMessage(`[{"id":"priority"}]`)}},
|
||||
{CodexToolCapabilities: map[string]json.RawMessage{"service_tiers": json.RawMessage(`[]`)}},
|
||||
})
|
||||
require.JSONEq(t, `[]`, string(merged.CodexToolCapabilities["service_tiers"]))
|
||||
}
|
||||
|
||||
func TestAstraCodexToolCapabilitiesPreserveLiveNullAndFalse(t *testing.T) {
|
||||
account := &Account{Platform: PlatformOpenAI, Type: AccountTypeAPIKey,
|
||||
Credentials: map[string]any{"base_url": "https://api.openai.com/v1"}}
|
||||
|
||||
Reference in New Issue
Block a user