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
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
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.")