Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use TypeAliasType to define aliases #4701

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@

genai_requires = (
"pydantic < 3",
"typing_extensions > 4.6.0",
"docstring_parser < 1",
)

Expand Down
62 changes: 38 additions & 24 deletions vertexai/generative_models/_generative_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
overload,
TYPE_CHECKING,
)
from typing_extensions import TypeAliasType

from google.cloud.aiplatform import initializer as aiplatform_initializer
from google.cloud.aiplatform import utils as aiplatform_utils
Expand Down Expand Up @@ -86,36 +87,49 @@


# These type defnitions are expanded to help the user see all the types
PartsType = Union[
str,
"Image",
"Part",
List[Union[str, "Image", "Part"]],
]
PartsType = TypeAliasType(
"PartsType",
Union[
str,
"Image",
"Part",
List[Union[str, "Image", "Part"]],
],
)


ContentDict = Dict[str, Any]
ContentsType = Union[
List["Content"],
List[ContentDict],
str,
"Image",
"Part",
List[Union[str, "Image", "Part"]],
]
ContentsType = TypeAliasType(
"ContentsType",
Union[
List["Content"],
List[ContentDict],
str,
"Image",
"Part",
List[Union[str, "Image", "Part"]],
],
)

GenerationConfigDict = Dict[str, Any]
GenerationConfigType = Union[
"GenerationConfig",
GenerationConfigDict,
]
GenerationConfigType = TypeAliasType(
"GenerationConfigType",
Union[
"GenerationConfig",
GenerationConfigDict,
],
)

SafetySettingsType = Union[
List["SafetySetting"],
Dict[
gapic_content_types.HarmCategory,
gapic_content_types.SafetySetting.HarmBlockThreshold,
SafetySettingsType = TypeAliasType(
"SafetySettingsType",
Union[
List["SafetySetting"],
Dict[
gapic_content_types.HarmCategory,
gapic_content_types.SafetySetting.HarmBlockThreshold,
],
],
]
)


def _reconcile_model_name(model_name: str, project: str, location: str) -> str:
Expand Down