Skip to content

Commit 505e27f

Browse files
committed
================Commit Summary====================
feat: implement verbose output feature using viper settings for Client structure - Add a `verbose` flag to enable verbose output - Bind the `verbose` flag to the `viper` settings - Add import statements for `github.com/fatih/color` and `github.com/spf13/viper` - Include verbose printing based on the `verbose` flag in the `Completion` function of the `Client` structure. ==================================================
1 parent dbdf104 commit 505e27f

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

cmd/cmd.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var rootCmd = &cobra.Command{
2323
var (
2424
cfgFile string
2525
replacer = strings.NewReplacer("-", "_", ".", "_")
26+
verbose bool
2627
)
2728

2829
const (
@@ -34,6 +35,9 @@ func init() {
3435
cobra.OnInitialize(initConfig)
3536

3637
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.config/codegpt/.codegpt.yaml)")
38+
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose output")
39+
viper.BindPFlag("verbose", rootCmd.PersistentFlags().Lookup("verbose"))
40+
3741
rootCmd.AddCommand(versionCmd)
3842
rootCmd.AddCommand(configCmd)
3943
rootCmd.AddCommand(commitCmd)
@@ -101,7 +105,6 @@ func initConfig() {
101105
}
102106
}
103107
}
104-
105108
func Execute(ctx context.Context) {
106109
if _, err := rootCmd.ExecuteContextC(ctx); err != nil {
107110
os.Exit(1)

cmd/codegpt/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ import (
88

99
func main() {
1010
m := graceful.NewManager()
11+
1112
cmd.Execute(m.ShutdownContext())
1213
}

openai/openai.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"net/url"
99

1010
"github.com/appleboy/CodeGPT/groq"
11+
"github.com/fatih/color"
12+
"github.com/spf13/viper"
1113

1214
openai "github.com/sashabaranov/go-openai"
1315
"golang.org/x/net/proxy"
@@ -66,7 +68,6 @@ type Client struct {
6668
maxTokens int
6769
temperature float32
6870
isFuncCall bool
69-
7071
// An alternative to sampling with temperature, called nucleus sampling,
7172
// where the model considers the results of the tokens with top_p probability mass.
7273
// So 0.1 means only the tokens comprising the top 10% probability mass are considered.
@@ -171,6 +172,12 @@ func (c *Client) Completion(
171172
ctx context.Context,
172173
content string,
173174
) (*Response, error) {
175+
// Be verbose in case verbose flag is true and print the content to the console.
176+
// otherwise, tell me what the model is doing
177+
if viper.GetBool("verbose") {
178+
color.Cyan("VERBOSE PROMPT: " + content)
179+
}
180+
174181
resp := &Response{}
175182
switch c.model {
176183
case openai.GPT3Dot5Turbo,

0 commit comments

Comments
 (0)