Skip to content

Commit a2eeaf3

Browse files
authored
strip whitespace (#680)
1 parent 2f57d18 commit a2eeaf3

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

langchain/agents/mrkl/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def get_action_and_input(llm_output: str) -> Tuple[str, str]:
4141
match = re.search(regex, llm_output)
4242
if not match:
4343
raise ValueError(f"Could not parse LLM output: `{llm_output}`")
44-
action = match.group(1)
44+
action = match.group(1).strip()
4545
action_input = match.group(2)
4646
return action, action_input.strip(" ").strip('"')
4747

tests/unit_tests/agents/test_mrkl.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ def test_get_action_and_input() -> None:
1919
assert action_input == "NBA"
2020

2121

22+
def test_get_action_and_input_whitespace() -> None:
23+
"""Test getting an action from text."""
24+
llm_output = "Thought: I need to search for NBA\nAction: Search \nAction Input: NBA"
25+
action, action_input = get_action_and_input(llm_output)
26+
assert action == "Search"
27+
assert action_input == "NBA"
28+
29+
2230
def test_get_final_answer() -> None:
2331
"""Test getting final answer."""
2432
llm_output = (

0 commit comments

Comments
 (0)