Merge pull request #9094 from pood1e/feat/declare-image-input-models

feat(codex): let accounts declare image-input models
This commit is contained in:
Wesley Liddick authored and GitHub committed 2026-11-26 12:06:32 +08:00
commit 81ce8356d9
2 files changed
+103

No files matched your search

@@ -1323,12 +1323,38 @@ func codexExplicitModelMappingClaims(account Account, modelID string) bool {
return mapped != ""
}
// ImageInputModelsExtraKey is an optional account extra key, set through the
// admin account API, that lists upstream model IDs accepting image input.
// It covers models that neither the upstream model list nor models.dev
// describes, such as multimodal models served by vLLM or SGLang. Declared
// models advertise image input ahead of synced metadata and name fallbacks.
const ImageInputModelsExtraKey = "image_input_models"
// accountDeclaresImageInputModel reports whether the account lists
// upstreamModel under ImageInputModelsExtraKey, ignoring case.
func accountDeclaresImageInputModel(account *Account, upstreamModel string) bool {
model := strings.TrimSpace(upstreamModel)
if account == nil || account.Extra == nil || model == "" {
return false
}
declared, _ := account.Extra[ImageInputModelsExtraKey].([]any)
for _, value := range declared {
if name, ok := value.(string); ok && strings.EqualFold(strings.TrimSpace(name), model) {
return true
}
}
return false
}
func accountCodexModelSupportsImageInput(account *Account, upstreamModel string) bool {
if account == nil {
return false
}
switch account.Platform {
case PlatformOpenAI, PlatformDeepseek, PlatformOpenCodeGo, PlatformCommandCode:
if accountDeclaresImageInputModel(account, upstreamModel) {
return true
}
if metadata, ok := account.GetUpstreamModelMetadata(upstreamModel); ok {
if modalities := normalizeCodexInputModalities(metadata.InputModalities); len(modalities) > 0 {
// Official GPT-6 Astra metadata briefly shipped with a stale
@@ -907,6 +907,83 @@ func TestBuildCodexModelsManifestForGroupUsesDeepSeekVisionCapabilities(t *testi
}
}
func TestBuildCodexModelsManifestForGroupUsesDeclaredImageInputModels(t *testing.T) {
t.Parallel()
const model = "deepseek-v4.1-flash"
newAccount := func(id int64, declared []any, syncedModalities []string) Account {
account := Account{
ID: id, Platform: PlatformOpenAI, Type: AccountTypeAPIKey,
Credentials: map[string]any{
"base_url": "http://vllm.internal:8000",
"model_mapping": map[string]any{model: model},
},
}
if declared != nil {
account.Extra = map[string]any{ImageInputModelsExtraKey: declared}
}
if syncedModalities != nil {
account.SetUpstreamModelMetadataSnapshot(UpstreamModelMetadataSnapshot{Models: map[string]UpstreamModelMetadata{
model: {ID: model, InputModalities: syncedModalities},
}})
}
return account
}
tests := []struct {
name string
accounts []Account
modalities []any
}{
{
name: "undeclared self-hosted model",
accounts: []Account{newAccount(1, nil, nil)},
modalities: []any{"text"},
},
{
name: "declared self-hosted model",
accounts: []Account{newAccount(1, []any{model}, nil)},
modalities: []any{"text", "image"},
},
{
name: "declaration ignores case",
accounts: []Account{newAccount(1, []any{"DeepSeek-V4.1-Flash"}, nil)},
modalities: []any{"text", "image"},
},
{
name: "declaration overrides synced text-only metadata",
accounts: []Account{newAccount(1, []any{model}, []string{"text"})},
modalities: []any{"text", "image"},
},
{
name: "another model declared",
accounts: []Account{newAccount(1, []any{"qwen3-vl"}, nil)},
modalities: []any{"text"},
},
{
name: "an undeclared account in the pool keeps text only",
accounts: []Account{newAccount(1, []any{model}, nil), newAccount(2, nil, nil)},
modalities: []any{"text"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
const groupID int64 = 791
svc := &GatewayService{accountRepo: codexModelsVisibilityAccountRepo{byGroup: map[int64][]Account{
groupID: tt.accounts,
}}}
body, err := svc.BuildCodexModelsManifestForGroup(context.Background(),
&Group{ID: groupID, Platform: PlatformOpenAI}, "", []string{model})
require.NoError(t, err)
models := decodeCodexManifestModels(t, body)
require.Len(t, models, 1)
require.Equal(t, tt.modalities, models[0]["input_modalities"])
})
}
}
func TestBuildCodexModelsManifestForGroupPrefersSyncedOpenAIImageCapabilities(t *testing.T) {
t.Parallel()