File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change 10
10
from langchain .llms .base import BaseLLM
11
11
from langchain .prompts import PromptTemplate
12
12
13
- FINAL_ANSWER_ACTION = "Final Answer: "
13
+ FINAL_ANSWER_ACTION = "Final Answer:"
14
14
15
15
16
16
class ChainConfig (NamedTuple ):
@@ -30,7 +30,7 @@ class ChainConfig(NamedTuple):
30
30
def get_action_and_input (llm_output : str ) -> Tuple [str , str ]:
31
31
"""Parse out the action and input from the LLM output."""
32
32
if FINAL_ANSWER_ACTION in llm_output :
33
- return "Final Answer" , llm_output .split (FINAL_ANSWER_ACTION )[- 1 ]
33
+ return "Final Answer" , llm_output .split (FINAL_ANSWER_ACTION )[- 1 ]. strip ()
34
34
regex = r"Action: (.*?)\nAction Input: (.*)"
35
35
match = re .search (regex , llm_output )
36
36
if not match :
Original file line number Diff line number Diff line change @@ -34,6 +34,21 @@ def test_get_final_answer() -> None:
34
34
assert action_input == "1994"
35
35
36
36
37
+ def test_get_final_answer_new_line () -> None :
38
+ """Test getting final answer."""
39
+ llm_output = (
40
+ "Thought: I need to search for NBA\n "
41
+ "Action: Search\n "
42
+ "Action Input: NBA\n "
43
+ "Observation: founded in 1994\n "
44
+ "Thought: I can now answer the question\n "
45
+ "Final Answer:\n 1994"
46
+ )
47
+ action , action_input = get_action_and_input (llm_output )
48
+ assert action == "Final Answer"
49
+ assert action_input == "1994"
50
+
51
+
37
52
def test_get_final_answer_multiline () -> None :
38
53
"""Test getting final answer that is multiline."""
39
54
llm_output = (
You can’t perform that action at this time.
0 commit comments