-
Notifications
You must be signed in to change notification settings - Fork 20
Use the GitHub models catalog endpoint for listing models #72
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
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 |
|---|---|---|
| @@ -1,16 +1,25 @@ | ||
| { | ||
| // Use IntelliSense to learn about possible attributes. | ||
| // Hover to view descriptions of existing attributes. | ||
| // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
| "name": "Run models list", | ||
| "type": "go", | ||
| "request": "launch", | ||
| "mode": "auto", | ||
| "program": "${workspaceFolder}/main.go", | ||
| "args": ["list"] | ||
| } | ||
| ] | ||
| } | ||
| // Use IntelliSense to learn about possible attributes. | ||
| // Hover to view descriptions of existing attributes. | ||
| // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
| "name": "Run models list", | ||
| "type": "go", | ||
| "request": "launch", | ||
| "mode": "auto", | ||
| "program": "${workspaceFolder}/main.go", | ||
| "args": ["list"] | ||
| }, | ||
| { | ||
| "name": "Run models view", | ||
| "type": "go", | ||
| "request": "launch", | ||
| "mode": "auto", | ||
| "program": "${workspaceFolder}/main.go", | ||
| "args": ["view"], | ||
| "console": "integratedTerminal" | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,14 +14,13 @@ func TestView(t *testing.T) { | |
| t.Run("NewViewCommand happy path", func(t *testing.T) { | ||
| client := azuremodels.NewMockClient() | ||
| modelSummary := &azuremodels.ModelSummary{ | ||
| ID: "test-id-1", | ||
| ID: "openai/test-model-1", | ||
|
Member
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. I thought I remembered talk recently of moving away from requiring the publisher name in model identifiers, something from @sgoedecke. Did that happen? Should we also have a test that just has the model name for its |
||
| Name: "test-model-1", | ||
| FriendlyName: "Test Model 1", | ||
| Task: "chat-completion", | ||
| Publisher: "OpenAI", | ||
| Summary: "This is a test model", | ||
| Version: "1.0", | ||
| RegistryName: "azure-openai", | ||
| } | ||
| listModelsCallCount := 0 | ||
| client.MockListModels = func(ctx context.Context) ([]*azuremodels.ModelSummary, error) { | ||
|
|
@@ -49,7 +48,7 @@ func TestView(t *testing.T) { | |
| buf := new(bytes.Buffer) | ||
| cfg := command.NewConfig(buf, buf, client, true, 80) | ||
| viewCmd := NewViewCommand(cfg) | ||
| viewCmd.SetArgs([]string{azuremodels.FormatIdentifier(modelSummary.Publisher, modelSummary.Name)}) | ||
| viewCmd.SetArgs([]string{modelSummary.ID}) | ||
|
|
||
| _, err := viewCmd.ExecuteC() | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,9 +9,11 @@ import ( | |
| "fmt" | ||
| "io" | ||
| "net/http" | ||
| "slices" | ||
| "strings" | ||
|
|
||
| "github.com/cli/go-gh/v2/pkg/api" | ||
| "github.com/github/gh-models/internal/modelkey" | ||
| "github.com/github/gh-models/internal/sse" | ||
| "golang.org/x/text/language" | ||
| "golang.org/x/text/language/display" | ||
|
|
@@ -185,19 +187,7 @@ func lowercaseStrings(input []string) []string { | |
|
|
||
| // ListModels returns a list of available models. | ||
| func (c *AzureClient) ListModels(ctx context.Context) ([]*ModelSummary, error) { | ||
| body := bytes.NewReader([]byte(` | ||
| { | ||
| "filters": [ | ||
| { "field": "freePlayground", "values": ["true"], "operator": "eq"}, | ||
| { "field": "labels", "values": ["latest"], "operator": "eq"} | ||
| ], | ||
| "order": [ | ||
| { "field": "displayName", "direction": "asc" } | ||
| ] | ||
| } | ||
| `)) | ||
|
|
||
| httpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, c.cfg.ModelsURL, body) | ||
| httpReq, err := http.NewRequestWithContext(ctx, http.MethodGet, c.cfg.ModelsURL, nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
@@ -218,28 +208,34 @@ func (c *AzureClient) ListModels(ctx context.Context) ([]*ModelSummary, error) { | |
| decoder := json.NewDecoder(resp.Body) | ||
| decoder.UseNumber() | ||
|
|
||
| var searchResponse modelCatalogSearchResponse | ||
| err = decoder.Decode(&searchResponse) | ||
| var catalog githubModelCatalogResponse | ||
| err = decoder.Decode(&catalog) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| models := make([]*ModelSummary, 0, len(searchResponse.Summaries)) | ||
| for _, summary := range searchResponse.Summaries { | ||
| models := make([]*ModelSummary, 0, len(catalog)) | ||
| for _, catalogModel := range catalog { | ||
| // Determine task from supported modalities - if it supports text input/output, it's likely a chat model | ||
| inferenceTask := "" | ||
| if len(summary.InferenceTasks) > 0 { | ||
| inferenceTask = summary.InferenceTasks[0] | ||
| if slices.Contains(catalogModel.SupportedInputModalities, "text") && slices.Contains(catalogModel.SupportedOutputModalities, "text") { | ||
cschleiden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| inferenceTask = "chat-completion" | ||
| } | ||
|
|
||
| modelKey, err := modelkey.ParseModelKey(catalogModel.ID) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("parsing model key %q: %w", catalogModel.ID, err) | ||
|
Member
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. Ahh you calling it a "model key" here when printing out the |
||
| } | ||
|
|
||
| models = append(models, &ModelSummary{ | ||
| ID: summary.AssetID, | ||
| Name: summary.Name, | ||
| FriendlyName: summary.DisplayName, | ||
| ID: catalogModel.ID, | ||
| Name: modelKey.ModelName, | ||
| Registry: catalogModel.Registry, | ||
| FriendlyName: catalogModel.Name, | ||
| Task: inferenceTask, | ||
| Publisher: summary.Publisher, | ||
| Summary: summary.Summary, | ||
| Version: summary.Version, | ||
| RegistryName: summary.RegistryName, | ||
| Publisher: catalogModel.Publisher, | ||
| Summary: catalogModel.Summary, | ||
| Version: catalogModel.Version, | ||
| }) | ||
| } | ||
|
|
||
|
|
||
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.
It's nice being able to use a simple
IDproperty and not have to format an identifier from other bits.