Merge pull request #54 from jmorganca/empty-line
no prompt on empty line
This commit is contained in:
commit
0fea50cd42
2 changed files with 31 additions and 26 deletions
56
cmd/cmd.go
56
cmd/cmd.go
|
@ -9,6 +9,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/schollz/progressbar/v3"
|
"github.com/schollz/progressbar/v3"
|
||||||
|
@ -75,38 +76,41 @@ func RunGenerate(_ *cobra.Command, args []string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func generate(model, prompt string) error {
|
func generate(model, prompt string) error {
|
||||||
client := api.NewClient()
|
if len(strings.TrimSpace(prompt)) > 0 {
|
||||||
|
client := api.NewClient()
|
||||||
|
|
||||||
spinner := progressbar.NewOptions(-1,
|
spinner := progressbar.NewOptions(-1,
|
||||||
progressbar.OptionSetWriter(os.Stderr),
|
progressbar.OptionSetWriter(os.Stderr),
|
||||||
progressbar.OptionThrottle(60*time.Millisecond),
|
progressbar.OptionThrottle(60*time.Millisecond),
|
||||||
progressbar.OptionSpinnerType(14),
|
progressbar.OptionSpinnerType(14),
|
||||||
progressbar.OptionSetRenderBlankState(true),
|
progressbar.OptionSetRenderBlankState(true),
|
||||||
progressbar.OptionSetElapsedTime(false),
|
progressbar.OptionSetElapsedTime(false),
|
||||||
progressbar.OptionClearOnFinish(),
|
progressbar.OptionClearOnFinish(),
|
||||||
)
|
)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for range time.Tick(60 * time.Millisecond) {
|
for range time.Tick(60 * time.Millisecond) {
|
||||||
if spinner.IsFinished() {
|
if spinner.IsFinished() {
|
||||||
break
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
spinner.Add(1)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
client.Generate(context.Background(), &api.GenerateRequest{Model: model, Prompt: prompt}, func(resp api.GenerateResponse) error {
|
||||||
|
if !spinner.IsFinished() {
|
||||||
|
spinner.Finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
spinner.Add(1)
|
fmt.Print(resp.Response)
|
||||||
}
|
return nil
|
||||||
}()
|
})
|
||||||
|
|
||||||
client.Generate(context.Background(), &api.GenerateRequest{Model: model, Prompt: prompt}, func(resp api.GenerateResponse) error {
|
fmt.Println()
|
||||||
if !spinner.IsFinished() {
|
fmt.Println()
|
||||||
spinner.Finish()
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Print(resp.Response)
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
fmt.Println()
|
|
||||||
fmt.Println()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
{{ .Prompt }}
|
{{ .Prompt }}
|
||||||
|
|
||||||
### Response:
|
### Response:
|
||||||
|
|
Loading…
Reference in a new issue