From 7eba828e1b9542de4a0b67d1da2ffcfa83c6baca Mon Sep 17 00:00:00 2001 From: Harrison Chase Date: Wed, 8 Mar 2023 17:41:17 -0800 Subject: [PATCH] Harrison/update regex (#1534) Co-authored-by: Luis <57528712+LuisLechugaRuiz@users.noreply.github.com> --- langchain/agents/conversational/base.py | 2 +- langchain/agents/mrkl/base.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/langchain/agents/conversational/base.py b/langchain/agents/conversational/base.py index 16739881..e47329d2 100644 --- a/langchain/agents/conversational/base.py +++ b/langchain/agents/conversational/base.py @@ -78,7 +78,7 @@ class ConversationalAgent(Agent): def _extract_tool_and_input(self, llm_output: str) -> Optional[Tuple[str, str]]: if f"{self.ai_prefix}:" in llm_output: return self.ai_prefix, llm_output.split(f"{self.ai_prefix}:")[-1].strip() - regex = r"Action: (.*?)\nAction Input: (.*)" + regex = r"Action: (.*?)[\n]*Action Input: (.*)" match = re.search(regex, llm_output) if not match: raise ValueError(f"Could not parse LLM output: `{llm_output}`") diff --git a/langchain/agents/mrkl/base.py b/langchain/agents/mrkl/base.py index 2b0e190a..64f0ed71 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: (.*)" + regex = r"Action: (.*?)[\n]*Action Input: (.*)" match = re.search(regex, llm_output, re.DOTALL) if not match: raise ValueError(f"Could not parse LLM output: `{llm_output}`")