Skip to content

Commit

Permalink
Initial version of the gh models extension.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brannon committed Aug 28, 2024
0 parents commit ea2387f
Show file tree
Hide file tree
Showing 15 changed files with 1,031 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: release
on:
push:
tags:
- "v*"
permissions:
contents: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cli/gh-extension-precompile@v1
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/gh-models
/gh-models.exe
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## GitHub Models extension

Use the GitHub Models service from the CLI!

### Building

Run `script/build`.

### Prerequisites

The extension requires the `gh` CLI to be installed and in the PATH. The extension also requires the user have authenticated via `gh auth`.
65 changes: 65 additions & 0 deletions cmd/list/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package list

import (
"io"

"github.com/cli/go-gh/v2/pkg/auth"
"github.com/cli/go-gh/v2/pkg/tableprinter"
"github.com/cli/go-gh/v2/pkg/term"
"github.com/github/gh-models/internal/azure_models"
"github.com/github/gh-models/internal/ux"
"github.com/spf13/cobra"
)

func NewListCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List available models",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
terminal := term.FromEnv()
out := terminal.Out()

token, _ := auth.TokenForHost("github.com")
if token == "" {
io.WriteString(out, "No GitHub token found. Please run 'gh auth login' to authenticate.\n")
return nil
}

client := azure_models.NewClient(token)

models, err := client.ListModels()
if err != nil {
return err
}

ux.SortModels(models)

width, _, _ := terminal.Size()
printer := tableprinter.New(out, terminal.IsTerminalOutput(), width)

printer.AddHeader([]string{"Name", "Friendly Name", "Publisher"})
printer.EndRow()

for _, model := range models {
if !ux.IsChatModel(model) {
continue
}

printer.AddField(model.Name)
printer.AddField(model.FriendlyName)
printer.AddField(model.Publisher)
printer.EndRow()
}

err = printer.Render()
if err != nil {
return err
}

return nil
},
}

return cmd
}
19 changes: 19 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmd

import (
"github.com/github/gh-models/cmd/list"
"github.com/github/gh-models/cmd/run"
"github.com/spf13/cobra"
)

func NewRootCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "gh models",
Short: "GitHub Models extension",
}

cmd.AddCommand(list.NewListCommand())
cmd.AddCommand(run.NewRunCommand())

return cmd
}
Loading

0 comments on commit ea2387f

Please sign in to comment.