Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions sdk/cliproxy/openai_compat_config_models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,27 @@ func TestBuildOpenAICompatibilityConfigModels_InputModalities(t *testing.T) {
}

models := buildOpenAICompatibilityConfigModels(compat)
if len(models) != 2 {
t.Fatalf("model count = %d, want 2", len(models))
if len(models) != 4 {
t.Fatalf("model count = %d, want 4", len(models))
}

var vision *ModelInfo
var originalVision *ModelInfo
var imageModel *ModelInfo
var originalImageModel *ModelInfo
for _, model := range models {
if model == nil {
continue
}
switch model.ID {
case "mimo-v2.5-pro":
vision = model
case "upstream-vision":
originalVision = model
case "compat-image":
imageModel = model
case "upstream-image":
originalImageModel = model
}
}
if vision == nil {
Expand All @@ -48,6 +54,12 @@ func TestBuildOpenAICompatibilityConfigModels_InputModalities(t *testing.T) {
if got := joinModalities(vision.SupportedInputModalities); got != "text,image" {
t.Fatalf("SupportedInputModalities = %q, want text,image", got)
}
if originalVision == nil {
t.Fatal("expected original vision model")
}
if got := joinModalities(originalVision.SupportedInputModalities); got != "text,image" {
t.Fatalf("original SupportedInputModalities = %q, want text,image", got)
}
if imageModel == nil {
t.Fatal("expected image model")
}
Expand All @@ -57,6 +69,15 @@ func TestBuildOpenAICompatibilityConfigModels_InputModalities(t *testing.T) {
if len(imageModel.SupportedInputModalities) != 0 {
t.Fatalf("image model input modalities = %+v, want none", imageModel.SupportedInputModalities)
}
if originalImageModel == nil {
t.Fatal("expected original image model")
}
if originalImageModel.Type != registry.OpenAIImageModelType {
t.Fatalf("original image model type = %q, want %q", originalImageModel.Type, registry.OpenAIImageModelType)
}
if len(originalImageModel.SupportedInputModalities) != 0 {
t.Fatalf("original image model input modalities = %+v, want none", originalImageModel.SupportedInputModalities)
}
}

func joinModalities(modalities []string) string {
Expand Down
151 changes: 133 additions & 18 deletions sdk/cliproxy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1951,7 +1951,7 @@ func (s *Service) registerModelsForAuthWithCache(ctx context.Context, a *coreaut
models = buildGeminiConfigModels(entry)
}
if authKind == "apikey" {
excluded = entry.ExcludedModels
excluded = expandExcludedModelsForConfigAliases(entry.ExcludedModels, entry.Models)
}
}
models = applyExcludedModels(models, excluded)
Expand All @@ -1962,7 +1962,7 @@ func (s *Service) registerModelsForAuthWithCache(ctx context.Context, a *coreaut
models = buildGeminiConfigModels(entry)
}
if authKind == "apikey" {
excluded = entry.ExcludedModels
excluded = expandExcludedModelsForConfigAliases(entry.ExcludedModels, entry.Models)
}
}
models = applyExcludedModels(models, excluded)
Expand All @@ -1974,7 +1974,7 @@ func (s *Service) registerModelsForAuthWithCache(ctx context.Context, a *coreaut
models = buildVertexCompatConfigModels(entry)
}
if authKind == "apikey" {
excluded = entry.ExcludedModels
excluded = expandExcludedModelsForConfigAliases(entry.ExcludedModels, entry.Models)
}
}
models = applyExcludedModels(models, excluded)
Expand All @@ -1992,7 +1992,7 @@ func (s *Service) registerModelsForAuthWithCache(ctx context.Context, a *coreaut
models = buildClaudeConfigModels(entry)
}
if authKind == "apikey" {
excluded = entry.ExcludedModels
excluded = expandExcludedModelsForConfigAliases(entry.ExcludedModels, entry.Models)
}
}
models = applyExcludedModels(models, excluded)
Expand All @@ -2018,7 +2018,7 @@ func (s *Service) registerModelsForAuthWithCache(ctx context.Context, a *coreaut
models = buildCodexConfigModels(entry)
}
if authKind == "apikey" {
excluded = entry.ExcludedModels
excluded = expandExcludedModelsForConfigAliases(entry.ExcludedModels, entry.Models)
}
}
models = applyExcludedModels(models, excluded)
Expand Down Expand Up @@ -2383,6 +2383,58 @@ func applyExcludedModels(models []*ModelInfo, excluded []string) []*ModelInfo {
return filtered
}

