-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add lint workflow #10
Conversation
As copied from another internal repo.
> Error return value of `io.WriteString` is not checked
Error: internal/azure_models/client.go:2:9: var-naming: don't use an underscore in package name (revive) package azure_models ^
Linter errors like: Error: internal/azuremodels/client.go:56:33: should rewrite http.NewRequestWithContext or add (*Request).WithContext (noctx) httpReq, err := http.NewRequest("POST", prodInferenceURL, body) ^
Error: cmd/run/run.go:191:1: Function name: NewRunCommand, Cyclomatic Complexity: 50, Halstead Volume: 6931.94, Maintainability Index: 13 (maintidx) func NewRunCommand() *cobra.Command { ^
Working toward fixing linter issues like these: Error: cmd/run/run.go:320:5: deferInLoop: Possible resource leak, 'defer' is called in the 'for' loop (gocritic) defer sp.Stop() ^ Error: cmd/run/run.go:327:5: deferInLoop: Possible resource leak, 'defer' is called in the 'for' loop (gocritic) defer resp.Reader.Close() ^
@@ -75,3 +78,13 @@ func NewListCommand() *cobra.Command { | |||
|
|||
return cmd | |||
} | |||
|
|||
func filterToChatModels(models []*azuremodels.ModelSummary) []*azuremodels.ModelSummary { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved from the ux
package because it was only used here.
@@ -1,14 +1,15 @@ | |||
// Package list provides a gh command to list available models. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot helped with the package and function docs. cc @brannon for input on whether Copilot and I described things accurately.
@@ -28,28 +30,29 @@ func NewListCommand() *cobra.Command { | |||
|
|||
token, _ := auth.TokenForHost("github.com") | |||
if token == "" { | |||
io.WriteString(out, "No GitHub token found. Please run 'gh auth login' to authenticate.\n") | |||
util.WriteToOut(out, "No GitHub token found. Please run 'gh auth login' to authenticate.\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved io.WriteString
calls to a new function that handles the returned error.
This PR is big enough already!
@@ -176,73 +189,26 @@ func isPipe(r io.Reader) bool { | |||
return false | |||
} | |||
|
|||
// NewRunCommand returns a new gh command for running a model. | |||
func NewRunCommand() *cobra.Command { | |||
cmd := &cobra.Command{ | |||
Use: "run [model] [prompt]", | |||
Short: "Run inference with the specified model", | |||
Args: cobra.ArbitraryArgs, | |||
RunE: func(cmd *cobra.Command, args []string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of changes to shrink this function because the linter complained about its complexity.
|
||
"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/azuremodels" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The linter dislikes underscores in package names.
@@ -439,3 +364,186 @@ func NewRunCommand() *cobra.Command { | |||
|
|||
return cmd | |||
} | |||
|
|||
type runCommandHandler struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a type to bundle together various things that are used in several pieces of the run handler function, so the large function could be more easily split into multiple functions.
@@ -30,27 +36,30 @@ type ChatCompletionOptions struct { | |||
TopP *float64 `json:"top_p,omitempty"` | |||
} | |||
|
|||
type ChatChoiceMessage struct { | |||
type chatChoiceMessage struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made some types internal to this package since they weren't used outside it.
func (m *ModelDetails) ContextLimits() string { | ||
return fmt.Sprintf("up to %d input tokens and %d output tokens", m.MaxInputTokens, m.MaxOutputTokens) | ||
} | ||
|
||
func Ptr[T any](value T) *T { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this to the util package since it felt generic.
sort.Slice(models, func(i, j int) bool { | ||
// Sort featured models first, by name | ||
isFeaturedI := slices.Contains(featuredModelNames, models[i].Name) | ||
isFeaturedJ := slices.Contains(featuredModelNames, models[j].Name) | ||
|
||
if isFeaturedI && !isFeaturedJ { | ||
return true | ||
} else if !isFeaturedI && isFeaturedJ { | ||
return false | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The linter complained about using else
branches when each branch returned.
@@ -20,12 +21,12 @@ func main() { | |||
} | |||
|
|||
func mainRun() exitCode { | |||
cmd := cmd.NewRootCommand() | |||
rootCmd := cmd.NewRootCommand() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable name cmd
shadowed an import.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I've run through a bunch of commands locally on this branch and it all worked great 👍
Part of https://github.com/github/models/issues/330. This adds a new Actions build for running the Go linter. I also fixed outstanding things the linter flagged. I'd love to make this new build required once this PR lands, to help keep things tidy, especially once we open source the repo and get external contributors.
I tried the
view
,run
with a prompt,run
in interactive mode, andlist
commands locally and they seem all right. I would appreciate additional verification from reviewers that this PR doesn't break anything. 🙇🏻♀️