Skip to content

Output parser

Bases: QueryComponent

输出解析器组件。

Source code in llama_index/core/output_parsers/base.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
class OutputParserComponent(QueryComponent):
    """输出解析器组件。"""

    output_parser: BaseOutputParser = Field(..., description="Output parser.")

    class Config:
        arbitrary_types_allowed = True

    def _run_component(self, **kwargs: Any) -> Dict[str, Any]:
        """运行组件。"""
        output = self.output_parser.parse(kwargs["input"])
        return {"output": output}

    async def _arun_component(self, **kwargs: Any) -> Dict[str, Any]:
        """运行组件。"""
        # NOTE: no native async for output parser
        return self._run_component(**kwargs)

    def _validate_component_inputs(self, input: Any) -> Any:
        """在运行组件期间验证组件输入。"""
        input["input"] = validate_and_convert_stringable(input["input"])
        return input

    def set_callback_manager(self, callback_manager: Any) -> None:
        """设置回调管理器。"""

    @property
    def input_keys(self) -> Any:
        """输入键。"""
        return InputKeys.from_keys({"input"})

    @property
    def output_keys(self) -> Any:
        """输出键。"""
        return OutputKeys.from_keys({"output"})

input_keys property #

input_keys: Any

输入键。

output_keys property #

output_keys: Any

输出键。

set_callback_manager #

set_callback_manager(callback_manager: Any) -> None

设置回调管理器。

Source code in llama_index/core/output_parsers/base.py
62
63
def set_callback_manager(self, callback_manager: Any) -> None:
    """设置回调管理器。"""