func expandExcludedModelsForConfigAliases[T modelEntry](excluded []string, models []T) []string {
if len(excluded) == 0 || len(models) == 0 {
return excluded
}
patterns := make([]string, 0, len(excluded))
seen := make(map[string]struct{}, len(excluded)+len(models)*2)
out := make([]string, 0, len(excluded)+len(models)*2)
add := func(model string) {
model = strings.ToLower(strings.TrimSpace(model))
if model == "" {
return
}
if _, exists := seen[model]; exists {
return
}
seen[model] = struct{}{}
out = append(out, model)
}
for _, item := range excluded {
trimmed := strings.ToLower(strings.TrimSpace(item))
if trimmed == "" {
continue
}
patterns = append(patterns, trimmed)
add(trimmed)
}
if len(patterns) == 0 {
return excluded
}
for i := range models {
name := strings.TrimSpace(models[i].GetName())
alias := strings.TrimSpace(models[i].GetAlias())
if name == "" || alias == "" || name == alias {
continue
}
nameKey := strings.ToLower(name)
aliasKey := strings.ToLower(alias)
matched := false
for _, pattern := range patterns {
if matchWildcard(pattern, nameKey) || matchWildcard(pattern, aliasKey) {
matched = true
break
}
}
if matched {
add(name)
add(alias)
}
}
return out
}

func applyModelPrefixes(models []*ModelInfo, prefix string, forceModelPrefix bool) []*ModelInfo {
trimmedPrefix := strings.TrimSpace(prefix)
if trimmedPrefix == "" || len(models) == 0 {
Expand Down Expand Up @@ -2479,12 +2531,15 @@ func buildOpenAICompatibilityConfigModels(compat *config.OpenAICompatibility) []
return nil
}
now := time.Now().Unix()
models := make([]*ModelInfo, 0, len(compat.Models))
models := make([]*ModelInfo, 0, len(compat.Models)*2)
seen := make(map[string]struct{}, len(compat.Models)*2)
for i := range compat.Models {
model := compat.Models[i]
modelID := strings.TrimSpace(model.Alias)
alias := strings.TrimSpace(model.Alias)
name := strings.TrimSpace(model.Name)
modelID := alias
if modelID == "" {
modelID = strings.TrimSpace(model.Name)
modelID = name
}
if modelID == "" {
continue
Expand All @@ -2499,7 +2554,7 @@ func buildOpenAICompatibilityConfigModels(compat *config.OpenAICompatibility) []
}
inputModalities := normalizeCompatConfigModalities(model.InputModalities)
outputModalities := normalizeCompatConfigModalities(model.OutputModalities)
models = append(models, &ModelInfo{
info := &ModelInfo{
ID: modelID,
Object: "model",
Created: now,
Expand All @@ -2510,11 +2565,73 @@ func buildOpenAICompatibilityConfigModels(compat *config.OpenAICompatibility) []
Thinking: thinking,
SupportedInputModalities: inputModalities,
SupportedOutputModalities: outputModalities,
})
}
models = appendModelInfoIfUnique(models, info, seen)
if alias != "" && name != "" && alias != name {
original := configOriginalModelInfo(name, compat.Name, modelType, now, false, thinking)
if original != nil {
original.SupportedInputModalities = inputModalities
original.SupportedOutputModalities = outputModalities
}
models = appendModelInfoIfUnique(models, original, seen)
}
}
return models
}

func appendModelInfoIfUnique(models []*ModelInfo, info *ModelInfo, seen map[string]struct{}) []*ModelInfo {
if info == nil {
return models
}
modelID := strings.TrimSpace(info.ID)
if modelID == "" {
return models
}
key := modelID

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve folded de-dupe for configured aliases

When a config contains two aliases that differ only by case, this helper now registers both spellings as separate model IDs because the de-dupe key is the exact ID. The execution path still resolves API-key aliases case-insensitively and keeps the first mapping in compileAPIKeyModelAliasForModels (OpenAI-compatible pooling also matches aliases with EqualFold), so a request for the second advertised alias selects this credential but is sent to the first alias's upstream model. Please keep folded de-dupe for configured aliases and apply case-sensitive uniqueness only when adding the extra original upstream ID.

Useful? React with 👍 / 👎.

if _, exists := seen[key]; exists {
return models
}
seen[key] = struct{}{}
info.ID = modelID
return append(models, info)
}

func configOriginalModelInfo(name, ownedBy, modelType string, created int64, userDefined bool, thinking *registry.ThinkingSupport) *ModelInfo {
name = strings.TrimSpace(name)
if name == "" {
return nil
}
if info := registry.LookupStaticModelInfo(name); info != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve compat thinking on original IDs

Fresh issue in the static-metadata fix: when an OpenAI-compatible entry aliases a static native model (for example name: "gemini-2.5-pro", alias: "gemini-pro"), this branch copies the native static Thinking field and ignores the OpenAI-compatible thinking value passed in from buildOpenAICompatibilityConfigModels. The alias keeps level-based OpenAI-compatible reasoning, but the newly registered original ID is looked up with Gemini/Claude budget metadata, so direct requests such as gemini-2.5-pro(high) do not have the suffix applied through the OpenAI-compatible executor. Please overlay the provider/config Thinking on top of the static metadata for these original-ID entries.

Useful? React with 👍 / 👎.

info.ID = name
if info.Object == "" {
info.Object = "model"
}
if info.Created == 0 {
info.Created = created
}
info.OwnedBy = ownedBy
info.Type = modelType
if info.DisplayName == "" {
info.DisplayName = name
}
if thinking != nil {
info.Thinking = thinking
}
info.UserDefined = false
return info
}
return &ModelInfo{
ID: name,
Object: "model",
Created: created,
OwnedBy: ownedBy,
Type: modelType,
DisplayName: name,
UserDefined: userDefined,
Thinking: thinking,
}
}

func normalizeCompatConfigModalities(raw []string) []string {
if len(raw) == 0 {
return nil
Expand Down Expand Up @@ -2543,8 +2660,8 @@ func buildConfigModels[T modelEntry](models []T, ownedBy, modelType string) []*M
return nil
}
now := time.Now().Unix()
out := make([]*ModelInfo, 0, len(models))
seen := make(map[string]struct{}, len(models))
out := make([]*ModelInfo, 0, len(models)*2)
seen := make(map[string]struct{}, len(models)*2)
for i := range models {
model := models[i]
name := strings.TrimSpace(model.GetName())
Expand All @@ -2555,11 +2672,6 @@ func buildConfigModels[T modelEntry](models []T, ownedBy, modelType string) []*M
if alias == "" {
continue
}
key := strings.ToLower(alias)
if _, exists := seen[key]; exists {
continue
}
seen[key] = struct{}{}
display := name
if display == "" {
display = alias
Expand All @@ -2578,7 +2690,10 @@ func buildConfigModels[T modelEntry](models []T, ownedBy, modelType string) []*M
info.Thinking = upstream.Thinking
}
}
out = append(out, info)
out = appendModelInfoIfUnique(out, info, seen)
if name != "" && alias != name {
out = appendModelInfoIfUnique(out, configOriginalModelInfo(name, ownedBy, modelType, now, true, info.Thinking), seen)
}
}
return out
}
Expand Down
Loading
Loading