Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

678 B
Raw Blame
from typing import Any

from pydantic import BaseModel

"""
We want to exclude null values from objects that make their way to the client.

Unfortunately there is no built-in way to do this in pydantic, so we need to override the default
dict method to do this.

From https://github.com/tiangolo/fastapi/discussions/8882#discussioncomment-5154541
"""


class BaseModelExcludeNull(BaseModel):
    def model_dump(self, *args, **kwargs) -> dict[str, Any]:
        """
        Override the default dict method to exclude None values in the response
        """
        kwargs.pop("exclude_none", None)
        return super().model_dump(*args, exclude_none=True, **kwargs)

    pass