Skip to content

Commit

Permalink
chore: interactive switch
Browse files Browse the repository at this point in the history
  • Loading branch information
williamfzc committed Mar 18, 2023
1 parent ccfc46c commit 8650afc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 8 additions & 3 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type ApiConfig struct {
RendererType RendererType `json:"rendererType"`
RendererBin string `json:"rendererBin"`
ClientType ClientType `json:"clientType"`
Interactive bool `json:"interactive"`
}

var logger = log.Default()
Expand Down Expand Up @@ -46,7 +47,7 @@ func GenAndRenderString(shellContext *ishell.Context, config ApiConfig) (string,
shellContext.Println("start generating ...")
topics := make([]*Topic, 0)
for _, eachTopic := range config.Topics {
finalTopic, err := getFinalTopic(shellContext, c, eachTopic)
finalTopic, err := getFinalTopic(shellContext, c, eachTopic, config.Interactive)
if err != nil {
return "", err
}
Expand All @@ -66,19 +67,23 @@ func GenAndRenderString(shellContext *ishell.Context, config ApiConfig) (string,
return str, nil
}

func getFinalTopic(shellContext *ishell.Context, c Client, eachTopic string) (*Topic, error) {
func getFinalTopic(shellContext *ishell.Context, c Client, eachTopic string, needConfirm bool) (*Topic, error) {
resp, err := c.FillTopic(eachTopic)
if err != nil {
return nil, err
}

if !needConfirm {
return resp, nil
}

shellContext.Println("Here is your response, type any key to continue, type 'n' to edit", resp.ToMarkdown())
ok := shellContext.ReadLine()
if ok != "n" {
return resp, nil
} else {
shellContext.Println("You can enter a new topic to regenerate this page.")
newTopic := shellContext.ReadLine()
return getFinalTopic(shellContext, c, newTopic)
return getFinalTopic(shellContext, c, newTopic, needConfirm)
}
}
2 changes: 2 additions & 0 deletions cmd/cgp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func main() {
rendererType := flag.String("renderer", cgp.RendererRemark, "renderer type")
rendererBin := flag.String("rendererBin", "", "binary file for renderer")
clientType := flag.String("client", cgp.ClientGpt35, "gpt client type")
interactive := flag.Bool("i", false, "interactive mode")
flag.Parse()

// prepare
Expand All @@ -34,6 +35,7 @@ func main() {
RendererType: *rendererType,
RendererBin: *rendererBin,
ClientType: *clientType,
Interactive: *interactive,
}

shell := ishell.New()
Expand Down

0 comments on commit 8650afc

Please sign in to comment.