Skip to content

Commit

Permalink
feat: Add typing alias for models and their parameters
Browse files Browse the repository at this point in the history
Testing for #4701

PiperOrigin-RevId: 704506046
  • Loading branch information
yeesian authored and copybara-github committed Dec 10, 2024
1 parent 1b2457f commit f91b8bb
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 18 deletions.
1 change: 0 additions & 1 deletion .github/sync-repo-settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ branchProtectionRules:
- 'Presubmit - Unit Tests Python 3.11'
- 'Presubmit - Unit Tests Python 3.12'
- 'Presubmit - Unit Tests Ray 2.9.3'
- 'Presubmit - Unit Tests LangChain (Python 3.8)'
- 'Presubmit - Unit Tests LangChain (Python 3.9)'
- 'Presubmit - Unit Tests LangChain (Python 3.10)'
- 'Presubmit - Unit Tests LangChain (Python 3.11)'
13 changes: 0 additions & 13 deletions .kokoro/presubmit/unit_langchain_py38.cfg

This file was deleted.

3 changes: 2 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
)

UNIT_TEST_PYTHON_VERSIONS = ["3.8", "3.9", "3.10", "3.11", "3.12"]
UNIT_TEST_LANGCHAIN_PYTHON_VERSIONS = ["3.9", "3.10", "3.11", "3.12"]
UNIT_TEST_STANDARD_DEPENDENCIES = [
"mock",
"asyncmock",
Expand Down Expand Up @@ -275,7 +276,7 @@ def unit_ray(session, ray):
)


@nox.session(python=UNIT_TEST_PYTHON_VERSIONS)
@nox.session(python=UNIT_TEST_LANGCHAIN_PYTHON_VERSIONS)
def unit_langchain(session):
# Install all test dependencies, then install this package in-place.

Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@

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

Expand All @@ -143,7 +144,8 @@
"google-cloud-trace < 2",
"opentelemetry-sdk < 2",
"opentelemetry-exporter-gcp-trace < 2",
"pydantic >= 2.6.3, < 2.10",
"pydantic >= 2.6.3, < 3",
"typing_extensions",
]

evaluation_extra_require = [
Expand Down
3 changes: 1 addition & 2 deletions testing/constraints-langchain.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
langchain
langchain-core
langchain-google-vertexai
pydantic<2.10
langchain-google-vertexai
45 changes: 45 additions & 0 deletions vertexai/generative_models/_generative_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,51 @@
],
]

try:
# For Pydantic to resolve the forward references inside these aliases.
from typing_extensions import TypeAliasType

PartsType = TypeAliasType(
"PartsType",
Union[
str,
"Image",
"Part",
List[Union[str, "Image", "Part"]],
],
)
ContentsType = TypeAliasType(
"ContentsType",
Union[
List["Content"],
List[ContentDict],
str,
"Image",
"Part",
List[Union[str, "Image", "Part"]],
],
)
GenerationConfigType = TypeAliasType(
"GenerationConfigType",
Union[
"GenerationConfig",
GenerationConfigDict,
],
)
SafetySettingsType = TypeAliasType(
"SafetySettingsType",
Union[
List["SafetySetting"],
Dict[
gapic_content_types.HarmCategory,
gapic_content_types.SafetySetting.HarmBlockThreshold,
],
],
)
except ImportError:
# Use existing definitions if typing_extensions is not available.
pass


def _reconcile_model_name(model_name: str, project: str, location: str) -> str:
"""Returns a model name that's one of the following:
Expand Down

0 comments on commit f91b8bb

Please sign in to comment.