Skip to content

Commit

Permalink
feat: split tools messages from use message
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeis committed Oct 29, 2024
1 parent f2fdd6e commit 38406ee
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
20 changes: 12 additions & 8 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ func Cli(version string) (err error) {

// if none of the above currentFlags are set, run the initiate chat function

var messageTools string

if currentFlags.YouTube != "" {
if registry.YouTube.IsConfigured() == false {
err = fmt.Errorf("YouTube is not configured, please run the setup procedure")
Expand All @@ -158,8 +160,7 @@ func Cli(version string) (err error) {
if transcript, err = registry.YouTube.GrabTranscript(videoId, language); err != nil {
return
}

currentFlags.AppendMessage(transcript)
messageTools = AppendMessage(messageTools, transcript)
}

if currentFlags.YouTubeComments {
Expand All @@ -170,12 +171,12 @@ func Cli(version string) (err error) {

commentsString := strings.Join(comments, "\n")

currentFlags.AppendMessage(commentsString)
messageTools = AppendMessage(messageTools, commentsString)
}

if !currentFlags.IsChatRequest() {
// if the pattern flag is not set, we wanted only to grab the transcript or comments
fmt.Println(currentFlags.Message)
fmt.Println(messageTools)
return
}
}
Expand All @@ -187,8 +188,7 @@ func Cli(version string) (err error) {
if website, err = registry.Jina.ScrapeURL(currentFlags.ScrapeURL); err != nil {
return
}

currentFlags.AppendMessage(website)
messageTools = AppendMessage(messageTools, website)
}

// Check if the scrape_question flag is set and call ScrapeQuestion
Expand All @@ -198,16 +198,20 @@ func Cli(version string) (err error) {
return
}

currentFlags.AppendMessage(website)
messageTools = AppendMessage(messageTools, website)
}

if !currentFlags.IsChatRequest() {
// if the pattern flag is not set, we wanted only to grab the url or get the answer to the question
fmt.Println(currentFlags.Message)
fmt.Println(messageTools)
return
}
}

if messageTools != "" {
currentFlags.AppendMessage(messageTools)
}

var chatter *core.Chatter
if chatter, err = registry.GetChatter(currentFlags.Model, currentFlags.Stream, currentFlags.DryRun); err != nil {
return
Expand Down
17 changes: 11 additions & 6 deletions cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,20 @@ func (o *Flags) BuildChatRequest(Meta string) (ret *common.ChatRequest, err erro
}

func (o *Flags) AppendMessage(message string) {
if o.Message != "" {
o.Message = o.Message + "\n" + message
} else {
o.Message = message
}
o.Message = AppendMessage(o.Message, message)
return
}

func (o *Flags) IsChatRequest() (ret bool) {
ret = o.Message != "" || o.Context != "" || o.Session != "" || o.Pattern != "" || len(o.Attachments) > 0
ret = o.Message != "" || len(o.Attachments) > 0 || o.Context != "" || o.Session != "" || o.Pattern != ""
return
}

func AppendMessage(message string, newMessage string) (ret string) {
if message != "" {
ret = message + "\n" + newMessage
} else {
ret = newMessage
}
return
}

0 comments on commit 38406ee

Please sign in to comment.