mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 13:00:56 +03:00
update xml output parser
This commit is contained in:
@@ -779,3 +779,36 @@ Final Answer: the final answer to the original input question`
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export class XMLAgentOutputParser extends AgentActionOutputParser {
|
||||
lc_namespace = ['langchain', 'agents', 'xml']
|
||||
|
||||
static lc_name() {
|
||||
return 'XMLAgentOutputParser'
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the output text from the agent and returns an AgentAction or
|
||||
* AgentFinish object.
|
||||
* @param text The output text from the agent.
|
||||
* @returns An AgentAction or AgentFinish object.
|
||||
*/
|
||||
async parse(text: string): Promise<AgentAction | AgentFinish> {
|
||||
if (text.includes('</tool>')) {
|
||||
const [tool, toolInput] = text.split('</tool>')
|
||||
const _tool = tool.split('<tool>')[1]
|
||||
const _toolInput = toolInput.split('<tool_input>')[1]
|
||||
return { tool: _tool, toolInput: _toolInput, log: text }
|
||||
} else if (text.includes('<final_answer>')) {
|
||||
const [, answer] = text.split('<final_answer>')
|
||||
return { returnValues: { output: answer }, log: text }
|
||||
} else {
|
||||
// Instead of throwing Error, we return a AgentFinish object
|
||||
return { returnValues: { output: text }, log: text }
|
||||
}
|
||||
}
|
||||
|
||||
getFormatInstructions(): string {
|
||||
throw new Error('getFormatInstructions not implemented inside XMLAgentOutputParser.')
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user