Skip to content

Commit 290f4d6

Browse files
authored
Update inference endpoint in models client to use the now preferred models.github.ai (#42)
2 parents 6d4a5d0 + 91cae7f commit 290f4d6

File tree

13 files changed

+68
-46
lines changed

13 files changed

+68
-46
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ gh models list
3333

3434
Example output:
3535
```shell
36-
Name Friendly Name Publisher
37-
AI21-Jamba-Instruct AI21-Jamba-Instruct AI21 Labs
38-
gpt-4o OpenAI GPT-4o Azure OpenAI Service
39-
gpt-4o-mini OpenAI GPT-4o mini Azure OpenAI Service
40-
Cohere-command-r Cohere Command R cohere
41-
Cohere-command-r-plus Cohere Command R+ cohere
36+
ID DISPLAY NAME
37+
ai21-labs/ai21-jamba-1.5-large AI21 Jamba 1.5 Large
38+
openai/gpt-4.1 OpenAI GPT-4.1
39+
openai/gpt-4o-mini OpenAI GPT-4o mini
40+
cohere/cohere-command-r Cohere Command R
41+
deepseek/deepseek-v3-0324 Deepseek-V3-0324
4242
```
4343

44-
Use the value in the "Name" column when specifying the model on the command-line.
44+
Use the value in the "ID" column when specifying the model on the command-line.
4545

4646
#### Running inference
4747

@@ -58,12 +58,12 @@ In REPL mode, use `/help` to list available commands. Otherwise just type your p
5858

5959
Run the extension in single-shot mode. This will print the model output and exit.
6060
```shell
61-
gh models run gpt-4o-mini "why is the sky blue?"
61+
gh models run openai/gpt-4o-mini "why is the sky blue?"
6262
```
6363

6464
Run the extension with output from a command. This uses single-shot mode.
6565
```shell
66-
cat README.md | gh models run gpt-4o-mini "summarize this text"
66+
cat README.md | gh models run openai/gpt-4o-mini "summarize this text"
6767
```
6868

6969
## Notice

cmd/list/list.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ package list
44
import (
55
"fmt"
66

7+
"github.com/MakeNowJust/heredoc"
78
"github.com/cli/go-gh/v2/pkg/tableprinter"
89
"github.com/github/gh-models/internal/azuremodels"
910
"github.com/github/gh-models/pkg/command"
10-
"github.com/MakeNowJust/heredoc"
1111
"github.com/mgutz/ansi"
1212
"github.com/spf13/cobra"
1313
)
@@ -27,7 +27,7 @@ func NewListCommand(cfg *command.Config) *cobra.Command {
2727
Values from the "MODEL NAME" column can be used as the %[1]s[model]%[1]s
2828
argument in other commands.
2929
`, "`"),
30-
Args: cobra.NoArgs,
30+
Args: cobra.NoArgs,
3131
RunE: func(cmd *cobra.Command, args []string) error {
3232
ctx := cmd.Context()
3333
client := cfg.Client
@@ -49,12 +49,12 @@ func NewListCommand(cfg *command.Config) *cobra.Command {
4949

5050
printer := cfg.NewTablePrinter()
5151

52-
printer.AddHeader([]string{"DISPLAY NAME", "MODEL NAME"}, tableprinter.WithColor(lightGrayUnderline))
52+
printer.AddHeader([]string{"ID", "DISPLAY NAME"}, tableprinter.WithColor(lightGrayUnderline))
5353
printer.EndRow()
5454

5555
for _, model := range models {
56+
printer.AddField(azuremodels.FormatIdentifier(model.Publisher, model.Name))
5657
printer.AddField(model.FriendlyName)
57-
printer.AddField(model.Name)
5858
printer.EndRow()
5959
}
6060

cmd/list/list_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ func TestList(t *testing.T) {
3939
output := buf.String()
4040
require.Contains(t, output, "Showing 1 available chat models")
4141
require.Contains(t, output, "DISPLAY NAME")
42-
require.Contains(t, output, "MODEL NAME")
42+
require.Contains(t, output, "ID")
4343
require.Contains(t, output, modelSummary.FriendlyName)
44-
require.Contains(t, output, modelSummary.Name)
44+
require.Contains(t, output, azuremodels.FormatIdentifier(modelSummary.Publisher, modelSummary.Name))
4545
})
4646

4747
t.Run("--help prints usage info", func(t *testing.T) {

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"strings"
77

8+
"github.com/MakeNowJust/heredoc"
89
"github.com/cli/go-gh/v2/pkg/auth"
910
"github.com/cli/go-gh/v2/pkg/term"
1011
"github.com/github/gh-models/cmd/list"
@@ -13,7 +14,6 @@ import (
1314
"github.com/github/gh-models/internal/azuremodels"
1415
"github.com/github/gh-models/pkg/command"
1516
"github.com/github/gh-models/pkg/util"
16-
"github.com/MakeNowJust/heredoc"
1717
"github.com/spf13/cobra"
1818
)
1919

cmd/run/run.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import (
1313
"time"
1414

1515
"github.com/AlecAivazis/survey/v2"
16+
"github.com/MakeNowJust/heredoc"
1617
"github.com/briandowns/spinner"
1718
"github.com/github/gh-models/internal/azuremodels"
1819
"github.com/github/gh-models/internal/sse"
1920
"github.com/github/gh-models/pkg/command"
2021
"github.com/github/gh-models/pkg/util"
21-
"github.com/MakeNowJust/heredoc"
2222
"github.com/spf13/cobra"
2323
"github.com/spf13/pflag"
2424
)
@@ -205,8 +205,8 @@ func NewRunCommand(cfg *command.Config) *cobra.Command {
205205
206206
The return value will be the response to your prompt from the selected model.
207207
`, "`"),
208-
Example: "gh models run gpt-4o-mini \"how many types of hyena are there?\"",
209-
Args: cobra.ArbitraryArgs,
208+
Example: "gh models run openai/gpt-4o-mini \"how many types of hyena are there?\"",
209+
Args: cobra.ArbitraryArgs,
210210
RunE: func(cmd *cobra.Command, args []string) error {
211211
cmdHandler := newRunCommandHandler(cmd, cfg, args)
212212
if cmdHandler == nil {
@@ -413,7 +413,7 @@ func (h *runCommandHandler) getModelNameFromArgs(models []*azuremodels.ModelSumm
413413
if !model.IsChatModel() {
414414
continue
415415
}
416-
prompt.Options = append(prompt.Options, model.FriendlyName)
416+
prompt.Options = append(prompt.Options, azuremodels.FormatIdentifier(model.Publisher, model.Name))
417417
}
418418

419419
err := survey.AskOne(prompt, &modelName, survey.WithPageSize(10))
@@ -438,7 +438,6 @@ func validateModelName(modelName string, models []*azuremodels.ModelSummary) (st
438438
foundMatch := false
439439
for _, model := range models {
440440
if model.HasName(modelName) {
441-
modelName = model.Name
442441
foundMatch = true
443442
break
444443
}

cmd/run/run_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestRun(t *testing.T) {
5050
buf := new(bytes.Buffer)
5151
cfg := command.NewConfig(buf, buf, client, true, 80)
5252
runCmd := NewRunCommand(cfg)
53-
runCmd.SetArgs([]string{modelSummary.Name, "this is my prompt"})
53+
runCmd.SetArgs([]string{azuremodels.FormatIdentifier(modelSummary.Publisher, modelSummary.Name), "this is my prompt"})
5454

5555
_, err := runCmd.ExecuteC()
5656

cmd/view/view.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"fmt"
66

77
"github.com/AlecAivazis/survey/v2"
8+
"github.com/MakeNowJust/heredoc"
89
"github.com/github/gh-models/internal/azuremodels"
910
"github.com/github/gh-models/pkg/command"
10-
"github.com/MakeNowJust/heredoc"
1111
"github.com/spf13/cobra"
1212
)
1313

@@ -25,8 +25,8 @@ func NewViewCommand(cfg *command.Config) *cobra.Command {
2525
If you know which model you want information for, you can run the request in a single command
2626
as %[1]sgh models view [model]%[1]s
2727
`, "`"),
28-
Example: "gh models view gpt-4o",
29-
Args: cobra.ArbitraryArgs,
28+
Example: "gh models view openai/gpt-4.1",
29+
Args: cobra.ArbitraryArgs,
3030
RunE: func(cmd *cobra.Command, args []string) error {
3131
ctx := cmd.Context()
3232
client := cfg.Client
@@ -50,7 +50,7 @@ func NewViewCommand(cfg *command.Config) *cobra.Command {
5050
if !model.IsChatModel() {
5151
continue
5252
}
53-
prompt.Options = append(prompt.Options, model.FriendlyName)
53+
prompt.Options = append(prompt.Options, azuremodels.FormatIdentifier(model.Publisher, model.Name))
5454
}
5555

5656
err = survey.AskOne(prompt, &modelName, survey.WithPageSize(10))

cmd/view/view_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestView(t *testing.T) {
4949
buf := new(bytes.Buffer)
5050
cfg := command.NewConfig(buf, buf, client, true, 80)
5151
viewCmd := NewViewCommand(cfg)
52-
viewCmd.SetArgs([]string{modelSummary.Name})
52+
viewCmd.SetArgs([]string{azuremodels.FormatIdentifier(modelSummary.Publisher, modelSummary.Name)})
5353

5454
_, err := viewCmd.ExecuteC()
5555

internal/azuremodels/azure_client_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package azuremodels
22

33
const (
4-
defaultInferenceURL = "https://models.inference.ai.azure.com/chat/completions"
4+
defaultInferenceURL = "https://models.github.ai/inference/chat/completions"
55
defaultAzureAiStudioURL = "https://api.catalog.azureml.ms"
66
defaultModelsURL = defaultAzureAiStudioURL + "/asset-gallery/v1.0/models"
77
)

internal/azuremodels/model_details.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package azuremodels
22

3-
import "fmt"
3+
import (
4+
"fmt"
5+
"strings"
6+
)
47

58
// ModelDetails includes detailed information about a model.
69
type ModelDetails struct {
@@ -22,3 +25,15 @@ type ModelDetails struct {
2225
func (m *ModelDetails) ContextLimits() string {
2326
return fmt.Sprintf("up to %d input tokens and %d output tokens", m.MaxInputTokens, m.MaxOutputTokens)
2427
}
28+
29+
// FormatIdentifier formats the model identifier based on the publisher and model name.
30+
func FormatIdentifier(publisher, name string) string {
31+
formatPart := func(s string) string {
32+
// Replace spaces with dashes and convert to lowercase
33+
result := strings.ToLower(s)
34+
result = strings.ReplaceAll(result, " ", "-")
35+
return result
36+
}
37+
38+
return fmt.Sprintf("%s/%s", formatPart(publisher), formatPart(name))
39+
}

internal/azuremodels/model_details_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,12 @@ func TestModelDetails(t *testing.T) {
1212
result := details.ContextLimits()
1313
require.Equal(t, "up to 123 input tokens and 456 output tokens", result)
1414
})
15+
16+
t.Run("FormatIdentifier", func(t *testing.T) {
17+
publisher := "Open AI"
18+
name := "GPT 3"
19+
expected := "open-ai/gpt-3"
20+
result := FormatIdentifier(publisher, name)
21+
require.Equal(t, expected, result)
22+
})
1523
}

internal/azuremodels/model_summary.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ func (m *ModelSummary) IsChatModel() bool {
2525

2626
// HasName checks if the model has the given name.
2727
func (m *ModelSummary) HasName(name string) bool {
28-
return strings.EqualFold(m.FriendlyName, name) || strings.EqualFold(m.Name, name)
28+
modelID := FormatIdentifier(m.Publisher, m.Name)
29+
return strings.EqualFold(modelID, name)
2930
}
3031

3132
var (
@@ -49,9 +50,9 @@ func SortModels(models []*ModelSummary) {
4950

5051
// Otherwise, sort by friendly name
5152
// Note: sometimes the casing returned by the API is inconsistent, so sort using lowercase values.
52-
friendlyNameI := strings.ToLower(models[i].FriendlyName)
53-
friendlyNameJ := strings.ToLower(models[j].FriendlyName)
53+
idI := FormatIdentifier(models[i].Publisher, models[i].Name)
54+
idJ := FormatIdentifier(models[j].Publisher, models[j].Name)
5455

55-
return friendlyNameI < friendlyNameJ
56+
return idI < idJ
5657
})
5758
}

internal/azuremodels/model_summary_test.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,26 @@ func TestModelSummary(t *testing.T) {
1818
})
1919

2020
t.Run("HasName", func(t *testing.T) {
21-
model := &ModelSummary{Name: "foo123", FriendlyName: "Foo 123"}
21+
model := &ModelSummary{Name: "foo123", Publisher: "bar"}
2222

23-
require.True(t, model.HasName(model.Name))
24-
require.True(t, model.HasName("FOO123"))
25-
require.True(t, model.HasName(model.FriendlyName))
26-
require.True(t, model.HasName("fOo 123"))
23+
require.True(t, model.HasName(FormatIdentifier(model.Publisher, model.Name)))
24+
require.True(t, model.HasName("BaR/foO123"))
2725
require.False(t, model.HasName("completely different value"))
2826
require.False(t, model.HasName("foo"))
27+
require.False(t, model.HasName("bar"))
2928
})
3029

31-
t.Run("SortModels sorts given slice in-place by friendly name, case-insensitive", func(t *testing.T) {
32-
modelA := &ModelSummary{Name: "z", FriendlyName: "AARDVARK"}
33-
modelB := &ModelSummary{Name: "y", FriendlyName: "betta"}
34-
modelC := &ModelSummary{Name: "x", FriendlyName: "Cat"}
35-
models := []*ModelSummary{modelB, modelA, modelC}
30+
t.Run("SortModels sorts given slice in-place by publisher/name", func(t *testing.T) {
31+
modelA := &ModelSummary{Publisher: "a", Name: "z"}
32+
modelB := &ModelSummary{Publisher: "a", Name: "Y"}
33+
modelC := &ModelSummary{Publisher: "b", Name: "x"}
34+
models := []*ModelSummary{modelC, modelB, modelA}
3635

3736
SortModels(models)
3837

3938
require.Equal(t, 3, len(models))
40-
require.Equal(t, "AARDVARK", models[0].FriendlyName)
41-
require.Equal(t, "betta", models[1].FriendlyName)
42-
require.Equal(t, "Cat", models[2].FriendlyName)
39+
require.Equal(t, "Y", models[0].Name)
40+
require.Equal(t, "z", models[1].Name)
41+
require.Equal(t, "x", models[2].Name)
4342
})
4443
}

0 commit comments

Comments
 (0)