Documentation
¶
Overview ¶
Package encoding provides a pluggable framework for encoding and decoding data in various formats (JSON, YAML, TOML, etc.) for agentic flows.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ModeDefault = ModeJSONSchema
ModeDefault is the default mode for the encoder. Allow to everride in apps
Functions ¶
func NewSimpleOutputParser ¶
func NewSimpleOutputParser() chatmodel.OutputParser[chatmodel.String]
Types ¶
type SchemaEncoder ¶
type SchemaEncoder interface {
Marshal(req any) ([]byte, error)
Unmarshal([]byte, any) error
// GetFormatInstructions returns the wrapped message with message schema for the prompt
GetFormatInstructions() string
}
func PredefinedSchemaEncoder ¶
func PredefinedSchemaEncoder(mode Mode, req any) (SchemaEncoder, error)
type SchemaStreamEncoder ¶
type SimpleOutputParser ¶
type SimpleOutputParser struct{}
Simple is an output parser that does nothing.
func (*SimpleOutputParser) GetFormatInstructions ¶
func (p *SimpleOutputParser) GetFormatInstructions() string
func (*SimpleOutputParser) Parse ¶
func (p *SimpleOutputParser) Parse(text string) (*chatmodel.String, error)
func (*SimpleOutputParser) Type ¶
func (p *SimpleOutputParser) Type() string
type TypedOutputParser ¶
type TypedOutputParser[T any] struct { // contains filtered or unexported fields }
TypedOutputParser parses output from an LLM into Go structs. By providing the NewDefined constructor with a struct, one or more TypeScript interfaces are generated to help LLMs format responses with the desired JSON structure.
func NewTypedOutputParser ¶
func NewTypedOutputParser[T any](sourceType T, mode Mode) (*TypedOutputParser[T], error)
NewTypedOutputParser creates an output parser that structures data according to a given schema, as defined by struct field names and types. Tagging the field with "json" will explicitly use that value as the field name. Tagging with "describe" will add a line comment for the LLM to understand how to generate data, helpful when the field's name is insufficient.
func (*TypedOutputParser[T]) GetFormatInstructions ¶
func (p *TypedOutputParser[T]) GetFormatInstructions() string
GetFormatInstructions returns a string describing the format of the output.
func (*TypedOutputParser[T]) Parse ¶
func (p *TypedOutputParser[T]) Parse(text string) (*T, error)
Parse parses the output of an LLM call.
func (*TypedOutputParser[T]) Type ¶
func (p *TypedOutputParser[T]) Type() string
Type returns the string type key uniquely identifying this class of parser
func (*TypedOutputParser[T]) WithValidation ¶
func (p *TypedOutputParser[T]) WithValidation(validate bool)