janus.parsers.doc_parser#

Attributes#

log

Classes#

MultiDoc

Mixin to provide __str__, __repr__, and __pretty__ methods. See #884 for more details.

MultiDocumentationParser

Base class to parse the output of an LLM call.

ClozeDocumentationParser

Base class to parse the output of an LLM call.

Module Contents#

janus.parsers.doc_parser.log#
class janus.parsers.doc_parser.MultiDoc(**data)#

Bases: langchain_core.pydantic_v1.BaseModel

Mixin to provide __str__, __repr__, and __pretty__ methods. See #884 for more details.

__pretty__ is used by [devtools](https://python-devtools.helpmanual.io/) to provide human readable representations of objects.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Parameters:

data (Any) –

docstring: str#
example_usage: str#
pseudocode: str#
class janus.parsers.doc_parser.MultiDocumentationParser#

Bases: janus.parsers.parser.JanusParser, langchain.output_parsers.PydanticOutputParser

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"
block_name: str = ''#
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:

str

parse(text)#

Parse a single string model output into some structure.

Parameters:

text (str | langchain_core.messages.BaseMessage) – String output of a language model.

Returns:

Structured output.

Return type:

str

parse_combined_output(text)#

Parse the output text from the LLM when multiple inputs are combined.

Parameters:

text (str) – The output text from the LLM.

Returns:

A parsed version of the text.

Return type:

str

get_format_instructions()#

Get the format instructions for the parser.

Returns:

The format instructions for the LLM.

Return type:

str

class janus.parsers.doc_parser.ClozeDocumentationParser#

Bases: janus.parsers.parser.JanusParser

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"
expected_keys: set[str]#
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:

str

parse(text)#

Parse a single string model output into some structure.

Parameters:

text (str | langchain_core.messages.BaseMessage) – String output of a language model.

Returns:

Structured output.

Return type:

str

parse_combined_output(text)#

Parse the output text from the LLM when multiple inputs are combined.

Parameters:

text (str) – The output text from the LLM.

Returns:

A parsed version of the text.

Return type:

str

get_format_instructions()#

Get the format instructions for the parser.

Returns:

The format instructions for the LLM.

Return type:

str