|
|
|
@ -5,7 +5,7 @@ from typing import Union
|
|
|
|
|
|
|
|
|
|
from langchain.agents import AgentOutputParser
|
|
|
|
|
from langchain.agents.conversational_chat.prompt import FORMAT_INSTRUCTIONS
|
|
|
|
|
from langchain.schema import AgentAction, AgentFinish
|
|
|
|
|
from langchain.schema import AgentAction, AgentFinish, OutputParserException
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ConvoOutputParser(AgentOutputParser):
|
|
|
|
@ -13,6 +13,7 @@ class ConvoOutputParser(AgentOutputParser):
|
|
|
|
|
return FORMAT_INSTRUCTIONS
|
|
|
|
|
|
|
|
|
|
def parse(self, text: str) -> Union[AgentAction, AgentFinish]:
|
|
|
|
|
try:
|
|
|
|
|
cleaned_output = text.strip()
|
|
|
|
|
if "```json" in cleaned_output:
|
|
|
|
|
_, cleaned_output = cleaned_output.split("```json")
|
|
|
|
@ -31,6 +32,8 @@ class ConvoOutputParser(AgentOutputParser):
|
|
|
|
|
return AgentFinish({"output": action_input}, text)
|
|
|
|
|
else:
|
|
|
|
|
return AgentAction(action, action_input, text)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
raise OutputParserException(f"Could not parse LLM output: {text}") from e
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def _type(self) -> str:
|
|
|
|
|