Skip to content

Commit

Permalink
Merge pull request #5 from ntauth/feature/mrkl-final-answer-regex
Browse files Browse the repository at this point in the history
feat: make mrkl final answer parsing more reliable
  • Loading branch information
ntauth authored Mar 29, 2024
2 parents 0e35361 + c112f3c commit 46b4622
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions agents/mrkl.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
)

const (
_finalAnswerAction = "Final Answer:"
_defaultOutputKey = "output"
_finalAnswerActionRegex = "(?i)Final Answer:"
_defaultOutputKey = "output"
)

// OneShotZeroAgent is a struct that represents an agent responsible for deciding
Expand Down Expand Up @@ -116,8 +116,10 @@ func (a *OneShotZeroAgent) GetOutputKeys() []string {
}

func (a *OneShotZeroAgent) parseOutput(output string) ([]schema.AgentAction, *schema.AgentFinish, error) {
if strings.Contains(output, _finalAnswerAction) {
splits := strings.Split(output, _finalAnswerAction)
finalAnswerRegex := regexp.MustCompile(_finalAnswerActionRegex)
finalAnswerPrefixMatches := finalAnswerRegex.FindStringSubmatch(output)
if len(finalAnswerPrefixMatches) != 0 {
splits := strings.Split(output, finalAnswerPrefixMatches[0])

return nil, &schema.AgentFinish{
ReturnValues: map[string]any{
Expand Down

0 comments on commit 46b4622

Please sign in to comment.