Skip to content

generated_chat_parser

Parses ChatML output from a LLM generation

This module provides a parser for the output of a chat conversation generated by a Large Language Model (LLM). The parser is designed to handle the output of a conversation between a human and an AI, where the AI’s responses are structured JSON objects. The parser will validate the output and return a normalized conversation object.

Warning

This module has been held over prior to the 2024 refactor and is out of date. Classes are marked as deprecated and will be removed in the future.

Attributes

Classes

ChatParserException

Bases: Exception

Raised when there is an error parsing chat output.

GeneratedChatOutputParser

Bases: BaseOutputParser[CanonicalChat]

Parses an output chat conversation. Leverages a simplified syntax so that we don’t have to worry about confusing the LLM with ChatML tags

Attributes

ignore_cannot_parse_threshold class-attribute instance-attribute
ignore_cannot_parse_threshold: int = -1
normalized_json_indent class-attribute instance-attribute
normalized_json_indent: int = 2
override_ai_role class-attribute instance-attribute
override_ai_role: Optional[str] = None
override_human_role class-attribute instance-attribute
override_human_role: Optional[str] = None
system_prompt class-attribute instance-attribute
system_prompt: str = ''
valid_ai_json_fields class-attribute instance-attribute
valid_ai_json_fields: List[str] = [
    "thoughts",
    "response",
    "speech_type",
]
valid_ai_roles class-attribute instance-attribute
valid_ai_roles: List[str] = ['AI']
valid_human_roles class-attribute instance-attribute
valid_human_roles: List[str] = ['Human']

Functions

get_format_instructions
get_format_instructions() -> str
parse
parse(text: str) -> CanonicalChat

NormalizedConversationTurn

Bases: BaseModel

Attributes

content instance-attribute
content: str
role instance-attribute
role: str
speaker instance-attribute
speaker: Literal['human', 'ai']

Functions