Skip to content

ModelGenerator

🛈 DocStrings

Fill a pydantic model interactively; prefer :func:promptantic.fill.

The constructor's options (style, show_progress, ...) belonged to the old prompt-per-type implementation and are accepted but ignored.

Source code in src/promptantic/generator.py
class ModelGenerator:
    """Fill a pydantic model interactively; prefer :func:`promptantic.fill`.

    The constructor's options (``style``, ``show_progress``, ...) belonged to the old
    prompt-per-type implementation and are accepted but ignored.
    """

    def __init__(self, *_args: Any, **_kwargs: Any) -> None:
        pass

    @overload
    async def apopulate[M: BaseModel](self, model: type[M]) -> M: ...
    @overload
    async def apopulate[M: BaseModel](self, model: M) -> M: ...
    async def apopulate[M: BaseModel](self, model: type[M] | M) -> M:
        """An instance of ``model``; given an instance, its values are the starting values."""
        if isinstance(model, BaseModel):
            return await fill(type(model), initial=initial_values(model))
        return await fill(model)

    @overload
    def populate[M: BaseModel](self, model: type[M]) -> M: ...
    @overload
    def populate[M: BaseModel](self, model: M) -> M: ...
    def populate[M: BaseModel](self, model: type[M] | M) -> M:
        """Like :meth:`apopulate`, for code that isn't async."""
        return asyncio.run(self.apopulate(model))

apopulate async

apopulate(model: type[M]) -> M
apopulate(model: M) -> M
apopulate(model: type[M] | M) -> M

An instance of model; given an instance, its values are the starting values.

Source code in src/promptantic/generator.py
async def apopulate[M: BaseModel](self, model: type[M] | M) -> M:
    """An instance of ``model``; given an instance, its values are the starting values."""
    if isinstance(model, BaseModel):
        return await fill(type(model), initial=initial_values(model))
    return await fill(model)

populate

populate(model: type[M]) -> M
populate(model: M) -> M
populate(model: type[M] | M) -> M

Like :meth:apopulate, for code that isn't async.

Source code in src/promptantic/generator.py
def populate[M: BaseModel](self, model: type[M] | M) -> M:
    """Like :meth:`apopulate`, for code that isn't async."""
    return asyncio.run(self.apopulate(model))

:fa-brands-github: Show source on GitHub