diff --git a/README.md b/README.md index 25fcefa..258879c 100644 --- a/README.md +++ b/README.md @@ -215,6 +215,7 @@ Application Options: --transcript Grab transcript from YouTube video and send to chat --comments Grab comments from YouTube video and send to chat --dry-run Show what would be sent to the model without actually sending it + -g, --language= Specify the Language Code for the chat, e.g. -g=en -g=zh -u, --scrape_url= Scrape website URL to markdown using Jina AI -q, --scrape_question= Search question using Jina AI diff --git a/cli/flags.go b/cli/flags.go index 40e2735..020d7d3 100644 --- a/cli/flags.go +++ b/cli/flags.go @@ -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 @@ -40,6 +41,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:"Specify the Language Code for the chat, e.g. -g=en -g=zh" default:""` ScrapeURL string `short:"u" long:"scrape_url" description:"Scrape website URL to markdown using Jina AI"` ScrapeQuestion string `short:"q" long:"scrape_question" description:"Search question using Jina AI"` } @@ -109,6 +111,12 @@ func (o *Flags) BuildChatRequest() (ret *common.ChatRequest) { PatternVariables: o.PatternVariables, Message: o.Message, } + if o.Language != "" { + langTag, err := language.Parse(o.Language) + if err == nil { + ret.Language = langTag.String() + } + } return } diff --git a/common/domain.go b/common/domain.go index 3839e8e..33365a7 100644 --- a/common/domain.go +++ b/common/domain.go @@ -13,6 +13,7 @@ type ChatRequest struct { PatternName string PatternVariables map[string]string Message string + Language string } type ChatOptions struct { diff --git a/core/chatter.go b/core/chatter.go index b69616b..84f948f 100644 --- a/core/chatter.go +++ b/core/chatter.go @@ -60,7 +60,9 @@ func (o *Chatter) Send(request *common.ChatRequest, opts *common.ChatOptions) (m } func (o *Chatter) NewChat(request *common.ChatRequest) (ret *Chat, err error) { - ret = &Chat{} + ret = &Chat{ + Language: request.Language, + } if request.ContextName != "" { var ctx *db.Context @@ -97,8 +99,9 @@ func (o *Chatter) NewChat(request *common.ChatRequest) (ret *Chat, err error) { } type Chat struct { - Context string - Pattern string - Message string - Session *db.Session + Context string + Pattern string + Message string + Session *db.Session + Language string } diff --git a/core/fabric.go b/core/fabric.go index 56572cc..a70ff37 100644 --- a/core/fabric.go +++ b/core/fabric.go @@ -257,6 +257,9 @@ func (o *Chat) BuildChatSession(raw bool) (ret *db.Session, err error) { } systemMessage := strings.TrimSpace(o.Context) + strings.TrimSpace(o.Pattern) + if o.Language != "" { + systemMessage = fmt.Sprintf("%s. Please use the language '%s' for the output.", systemMessage, o.Language) + } userMessage := strings.TrimSpace(o.Message) if raw {