-
-
Notifications
You must be signed in to change notification settings - Fork 50
server: support provider/model selectors and optional provider field #114
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c15d59f
providers: preserve provider instance identity in registry cache
SantiagoDePolonia da62fe4
server: support provider/model selectors and optional provider field
SantiagoDePolonia edf2753
providers: remove cache versioning
SantiagoDePolonia b29c82c
cache: group models by provider and fix slash-in-model-ID lookups
SantiagoDePolonia 280b696
Merge branch 'feature/provider-instance-cache' into feature/provider-…
SantiagoDePolonia 2a32789
Merge remote-tracking branch 'origin/main' into feature/provider-sele…
SantiagoDePolonia d6bec63
refactor: refactored the code to remove repetitions
SantiagoDePolonia 2a7edfc
fix: resolve pre-existing lint issues in contract test suite
SantiagoDePolonia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package core | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
| ) | ||
|
|
||
| // ModelSelector is a normalized model routing selector. | ||
| // Model is always the raw upstream model ID (without provider prefix). | ||
| type ModelSelector struct { | ||
| Model string | ||
| Provider string | ||
| } | ||
|
|
||
| // QualifiedModel returns "provider/model" when Provider is set, or only model otherwise. | ||
| func (s ModelSelector) QualifiedModel() string { | ||
| if s.Provider == "" { | ||
| return s.Model | ||
| } | ||
| return s.Provider + "/" + s.Model | ||
| } | ||
|
|
||
| // ParseModelSelector normalizes model/provider routing input. | ||
| // | ||
| // Accepted forms: | ||
| // - model only: "gpt-4o" | ||
| // - model with prefix: "openai/gpt-4o" | ||
| // - explicit provider field: provider="openai", model="gpt-4o" | ||
| // | ||
| // If provider is present in both places, values must match. | ||
| func ParseModelSelector(model, provider string) (ModelSelector, error) { | ||
| model = strings.TrimSpace(model) | ||
| provider = strings.TrimSpace(provider) | ||
|
|
||
| if model == "" { | ||
| return ModelSelector{}, fmt.Errorf("model is required") | ||
| } | ||
|
|
||
| parts := strings.SplitN(model, "/", 2) | ||
| if len(parts) == 2 { | ||
| prefix := strings.TrimSpace(parts[0]) | ||
| rest := strings.TrimSpace(parts[1]) | ||
| if prefix != "" && rest != "" { | ||
| if provider != "" && provider != prefix { | ||
| return ModelSelector{}, fmt.Errorf("provider field %q conflicts with model prefix %q", provider, prefix) | ||
| } | ||
| provider = prefix | ||
| model = rest | ||
| } | ||
| } | ||
|
|
||
| if model == "" { | ||
| return ModelSelector{}, fmt.Errorf("model is required") | ||
| } | ||
|
|
||
| return ModelSelector{ | ||
| Model: model, | ||
| Provider: provider, | ||
| }, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package core | ||
|
|
||
| import "testing" | ||
|
|
||
| func TestParseModelSelector(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| model string | ||
| provider string | ||
| wantModel string | ||
| wantProvider string | ||
| wantQualified string | ||
| wantErr bool | ||
| }{ | ||
| { | ||
| name: "plain model", | ||
| model: "gpt-4o", | ||
| wantModel: "gpt-4o", | ||
| wantProvider: "", | ||
| wantQualified: "gpt-4o", | ||
| }, | ||
| { | ||
| name: "prefixed model", | ||
| model: "openai/gpt-4o", | ||
| wantModel: "gpt-4o", | ||
| wantProvider: "openai", | ||
| wantQualified: "openai/gpt-4o", | ||
| }, | ||
| { | ||
| name: "provider field", | ||
| model: "gpt-4o", | ||
| provider: "openai", | ||
| wantModel: "gpt-4o", | ||
| wantProvider: "openai", | ||
| wantQualified: "openai/gpt-4o", | ||
| }, | ||
| { | ||
| name: "provider conflict", | ||
| model: "openai/gpt-4o", | ||
| provider: "anthropic", | ||
| wantErr: true, | ||
| }, | ||
| { | ||
| name: "missing model", | ||
| model: "", | ||
| wantErr: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| selector, err := ParseModelSelector(tt.model, tt.provider) | ||
| if tt.wantErr { | ||
| if err == nil { | ||
| t.Fatal("expected error, got nil") | ||
| } | ||
| return | ||
| } | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| if selector.Model != tt.wantModel { | ||
| t.Fatalf("Model = %q, want %q", selector.Model, tt.wantModel) | ||
| } | ||
| if selector.Provider != tt.wantProvider { | ||
| t.Fatalf("Provider = %q, want %q", selector.Provider, tt.wantProvider) | ||
| } | ||
| if selector.QualifiedModel() != tt.wantQualified { | ||
| t.Fatalf("QualifiedModel = %q, want %q", selector.QualifiedModel(), tt.wantQualified) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: ENTERPILOT/GOModel
Length of output: 1420
Commit
cmd/gomodel/docs/docs.goalongsideswagger.jsonper coding guidelines.The coding guidelines explicitly require committing both
cmd/gomodel/docs/swagger.jsonandcmd/gomodel/docs/docs.gotogether when making API changes. Whileswagger.jsonis included in this PR with the provider field additions,docs.gois not in the changed files. Regenerate and commitdocs.gowith this PR to maintain consistency between the generated Swagger files.🤖 Prompt for AI Agents