feat: add cmd -g to select the language would reply

This commit is contained in:
csquarechen
2024-09-13 16:41:54 +08:00
parent d25ea0e88b
commit b96415d445
6 changed files with 21 additions and 8 deletions

View File

@@ -9,6 +9,7 @@ import (
"github.com/danielmiessler/fabric/common"
"github.com/jessevdk/go-flags"
"golang.org/x/text/language"
)
// Flags create flags struct. the users flags go into this, this will be passed to the chat struct in cli
@@ -39,6 +40,7 @@ type Flags struct {
YouTubeTranscript bool `long:"transcript" description:"Grab transcript from YouTube video and send to chat"`
YouTubeComments bool `long:"comments" description:"Grab comments from YouTube video and send to chat"`
DryRun bool `long:"dry-run" description:"Show what would be sent to the model without actually sending it"`
Language string `short:"g" long:"language" description:"Language of the chat" default:"en"`
}
// Init Initialize flags. returns a Flags struct and an error
@@ -105,5 +107,10 @@ func (o *Flags) BuildChatRequest() (ret *common.ChatRequest) {
PatternVariables: o.PatternVariables,
Message: o.Message,
}
langTag, err := language.Parse(o.Language)
if err != nil {
langTag = language.English
}
ret.Language = langTag.String()
return
}