mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-27 08:58:48 +00:00
revert bad json (#5370)
This commit is contained in:
parent
9a5c9df809
commit
b6927970f1
@ -1,8 +1,8 @@
|
|||||||
|
import json
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from langchain.agents.agent import AgentOutputParser
|
from langchain.agents.agent import AgentOutputParser
|
||||||
from langchain.agents.chat.prompt import FORMAT_INSTRUCTIONS
|
from langchain.agents.chat.prompt import FORMAT_INSTRUCTIONS
|
||||||
from langchain.output_parsers.json import parse_json_markdown
|
|
||||||
from langchain.schema import AgentAction, AgentFinish, OutputParserException
|
from langchain.schema import AgentAction, AgentFinish, OutputParserException
|
||||||
|
|
||||||
FINAL_ANSWER_ACTION = "Final Answer:"
|
FINAL_ANSWER_ACTION = "Final Answer:"
|
||||||
@ -18,7 +18,8 @@ class ChatOutputParser(AgentOutputParser):
|
|||||||
{"output": text.split(FINAL_ANSWER_ACTION)[-1].strip()}, text
|
{"output": text.split(FINAL_ANSWER_ACTION)[-1].strip()}, text
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
response = parse_json_markdown(text)
|
action = text.split("```")[1]
|
||||||
|
response = json.loads(action.strip())
|
||||||
return AgentAction(response["action"], response["action_input"], text)
|
return AgentAction(response["action"], response["action_input"], text)
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
|
Loading…
Reference in New Issue
Block a user