Skip to content

Commit ea2387f

Browse files
committed
Initial version of the gh models extension.
Includes basic functionality for: - Listing available models - Running inference with a specific model, both in "single-shot" and REPL modes. - Basic support for model parameters.
0 parents  commit ea2387f

File tree

15 files changed

+1031
-0
lines changed

15 files changed

+1031
-0
lines changed

.github/workflows/release.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: release
2+
on:
3+
push:
4+
tags:
5+
- "v*"
6+
permissions:
7+
contents: write
8+
9+
jobs:
10+
release:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- uses: cli/gh-extension-precompile@v1

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/gh-models
2+
/gh-models.exe

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## GitHub Models extension
2+
3+
Use the GitHub Models service from the CLI!
4+
5+
### Building
6+
7+
Run `script/build`.
8+
9+
### Prerequisites
10+
11+
The extension requires the `gh` CLI to be installed and in the PATH. The extension also requires the user have authenticated via `gh auth`.

cmd/list/list.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package list
2+
3+
import (
4+
"io"
5+
6+
"github.com/cli/go-gh/v2/pkg/auth"
7+
"github.com/cli/go-gh/v2/pkg/tableprinter"
8+
"github.com/cli/go-gh/v2/pkg/term"
9+
"github.com/github/gh-models/internal/azure_models"
10+
"github.com/github/gh-models/internal/ux"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
func NewListCommand() *cobra.Command {
15+
cmd := &cobra.Command{
16+
Use: "list",
17+
Short: "List available models",
18+
Args: cobra.NoArgs,
19+
RunE: func(cmd *cobra.Command, args []string) error {
20+
terminal := term.FromEnv()
21+
out := terminal.Out()
22+
23+
token, _ := auth.TokenForHost("github.com")
24+
if token == "" {
25+
io.WriteString(out, "No GitHub token found. Please run 'gh auth login' to authenticate.\n")
26+
return nil
27+
}
28+
29+
client := azure_models.NewClient(token)
30+
31+
models, err := client.ListModels()
32+
if err != nil {
33+
return err
34+
}
35+
36+
ux.SortModels(models)
37+
38+
width, _, _ := terminal.Size()
39+
printer := tableprinter.New(out, terminal.IsTerminalOutput(), width)
40+
41+
printer.AddHeader([]string{"Name", "Friendly Name", "Publisher"})
42+
printer.EndRow()
43+
44+
for _, model := range models {
45+
if !ux.IsChatModel(model) {
46+
continue
47+
}
48+
49+
printer.AddField(model.Name)
50+
printer.AddField(model.FriendlyName)
51+
printer.AddField(model.Publisher)
52+
printer.EndRow()
53+
}
54+
55+
err = printer.Render()
56+
if err != nil {
57+
return err
58+
}
59+
60+
return nil
61+
},
62+
}
63+
64+
return cmd
65+
}

cmd/root.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package cmd
2+
3+
import (
4+
"github.com/github/gh-models/cmd/list"
5+
"github.com/github/gh-models/cmd/run"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
func NewRootCommand() *cobra.Command {
10+
cmd := &cobra.Command{
11+
Use: "gh models",
12+
Short: "GitHub Models extension",
13+
}
14+
15+
cmd.AddCommand(list.NewListCommand())
16+
cmd.AddCommand(run.NewRunCommand())
17+
18+
return cmd
19+
}

0 commit comments

Comments
 (0)