File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -38,12 +38,18 @@ export class XMLAgentOutputParser extends AgentActionOutputParser {
38
38
*/
39
39
async parse ( text : string ) : Promise < AgentAction | AgentFinish > {
40
40
if ( text . includes ( "</tool>" ) ) {
41
- const [ tool , toolInput ] = text . split ( "</tool>" ) ;
42
- const _tool = tool . split ( "<tool>" ) [ 1 ] ;
43
- const _toolInput = toolInput . split ( "<tool_input>" ) [ 1 ] ;
41
+ const _toolMatch = text . match ( / < t o o l > ( [ ^ < ] * ) < \/ t o o l > / ) ;
42
+ const _tool = _toolMatch ? _toolMatch [ 1 ] : "" ;
43
+ const _toolInputMatch = text . match (
44
+ / < t o o l _ i n p u t > ( [ ^ < ] * ?) (?: < \/ t o o l _ i n p u t > | $ ) /
45
+ ) ;
46
+ const _toolInput = _toolInputMatch ? _toolInputMatch [ 1 ] : "" ;
44
47
return { tool : _tool , toolInput : _toolInput , log : text } ;
45
48
} else if ( text . includes ( "<final_answer>" ) ) {
46
- const [ , answer ] = text . split ( "<final_answer>" ) ;
49
+ const answerMatch = text . match (
50
+ / < f i n a l _ a n s w e r > ( [ ^ < ] * ?) (?: < \/ f i n a l _ a n s w e r > | $ ) /
51
+ ) ;
52
+ const answer = answerMatch ? answerMatch [ 1 ] : "" ;
47
53
return { returnValues : { output : answer } , log : text } ;
48
54
} else {
49
55
throw new OutputParserException ( `Could not parse LLM output: ${ text } ` ) ;
You can’t perform that action at this time.
0 commit comments