Skip to content

Index

BasePydanticProgram #

Bases: DispatcherSpanMixin, ABC, Generic[Model]

A base class for LLM-powered function that return a pydantic model.

Note: this interface is not yet stable.

Source code in llama-index-core/llama_index/core/types.py
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
class BasePydanticProgram(DispatcherSpanMixin, ABC, Generic[Model]):
    """A base class for LLM-powered function that return a pydantic model.

    Note: this interface is not yet stable.
    """

    @property
    @abstractmethod
    def output_cls(self) -> Type[Model]:
        pass

    @abstractmethod
    def __call__(self, *args: Any, **kwargs: Any) -> Model:
        pass

    async def acall(self, *args: Any, **kwargs: Any) -> Model:
        return self(*args, **kwargs)

    def stream_call(
        self, *args: Any, **kwargs: Any
    ) -> Generator[Union[Model, List[Model]], None, None]:
        raise NotImplementedError("stream_call is not supported by default.")

    async def astream_call(
        self, *args: Any, **kwargs: Any
    ) -> AsyncGenerator[Union[Model, List[Model]], None]:
        raise NotImplementedError("astream_call is not supported by default.")