mirror of
https://github.com/hwchase17/langchain.git
synced 2025-05-13 19:17:16 +00:00
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.
This commit is contained in:
parent
1614c5f5fd
commit
32b11101d3
@ -40,7 +40,7 @@ def get_action_and_input(llm_output: str) -> Tuple[str, str]:
|
|||||||
if FINAL_ANSWER_ACTION in llm_output:
|
if FINAL_ANSWER_ACTION in llm_output:
|
||||||
return "Final Answer", llm_output.split(FINAL_ANSWER_ACTION)[-1].strip()
|
return "Final Answer", llm_output.split(FINAL_ANSWER_ACTION)[-1].strip()
|
||||||
regex = r"Action: (.*?)\nAction Input: (.*)"
|
regex = r"Action: (.*?)\nAction Input: (.*)"
|
||||||
match = re.search(regex, llm_output)
|
match = re.search(regex, llm_output, re.DOTALL)
|
||||||
if not match:
|
if not match:
|
||||||
raise ValueError(f"Could not parse LLM output: `{llm_output}`")
|
raise ValueError(f"Could not parse LLM output: `{llm_output}`")
|
||||||
action = match.group(1).strip()
|
action = match.group(1).strip()
|
||||||
|
Loading…
Reference in New Issue
Block a user