Skip to content

Commit

Permalink
Get elements of ActionInput on newlines (langchain-ai#889)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sjwhitmore authored and zachschillaci27 committed Mar 8, 2023
1 parent abae3ce commit 7090625
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion langchain/agents/mrkl/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 7090625

Please sign in to comment.