Documentation ¶
Overview ¶
Package outputparser provides a set of output parsers to process structured or unstructured data from language models (LLMs).
The outputparser package includes the following parsers:
- BooleanParser: a parser that returns a boolean value based on string values assigned to true and false.
- Simple: a basic parser that returns the raw text as-is without any processing.
- Structured: a parser that expects a JSON-formatted response and returns it as a map[string]string while validating against a provided schema.
- Combining: a parser that combines the output of multiple parsers into a single parser.
- CommaSeparatedList: a parser that takes a string with comma-separated values and returns them as a string slice.
- RegexParser: a parser that takes a string, compiles it into a regular expression, and returns map[string]string of the regex groups.
- RegexDict: a parser that searches a string for values in a dictionary format, and returns a map[string]string of the keys and their associated value.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BooleanParser ¶
BooleanParser is an output parser used to parse the output of an llm as a boolean.
func NewBooleanParser ¶
func NewBooleanParser() BooleanParser
NewBooleanParser returns a new BooleanParser.
func (BooleanParser) GetFormatInstructions ¶
func (p BooleanParser) GetFormatInstructions() string
GetFormatInstructions returns instructions on the expected output format.
func (BooleanParser) Parse ¶
func (p BooleanParser) Parse(text string) (any, error)
Parse parses the output of an llm into a map of strings.
func (BooleanParser) ParseWithPrompt ¶
func (p BooleanParser) ParseWithPrompt(text string, _ schema.PromptValue) (any, error)
ParseWithPrompt does the same as Parse.
func (BooleanParser) Type ¶
func (p BooleanParser) Type() string
Type returns the type of the parser.
type Combining ¶
type Combining struct {
Parsers []schema.OutputParser[any]
}
Combining is a parser that combines multiple parsers into one.
func NewCombining ¶
func NewCombining(parsers []schema.OutputParser[any]) Combining
NewCombining creates a new combining parser.
func (Combining) GetFormatInstructions ¶
GetFormatInstructions returns the format instructions.
func (Combining) Parse ¶
Parse parses text delimited by two successive newline (`\n\n`) characters to the respective output parsers.
func (Combining) ParseWithPrompt ¶
Parse with prompts does the same as Parse.
type CommaSeparatedList ¶
type CommaSeparatedList struct{}
CommaSeparatedList is an output parser used to parse the output of an llm as a string slice. Splits in the output from the llm are done every comma.
func NewCommaSeparatedList ¶
func NewCommaSeparatedList() CommaSeparatedList
NewCommaSeparatedList creates a new CommaSeparatedList.
func (CommaSeparatedList) GetFormatInstructions ¶
func (p CommaSeparatedList) GetFormatInstructions() string
GetFormatInstructions returns the format instruction.
func (CommaSeparatedList) Parse ¶
func (p CommaSeparatedList) Parse(text string) ([]string, error)
Parse parses the output of an llm into a string slice.
func (CommaSeparatedList) ParseWithPrompt ¶
func (p CommaSeparatedList) ParseWithPrompt(text string, _ schema.PromptValue) ([]string, error)
Parse with prompts does the same as Parse.
func (CommaSeparatedList) Type ¶
func (p CommaSeparatedList) Type() string
type ParseError ¶
ParseError is the error type returned by output parsers.
func (ParseError) Error ¶
func (e ParseError) Error() string
type RegexDict ¶
type RegexDict struct { // OutputKeyToFormat is a map which has a key that represents an identifier for the regex, // and a value to search for as a key in the parsed text. OutputKeyToFormat map[string]string // NoUpdateValue is a string that prevents assignment to parsed outputs map when matched. NoUpdateValue string }
RegexDict is an output parser used to parse the output of an llm as a map.
func NewRegexDict ¶
NewRegexDict returns a new RegexDict.
func (RegexDict) GetFormatInstructions ¶
GetFormatInstructions returns instructions on the expected output format.
func (RegexDict) ParseWithPrompt ¶
ParseWithPrompt does the same as Parse.
type RegexParser ¶
RegexParser is an output parser used to parse the output of an llm as a map.
func NewRegexParser ¶
func NewRegexParser(expressionStr string) RegexParser
NewRegexParser returns a new RegexParser.
func (RegexParser) GetFormatInstructions ¶
func (p RegexParser) GetFormatInstructions() string
GetFormatInstructions returns instructions on the expected output format.
func (RegexParser) Parse ¶
func (p RegexParser) Parse(text string) (any, error)
Parse parses the output of an llm into a map of strings.
func (RegexParser) ParseWithPrompt ¶
func (p RegexParser) ParseWithPrompt(text string, _ schema.PromptValue) (any, error)
ParseWithPrompt does the same as Parse.
type ResponseSchema ¶
ResponseSchema is struct used in the structured output parser to describe how the llm should format its response. Name is a key in the parsed output map. Description is a description of what the value should contain.
type Simple ¶
type Simple struct{}
Simple is an output parser that does nothing.
func (Simple) GetFormatInstructions ¶
func (Simple) ParseWithPrompt ¶
type Structured ¶
type Structured struct {
ResponseSchemas []ResponseSchema
}
Structured is an output parser that parses the output of an llm into key value pairs. The name and description of what values the output of the llm should contain is stored in a list of response schema.
func NewStructured ¶
func NewStructured(schema []ResponseSchema) Structured
NewStructured is a function that creates a new structured output parser from a list of response schemas.
func (Structured) GetFormatInstructions ¶
func (p Structured) GetFormatInstructions() string
GetFormatInstructions returns a string explaining how the llm should format its response.
func (Structured) ParseWithPrompt ¶
func (p Structured) ParseWithPrompt(text string, _ schema.PromptValue) (any, error)
ParseWithPrompt does the same as Parse.
func (Structured) Type ¶
func (p Structured) Type() string
Type returns the type of the output parser.