From 5db44e3d0864c6583022ea287e5b3dfe6a2f9a5c Mon Sep 17 00:00:00 2001 From: kevin Date: Wed, 6 Oct 2021 23:11:23 +0800 Subject: [PATCH] feat: support simple mode in asking --- cli/ask/ask.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/cli/ask/ask.go b/cli/ask/ask.go index d818a25..1c0602b 100644 --- a/cli/ask/ask.go +++ b/cli/ask/ask.go @@ -13,11 +13,10 @@ import ( "github.com/kevwan/chatbot/bot/adapters/storage" ) -const tops = 5 - var ( verbose = flag.Bool("v", false, "verbose mode") storeFile = flag.String("c", "corpus.gob", "the file to store corpora") + tops = flag.Int("t", 5, "the number of answers to return") ) func main() { @@ -29,7 +28,7 @@ func main() { } chatbot := &bot.ChatBot{ - LogicAdapter: logic.NewClosestMatch(store, tops), + LogicAdapter: logic.NewClosestMatch(store, *tops), } if *verbose { chatbot.LogicAdapter.SetVerbose() @@ -46,13 +45,17 @@ func main() { startTime := time.Now() answers := chatbot.GetResponse(question) - for i, answer := range answers { - fmt.Printf("%d: %s\n", i+1, answer.Content) - if *verbose { - fmt.Printf("%d: %s\tConfidence: %.3f\t%s\n", i+1, answer.Content, - answer.Confidence, time.Since(startTime)) + if *tops == 1 { + fmt.Printf("A: %s\n", answers[0].Content) + } else { + for i, answer := range answers { + fmt.Printf("%d: %s\n", i+1, answer.Content) + if *verbose { + fmt.Printf("%d: %s\tConfidence: %.3f\t%s\n", i+1, answer.Content, + answer.Confidence, time.Since(startTime)) + } } + fmt.Println(time.Since(startTime)) } - fmt.Println(time.Since(startTime)) } }