diff --git a/.changeset/loud-bananas-shout.md b/.changeset/loud-bananas-shout.md new file mode 100644 index 0000000000..ab86c9f9cb --- /dev/null +++ b/.changeset/loud-bananas-shout.md @@ -0,0 +1,5 @@ +--- +"llamaindex": patch +--- + +corrected the regex in the react.ts file in extractToolUse & extractJsonStr functions, as mentioned in https://github.com/run-llama/LlamaIndexTS/issues/1019 diff --git a/packages/llamaindex/src/agent/react.ts b/packages/llamaindex/src/agent/react.ts index 091348f53e..866a5faa9e 100644 --- a/packages/llamaindex/src/agent/react.ts +++ b/packages/llamaindex/src/agent/react.ts @@ -66,7 +66,7 @@ function reasonFormatter(reason: Reason): string | Promise { } function extractJsonStr(text: string): string { - const pattern = /\{.*}/s; + const pattern = /\{.*\}/s; const match = text.match(pattern); if (!match) { @@ -98,7 +98,7 @@ function extractToolUse( inputText: string, ): [thought: string, action: string, input: string] { const pattern = - /\s*Thought: (.*?)\nAction: ([a-zA-Z0-9_]+).*?\.*Input: .*?(\{.*?})/s; + /\s*Thought: (.*?)\nAction: ([a-zA-Z0-9_]+).*?\.*Input: .*?(\{.*?\})/s; const match = inputText.match(pattern);