Skip to content

Commit

Permalink
revert bad json (#5370)
Browse files Browse the repository at this point in the history
  • Loading branch information
hwchase17 authored May 28, 2023
1 parent 9a5c9df commit b692797
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions langchain/agents/chat/output_parser.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json
from typing import Union

from langchain.agents.agent import AgentOutputParser
from langchain.agents.chat.prompt import FORMAT_INSTRUCTIONS
from langchain.output_parsers.json import parse_json_markdown
from langchain.schema import AgentAction, AgentFinish, OutputParserException

FINAL_ANSWER_ACTION = "Final Answer:"
Expand All @@ -18,7 +18,8 @@ def parse(self, text: str) -> Union[AgentAction, AgentFinish]:
{"output": text.split(FINAL_ANSWER_ACTION)[-1].strip()}, text
)
try:
response = parse_json_markdown(text)
action = text.split("```")[1]
response = json.loads(action.strip())
return AgentAction(response["action"], response["action_input"], text)

except Exception:
Expand Down

0 comments on commit b692797

Please sign in to comment.