From 32b11101d3beb47ce7c5c4759c9048c47f814dfc Mon Sep 17 00:00:00 2001 From: Samantha Whitmore Date: Sat, 4 Feb 2023 20:42:25 -0800 Subject: [PATCH] Get elements of ActionInput on newlines (#889) The re.DOTALL flag in Python's re (regular expression) module makes the . (dot) metacharacter match newline characters as well as any other character. Without re.DOTALL, the . metacharacter only matches any character except for a newline character. With re.DOTALL, the . metacharacter matches any character, including newline characters. --- langchain/agents/mrkl/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/langchain/agents/mrkl/base.py b/langchain/agents/mrkl/base.py index fb2acfb4..4477cb6d 100644 --- a/langchain/agents/mrkl/base.py +++ b/langchain/agents/mrkl/base.py @@ -40,7 +40,7 @@ def get_action_and_input(llm_output: str) -> Tuple[str, str]: if FINAL_ANSWER_ACTION in llm_output: return "Final Answer", llm_output.split(FINAL_ANSWER_ACTION)[-1].strip() regex = r"Action: (.*?)\nAction Input: (.*)" - match = re.search(regex, llm_output) + match = re.search(regex, llm_output, re.DOTALL) if not match: raise ValueError(f"Could not parse LLM output: `{llm_output}`") action = match.group(1).strip()