Skip to content

Commit

Permalink
feat: add proxy support to commit command
Browse files Browse the repository at this point in the history
- Add `httpsProxy` and `socksProxy` flags to `commit` command
- Set `openai.proxy` to `httpsProxy` if it is not empty
- Set `openai.socks` to `socksProxy` if it is not empty`
  • Loading branch information
appleboy committed Mar 13, 2023
1 parent 78678d7 commit 4364fcf
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cmd/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ var (
preview bool
diffUnified int
excludeList []string
httpsProxy string
socksProxy string
)

func init() {
Expand All @@ -31,6 +33,8 @@ func init() {
commitCmd.PersistentFlags().StringVar(&commitModel, "model", "gpt-3.5-turbo", "select openai model")
commitCmd.PersistentFlags().StringVar(&commitLang, "lang", "en", "summarizing language uses English by default")
commitCmd.PersistentFlags().StringSliceVar(&excludeList, "exclude_list", []string{}, "exclude file from git diff command")
commitCmd.PersistentFlags().StringVar(&httpsProxy, "proxy", "", "http proxy")
commitCmd.PersistentFlags().StringVar(&socksProxy, "socks", "", "socks proxy")
_ = viper.BindPFlag("output.file", commitCmd.PersistentFlags().Lookup("file"))
}

Expand Down Expand Up @@ -72,6 +76,14 @@ var commitCmd = &cobra.Command{
viper.Set("openai.model", commitModel)
}

if httpsProxy != "" {
viper.Set("openai.proxy", httpsProxy)
}

if socksProxy != "" {
viper.Set("openai.socks", socksProxy)
}

color.Green("Summarize the commit message use " + viper.GetString("openai.model") + " model")
client, err := openai.New(
openai.WithToken(viper.GetString("openai.api_key")),
Expand Down

0 comments on commit 4364fcf

Please sign in to comment.