[docs]classSelfAskOutputParser(AgentOutputParser):"""Parses self-ask style LLM calls. Expects output to be in one of two formats. If the output signals that an action should be taken, should be in the below format. This will result in an AgentAction being returned. ``` Thoughts go here... Follow up: what is the temperature in SF? ``` If the output signals that a final answer should be given, should be in the below format. This will result in an AgentFinish being returned. ``` Thoughts go here... So the final answer is: The temperature is 100 degrees ``` """followups:Sequence[str]=("Follow up:","Followup:")finish_string:str="So the final answer is: "
[docs]defparse(self,text:str)->Union[AgentAction,AgentFinish]:last_line=text.split("\n")[-1]ifnotany([followinlast_lineforfollowinself.followups]):ifself.finish_stringnotinlast_line:raiseOutputParserException(f"Could not parse output: {text}")returnAgentFinish({"output":last_line[len(self.finish_string):]},text)after_colon=text.split(":")[-1].strip()returnAgentAction("Intermediate Answer",after_colon,text)