Merge pull request #957 from quarechen/specify_language_return
Add cmd -g to select the language would reply
This commit is contained in:
commit
a61590efeb
@ -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
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ type ChatRequest struct {
|
||||
PatternName string
|
||||
PatternVariables map[string]string
|
||||
Message string
|
||||
Language string
|
||||
}
|
||||
|
||||
type ChatOptions struct {
|
||||
|
@ -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
|
||||
@ -101,4 +103,5 @@ type Chat struct {
|
||||
Pattern string
|
||||
Message string
|
||||
Session *db.Session
|
||||
Language string
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user