Skip to content

Commit

Permalink
fix: corrected the regex in the ReactAgent (run-llama#1022)
Browse files Browse the repository at this point in the history
Signed-off-by: ranjanmangla1 <ranjanmangla1@gmail.com>
  • Loading branch information
ranjanmangla1 authored Jul 9, 2024
1 parent 3ae832c commit a0f424e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-bananas-shout.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions packages/llamaindex/src/agent/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function reasonFormatter(reason: Reason): string | Promise<string> {
}

function extractJsonStr(text: string): string {
const pattern = /\{.*}/s;
const pattern = /\{.*\}/s;
const match = text.match(pattern);

if (!match) {
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit a0f424e

Please sign in to comment.