from langchain.schema import AgentAction, AgentFinish
def parse_output(message: str):
FINAL_ANSWER_ACTION = ""
includes_answer = FINAL_ANSWER_ACTION in message
if includes_answer:
answer = message.split(FINAL_ANSWER_ACTION)[1].strip()
if "" in answer:
answer = answer.split("")[0].strip()
return AgentFinish(return_values={"output": answer}, log=message)
elif "" in message:
tool, tool_input = message.split("")
_tool = tool.split("")[1]
_tool_input = tool_input.split("")[1]
if "" in _tool_input:
_tool_input = _tool_input.split("")[0]
return AgentAction(tool=_tool, tool_input=_tool_input, log=message)