Skip to content

Commit

Permalink
Provide more detail to the output of --help (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
JessRudder authored Oct 18, 2024
2 parents 1e426af + 14008ab commit 516aef5
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 3 deletions.
7 changes: 7 additions & 0 deletions cmd/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/cli/go-gh/v2/pkg/tableprinter"
"github.com/github/gh-models/internal/azuremodels"
"github.com/github/gh-models/pkg/command"
"github.com/MakeNowJust/heredoc"
"github.com/mgutz/ansi"
"github.com/spf13/cobra"
)
Expand All @@ -20,6 +21,12 @@ func NewListCommand(cfg *command.Config) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List available models",
Long: heredoc.Docf(`
Returns a list of models that are available to use via the CLI.
Values from the "MODEL NAME" column can be used as the %[1]s[model]%[1]s
argument in other commands.
`, "`"),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
Expand Down
2 changes: 1 addition & 1 deletion cmd/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestList(t *testing.T) {
err := listCmd.Help()

require.NoError(t, err)
require.Contains(t, outBuf.String(), "List available models")
require.Contains(t, outBuf.String(), "Returns a list of models that are available to use via the CLI.\n\nValues from the \"MODEL NAME\" column can be used as the `[model]`\nargument in other commands.")
require.Empty(t, errBuf.String())
})
}
11 changes: 11 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/github/gh-models/internal/azuremodels"
"github.com/github/gh-models/pkg/command"
"github.com/github/gh-models/pkg/util"
"github.com/MakeNowJust/heredoc"
"github.com/spf13/cobra"
)

Expand All @@ -21,6 +22,16 @@ func NewRootCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "models",
Short: "GitHub Models extension",
Long: heredoc.Docf(`
GitHub Models CLI extension allows you to experiment with AI models from the command line.
To see a list of all available commands, run %[1]sgh models help%[1]s. To run the extension in
interactive mode, run %[1]sgh models run%[1]s. This will prompt you to select a model and then
enter a prompt. The extension will then return a response from the model.
For more information about what you can do with GitHub Models extension, see the manual
at https://github.com/github/gh-models/blob/main/README.md.
`, "`"),
}

terminal := term.FromEnv()
Expand Down
14 changes: 14 additions & 0 deletions cmd/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/github/gh-models/internal/sse"
"github.com/github/gh-models/pkg/command"
"github.com/github/gh-models/pkg/util"
"github.com/MakeNowJust/heredoc"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
Expand Down Expand Up @@ -192,6 +193,19 @@ func NewRunCommand(cfg *command.Config) *cobra.Command {
cmd := &cobra.Command{
Use: "run [model] [prompt]",
Short: "Run inference with the specified model",
Long: heredoc.Docf(`
Prompts the specified model with the given prompt.
Use %[1]sgh models run%[1]s to run in interactive mode. It will provide a list of the current
models and allow you to select the one you want to run an inference with. After you select the model
you will be able to enter the prompt you want to run via the selected model.
If you know which model you want to run inference with, you can run the request in a single command
as %[1]sgh models run [model] [prompt]%[1]s
The return value will be the response to your prompt from the selected model.
`, "`"),
Example: "gh models run gpt-4o-mini \"how many types of hyena are there?\"",
Args: cobra.ArbitraryArgs,
RunE: func(cmd *cobra.Command, args []string) error {
cmdHandler := newRunCommandHandler(cmd, cfg, args)
Expand Down
2 changes: 1 addition & 1 deletion cmd/run/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestRun(t *testing.T) {

require.NoError(t, err)
output := outBuf.String()
require.Contains(t, output, "Run inference with the specified model")
require.Contains(t, output, "Use `gh models run` to run in interactive mode. It will provide a list of the current\nmodels and allow you to select the one you want to run an inference with.")
require.Regexp(t, regexp.MustCompile(`--max-tokens string\s+Limit the maximum tokens for the model response\.`), output)
require.Regexp(t, regexp.MustCompile(`--system-prompt string\s+Prompt the system\.`), output)
require.Regexp(t, regexp.MustCompile(`--temperature string\s+Controls randomness in the response, use lower to be more deterministic\.`), output)
Expand Down
11 changes: 11 additions & 0 deletions cmd/view/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/AlecAivazis/survey/v2"
"github.com/github/gh-models/internal/azuremodels"
"github.com/github/gh-models/pkg/command"
"github.com/MakeNowJust/heredoc"
"github.com/spf13/cobra"
)

Expand All @@ -15,6 +16,16 @@ func NewViewCommand(cfg *command.Config) *cobra.Command {
cmd := &cobra.Command{
Use: "view [model]",
Short: "View details about a model",
Long: heredoc.Docf(`
Returns details about the specified model.
Use %[1]sgh models view%[1]s to run in interactive mode. It will provide a list of the current
models and allow you to select the one you want information about.
If you know which model you want information for, you can run the request in a single command
as %[1]sgh models view [model]%[1]s
`, "`"),
Example: "gh models view gpt-4o",
Args: cobra.ArbitraryArgs,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
Expand Down
2 changes: 1 addition & 1 deletion cmd/view/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestView(t *testing.T) {
err := viewCmd.Help()

require.NoError(t, err)
require.Contains(t, outBuf.String(), "View details about a model")
require.Contains(t, outBuf.String(), "Use `gh models view` to run in interactive mode. It will provide a list of the current\nmodels and allow you to select the one you want information about.")
require.Empty(t, errBuf.String())
})
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ toolchain go1.22.8

require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/MakeNowJust/heredoc v1.0.0
github.com/briandowns/spinner v1.23.1
github.com/cli/cli/v2 v2.58.0
github.com/cli/go-gh/v2 v2.10.0
Expand Down

0 comments on commit 516aef5

Please sign in to comment.