diff --git a/pydantic_ai_slim/pydantic_ai/providers/google.py b/pydantic_ai_slim/pydantic_ai/providers/google.py index d0de4bcc4f..4b1c10bbc8 100644 --- a/pydantic_ai_slim/pydantic_ai/providers/google.py +++ b/pydantic_ai_slim/pydantic_ai/providers/google.py @@ -13,8 +13,7 @@ try: from google.auth.credentials import Credentials - from google.genai._api_client import BaseApiClient - from google.genai.client import Client, DebugConfig + from google.genai.client import Client from google.genai.types import HttpOptions except ImportError as _import_error: raise ImportError( @@ -115,8 +114,6 @@ def __init__( base_url=base_url, headers={'User-Agent': get_user_agent()}, httpx_async_client=http_client, - # TODO: Remove once https://github.com/googleapis/python-genai/issues/1565 is solved. - async_client_args={'transport': httpx.AsyncHTTPTransport()}, ) if not vertexai: if api_key is None: @@ -124,7 +121,7 @@ def __init__( 'Set the `GOOGLE_API_KEY` environment variable or pass it via `GoogleProvider(api_key=...)`' 'to use the Google Generative Language API.' ) - self._client = _SafelyClosingClient(vertexai=False, api_key=api_key, http_options=http_options) + self._client = Client(vertexai=False, api_key=api_key, http_options=http_options) else: if vertex_ai_args_used: api_key = None @@ -138,7 +135,7 @@ def __init__( # For more details, check: https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#available-regions location = location or os.getenv('GOOGLE_CLOUD_LOCATION') or 'us-central1' - self._client = _SafelyClosingClient( + self._client = Client( vertexai=True, api_key=api_key, project=project, @@ -184,40 +181,3 @@ def __init__( """Regions available for Vertex AI. More details [here](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#genai-locations). """ - - -class _SafelyClosingClient(Client): - @staticmethod - def _get_api_client( - vertexai: bool | None = None, - api_key: str | None = None, - credentials: Credentials | None = None, - project: str | None = None, - location: str | None = None, - debug_config: DebugConfig | None = None, - http_options: HttpOptions | None = None, - ) -> BaseApiClient: - return _NonClosingApiClient( - vertexai=vertexai, - api_key=api_key, - credentials=credentials, - project=project, - location=location, - http_options=http_options, - ) - - def close(self) -> None: - # This is called from `Client.__del__`, even if `Client.__init__` raised an error before `self._api_client` is set, which would raise an `AttributeError` here. - # TODO: Remove once https://github.com/googleapis/python-genai/issues/1567 is solved. - try: - super().close() - except AttributeError: - pass - - -class _NonClosingApiClient(BaseApiClient): - async def aclose(self) -> None: - # The original implementation also calls `await self._async_httpx_client.aclose()`, but we don't want to close our `cached_async_http_client` or the one the user passed in. - # TODO: Remove once https://github.com/googleapis/python-genai/issues/1566 is solved. - if self._aiohttp_session: - await self._aiohttp_session.close() # pragma: no cover diff --git a/pydantic_ai_slim/pyproject.toml b/pydantic_ai_slim/pyproject.toml index a1f917295d..c1d84f21b3 100644 --- a/pydantic_ai_slim/pyproject.toml +++ b/pydantic_ai_slim/pyproject.toml @@ -70,7 +70,7 @@ logfire = ["logfire[httpx]>=3.14.1"] openai = ["openai>=1.107.2"] cohere = ["cohere>=5.18.0; platform_system != 'Emscripten'"] vertexai = ["google-auth>=2.36.0", "requests>=2.32.2"] -google = ["google-genai>=1.46.0"] +google = ["google-genai>=1.50.1"] anthropic = ["anthropic>=0.70.0"] groq = ["groq>=0.25.0"] mistral = ["mistralai>=1.9.10"] diff --git a/uv.lock b/uv.lock index d8e9d5d31b..1e5612c491 100644 --- a/uv.lock +++ b/uv.lock @@ -1996,7 +1996,7 @@ wheels = [ [[package]] name = "google-genai" -version = "1.46.0" +version = "1.50.1" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "anyio" }, @@ -2008,9 +2008,9 @@ dependencies = [ { name = "typing-extensions" }, { name = "websockets" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/c7/2d/d5907af6a46fb0b660291a09bb62f9cbc1365899f7d64a74e7d8d2e056c2/google_genai-1.46.0.tar.gz", hash = "sha256:6824c31149fe3b1c7285b25f79b924c5f89fd52466f62e30f76954f8104fe3a7", size = 239561, upload-time = "2025-10-21T22:55:04.241Z" } +sdist = { url = "https://files.pythonhosted.org/packages/09/74/1382f655a8c24adc2811f113018ff2b3884f333284ba9bff5c57f8dbcbba/google_genai-1.50.1.tar.gz", hash = "sha256:8f0d95b1b165df71e6a7e1c0d0cadb5fad30f913f42c6b131b9ebb504eec0e5f", size = 254693, upload-time = "2025-11-13T23:17:22.526Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/db/79/8993ec6cbf56e5c8f88c165380e55de34ec74f7b928bc302ff5c370f9c4e/google_genai-1.46.0-py3-none-any.whl", hash = "sha256:879c4a260d630db0dcedb5cc84a9d7b47acd29e43e9dc63541b511b757ea7296", size = 239445, upload-time = "2025-10-21T22:55:03.072Z" }, + { url = "https://files.pythonhosted.org/packages/30/6b/78a7588d9a4f6c8c8ed326a32385d0566a3262c91c3f7a005e4231207894/google_genai-1.50.1-py3-none-any.whl", hash = "sha256:15ae694b080269c53d325dcce94622f33e94cf81bd2123f029ab77e6b8f09eab", size = 257324, upload-time = "2025-11-13T23:17:21.259Z" }, ] [[package]] @@ -5632,7 +5632,7 @@ requires-dist = [ { name = "fastmcp", marker = "extra == 'fastmcp'", specifier = ">=2.12.0" }, { name = "genai-prices", specifier = ">=0.0.35" }, { name = "google-auth", marker = "extra == 'vertexai'", specifier = ">=2.36.0" }, - { name = "google-genai", marker = "extra == 'google'", specifier = ">=1.46.0" }, + { name = "google-genai", marker = "extra == 'google'", specifier = ">=1.50.1" }, { name = "griffe", specifier = ">=1.3.2" }, { name = "groq", marker = "extra == 'groq'", specifier = ">=0.25.0" }, { name = "httpx", specifier = ">=0.27" },