-
-
Notifications
You must be signed in to change notification settings - Fork 59
feat(models): add configurable model ID format for GET /v1/models #333
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -344,7 +344,60 @@ func (r *ModelRegistry) ListPublicModels() []core.Model { | |||||||||||||||||||||
| return result | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // ModelCount returns the number of registered models | ||||||||||||||||||||||
| // ListModelsWithFormat returns models formatted according to the given ID format. | ||||||||||||||||||||||
| func (r *ModelRegistry) ListModelsWithFormat(format config.ModelsEndpointIDFormat) []core.Model { | ||||||||||||||||||||||
| format = config.ResolveModelsEndpointIDFormat(format) | ||||||||||||||||||||||
| switch format { | ||||||||||||||||||||||
| case config.ModelsEndpointIDFormatUnqualified: | ||||||||||||||||||||||
| return r.listModelsUnqualified() | ||||||||||||||||||||||
| case config.ModelsEndpointIDFormatBoth: | ||||||||||||||||||||||
| return r.listModelsBoth() | ||||||||||||||||||||||
| default: | ||||||||||||||||||||||
| return r.ListPublicModels() | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| func (r *ModelRegistry) listModelsUnqualified() []core.Model { | ||||||||||||||||||||||
| r.mu.RLock() | ||||||||||||||||||||||
| defer r.mu.RUnlock() | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| seen := make(map[string]struct{}) | ||||||||||||||||||||||
| result := make([]core.Model, 0, len(r.models)) | ||||||||||||||||||||||
| for providerName, models := range r.modelsByProvider { | ||||||||||||||||||||||
| for modelID, info := range models { | ||||||||||||||||||||||
| if _, exists := seen[modelID]; exists { | ||||||||||||||||||||||
| continue | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| seen[modelID] = struct{}{} | ||||||||||||||||||||||
| model := info.Model | ||||||||||||||||||||||
| model.ID = modelID | ||||||||||||||||||||||
| model.OwnedBy = providerName | ||||||||||||||||||||||
| result = append(result, model) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| sort.Slice(result, func(i, j int) bool { return result[i].ID < result[j].ID }) | ||||||||||||||||||||||
| return result | ||||||||||||||||||||||
|
Comment on lines
+361
to
+379
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.
|
||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| func (r *ModelRegistry) listModelsBoth() []core.Model { | ||||||||||||||||||||||
| qualified := r.ListPublicModels() | ||||||||||||||||||||||
| unqualified := r.listModelsUnqualified() | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| seen := make(map[string]struct{}, len(qualified)+len(unqualified)) | ||||||||||||||||||||||
| result := make([]core.Model, 0, len(qualified)+len(unqualified)) | ||||||||||||||||||||||
| for _, m := range qualified { | ||||||||||||||||||||||
| seen[m.ID] = struct{}{} | ||||||||||||||||||||||
| result = append(result, m) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| for _, m := range unqualified { | ||||||||||||||||||||||
| if _, exists := seen[m.ID]; exists { | ||||||||||||||||||||||
| continue | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| result = append(result, m) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| sort.Slice(result, func(i, j int) bool { return result[i].ID < result[j].ID }) | ||||||||||||||||||||||
| return result | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| func (r *ModelRegistry) ModelCount() int { | ||||||||||||||||||||||
|
Comment on lines
+398
to
401
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.
Suggested change
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||||||||||||||||||||||
| r.mu.RLock() | ||||||||||||||||||||||
| defer r.mu.RUnlock() | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
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.
Add validation for ModelsEndpointIDFormat in Load().
ConfiguredProviderModelsModeis both resolved and validated inLoad()(lines 169–172), butModelsEndpointIDFormatis only defaulted here with no corresponding normalization or validation inLoad(). This inconsistency means invalid user-supplied values will silently fall back to the default instead of producing a clear configuration error.Proposed fix to add validation after line 172
cfg.Models.ConfiguredProviderModelsMode = ResolveConfiguredProviderModelsMode(cfg.Models.ConfiguredProviderModelsMode) if !cfg.Models.ConfiguredProviderModelsMode.Valid() { return nil, fmt.Errorf("models.configured_provider_models_mode must be one of: fallback, allowlist") } +cfg.Models.ModelsEndpointIDFormat = ResolveModelsEndpointIDFormat(cfg.Models.ModelsEndpointIDFormat) +if !cfg.Models.ModelsEndpointIDFormat.Valid() { + return nil, fmt.Errorf("models.models_endpoint_id_format must be one of: qualified, unqualified, both") +}🤖 Prompt for AI Agents