janus.parsers.parser#
Attributes#
Exceptions#
Exception that output parsers should raise to signify a parsing error. |
Classes#
Base class to parse the output of an LLM call. |
|
Base class to parse the output of an LLM call. |
Module Contents#
- janus.parsers.parser.log#
- class janus.parsers.parser.JanusParser#
Bases:
langchain.schema.output_parser.BaseOutputParser
[str
]Base class to parse the output of an LLM call.
Output parsers help structure language model responses.
Example
class BooleanOutputParser(BaseOutputParser[bool]): true_val: str = "YES" false_val: str = "NO" def parse(self, text: str) -> bool: cleaned_text = text.strip().upper() if cleaned_text not in (self.true_val.upper(), self.false_val.upper()): raise OutputParserException( f"BooleanOutputParser expected output value to either be " f"{self.true_val} or {self.false_val} (case-insensitive). " f"Received {cleaned_text}." ) return cleaned_text == self.true_val.upper() @property def _type(self) -> str: return "boolean_output_parser"
- parse_input(block)#
Parse the input block into raw string input ready to be passed to an LLM. Also perform any processing or saving of metadata.
- Parameters:
block (janus.language.block.CodeBlock) – The CodeBlock to be processed
- Returns:
A parsed version of the input text
- Return type:
- parse_combined_output(text)#
Parse the output text from the LLM when multiple inputs are combined
- parse_into_block(text, block)#
- Parameters:
text (str | langchain_core.messages.BaseMessage) –
block (janus.language.block.CodeBlock) –
- class janus.parsers.parser.GenericParser#
Bases:
JanusParser
,langchain_core.output_parsers.StrOutputParser
Base class to parse the output of an LLM call.
Output parsers help structure language model responses.
Example
class BooleanOutputParser(BaseOutputParser[bool]): true_val: str = "YES" false_val: str = "NO" def parse(self, text: str) -> bool: cleaned_text = text.strip().upper() if cleaned_text not in (self.true_val.upper(), self.false_val.upper()): raise OutputParserException( f"BooleanOutputParser expected output value to either be " f"{self.true_val} or {self.false_val} (case-insensitive). " f"Received {cleaned_text}." ) return cleaned_text == self.true_val.upper() @property def _type(self) -> str: return "boolean_output_parser"
- parse(text)#
Parse a single string model output into some structure.
- exception janus.parsers.parser.JanusParserException(unparsed_output, *args, **kwargs)#
Bases:
langchain_core.exceptions.OutputParserException
Exception that output parsers should raise to signify a parsing error.
This exists to differentiate parsing errors from other code or execution errors that also may arise inside the output parser. OutputParserExceptions will be available to catch and handle in ways to fix the parsing error, while other errors will be raised.
- Parameters:
error – The error that’s being re-raised or an error message.
observation – String explanation of error which can be passed to a model to try and remediate the issue. Defaults to None.
llm_output – String model output which is error-ing. Defaults to None.
send_to_llm – Whether to send the observation and llm_output back to an Agent after an OutputParserException has been raised. This gives the underlying model driving the agent the context that the previous output was improperly structured, in the hopes that it will update the output to the correct format. Defaults to False.
Initialize self. See help(type(self)) for accurate signature.