-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
0 parents
commit ea2387f
Showing
15 changed files
with
1,031 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,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 |
This file contains 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,2 @@ | ||
/gh-models | ||
/gh-models.exe |
This file contains 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,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`. |
This file contains 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,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 | ||
} |
This file contains 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,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 | ||
} |
Oops, something went wrong.