输出解析器
¥Output parsers
此处的信息指的是解析器,它从模型中获取文本输出,并尝试将其解析为更结构化的表示形式。越来越多的模型支持函数(或工具)调用,它可以自动处理此类问题。建议使用函数/工具调用,而不是输出解析。请参阅 此处 的文档。
¥The information here refers to parsers that take a text output from a model try to parse it into a more structured representation. More and more models are supporting function (or tool) calling, which handles this automatically. It is recommended to use function/tool calling rather than output parsing. See documentation for that here.
输出解析器负责获取模型的输出并将其转换为更适合下游任务的格式。当你使用 LLM 生成结构化数据,或规范化聊天模型和 LLM 的输出时,此功能非常有用。
¥Output parsers are responsible for taking the output of a model and transforming it to a more suitable format for downstream tasks. Useful when you are using LLMs to generate structured data, or to normalize output from chat models and LLMs.
LangChain 拥有多种不同类型的输出解析器。这是 LangChain 支持的输出解析器列表。下表包含各种信息:
¥LangChain has lots of different types of output parsers. This is a list of output parsers LangChain supports. The table below has various pieces of information:
名称:输出解析器的名称
¥Name: The name of the output parser
支持流式传输:输出解析器是否支持流式传输。
¥Supports Streaming: Whether the output parser supports streaming.
包含格式化说明:输出解析器是否具有格式指令。这通常是可用的,除非 (a) 所需的模式未在提示中指定,而是在其他参数中指定(例如 OpenAI 函数调用),或者 (b) 当 OutputParser 封装另一个 OutputParser 时。
¥Has Format Instructions: Whether the output parser has format instructions. This is generally available except when (a) the desired schema is not specified in the prompt but rather in other parameters (like OpenAI function calling), or (b) when the OutputParser wraps another OutputParser.
调用 LLM:此输出解析器本身是否调用 LLM。这通常仅由尝试纠正格式错误的输出的输出解析器完成。
¥Calls LLM: Whether this output parser itself calls an LLM. This is usually only done by output parsers that attempt to correct misformatted output.
输入类型:预期输入类型。大多数输出解析器可以同时处理字符串和消息,但有些(例如 OpenAI Functions)需要带有特定 kwargs 的消息。
¥Input Type: Expected input type. Most output parsers work on both strings and messages, but some (like OpenAI Functions) need a message with specific kwargs.
输出类型:解析器返回对象的输出类型。
¥Output Type: The output type of the object returned by the parser.
描述:我们对此输出解析器及其使用时机的注释。
¥Description: Our commentary on this output parser and when to use it.
Name | Supports Streaming | Has Format Instructions | Calls LLM | Input Type | Output Type | Description |
---|---|---|---|---|---|---|
JSON | ✅ | ✅ | string | Message | JSON object | Returns a JSON object as specified. Probably the most reliable output parser for getting structured data that does NOT use function calling. | |
XML | ✅ | ✅ | string | Message | object | Returns a object of tags. Use when XML output is needed. Use with models that are good at writing XML (like Anthropic's). | |
CSV | ✅ | ✅ | string | Message | Array<string> | Returns a list of comma separated values. | |
OutputFixing | ✅ | string | Message | Wraps another output parser. If that output parser errors, then this will pass the error message and the bad output to an LLM and ask it to fix the output. | |||
Datetime | ✅ | string | Message | Date | Parses response into a datetime string. | ||
Structured | ✅ | string | Message | Record<string, string> | An output parser that returns structured information. It is less powerful than other output parsers since it only allows for fields to be strings. This can be useful when you are working with smaller LLMs. |
有关如何使用每个包的详细信息,请在相应的组件文档部分(例如 相关操作指南)中查找其页面。
¥For specifics on how to use output parsers, see the relevant how-to guides here.