输出解析器
信息
语言模型输出文本。但在很多情况下,你可能希望获取比纯文本更结构化的信息。这时就需要使用输出解析器。
输出解析器是一种帮助结构化语言模型响应的结构体。一个输出解析器必须实现以下三个主要方法:
// OutputParser 是用于解析 LLM 调用输出的接口。
type OutputParser[T any] interface {
// Parse 解析 LLM 调用的输出。
Parse(text string) (T, error)
// ParseWithPrompt 使用提示信息解析 LLM 调用的输出。
ParseWithPrompt(text string, prompt PromptValue) (T, error)
// GetFormatInstructions 返回描述输出格式的字符串。
GetFormatInstructions() string
// Type 返回唯一标识此类解析器类型的字符串键值。
Type() string
}