diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml index af19545c80..f6bda66b9f 100644 --- a/.github/sync-repo-settings.yaml +++ b/.github/sync-repo-settings.yaml @@ -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)' \ No newline at end of file diff --git a/.kokoro/presubmit/unit_langchain_py38.cfg b/.kokoro/presubmit/unit_langchain_py38.cfg deleted file mode 100644 index ecfef00cdc..0000000000 --- a/.kokoro/presubmit/unit_langchain_py38.cfg +++ /dev/null @@ -1,13 +0,0 @@ -# Format: //devtools/kokoro/config/proto/build.proto - -# Run unit tests for LangChain on Python 3.8 -env_vars: { - key: "NOX_SESSION" - value: "unit_langchain-3.8" -} - -# Run unit tests in parallel, splitting up by file -env_vars: { - key: "PYTEST_ADDOPTS" - value: "-n=auto --dist=loadscope" -} diff --git a/noxfile.py b/noxfile.py index 48ca9b0e30..282461dc21 100644 --- a/noxfile.py +++ b/noxfile.py @@ -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", @@ -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. diff --git a/setup.py b/setup.py index 21db80de42..173266ebf7 100644 --- a/setup.py +++ b/setup.py @@ -123,6 +123,7 @@ genai_requires = ( "pydantic < 3", + "typing_extensions", "docstring_parser < 1", ) @@ -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 = [ diff --git a/testing/constraints-langchain.txt b/testing/constraints-langchain.txt index 2be9f67361..14ba97ad53 100644 --- a/testing/constraints-langchain.txt +++ b/testing/constraints-langchain.txt @@ -1,4 +1,3 @@ langchain langchain-core -langchain-google-vertexai -pydantic<2.10 \ No newline at end of file +langchain-google-vertexai \ No newline at end of file diff --git a/vertexai/generative_models/_generative_models.py b/vertexai/generative_models/_generative_models.py index 462861ca5b..cd845d6630 100644 --- a/vertexai/generative_models/_generative_models.py +++ b/vertexai/generative_models/_generative_models.py @@ -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: