|
| 1 | +# Copyright 2025 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# |
| 15 | + |
| 16 | +from typing import Optional, Union |
| 17 | + |
| 18 | +import google.auth |
| 19 | +from google.genai import client |
| 20 | +from google.genai import types |
| 21 | +from .evals import Evals |
| 22 | +from .evals import AsyncEvals |
| 23 | + |
| 24 | + |
| 25 | +class AsyncClient: |
| 26 | + """Async Client for the GenAI SDK.""" |
| 27 | + |
| 28 | + def __init__(self, api_client: client.Client): |
| 29 | + self._api_client = api_client |
| 30 | + self._aio = AsyncClient(self._api_client) |
| 31 | + self._evals = AsyncEvals(self._api_client) |
| 32 | + |
| 33 | + @property |
| 34 | + def evals(self) -> AsyncEvals: |
| 35 | + return self._evals |
| 36 | + |
| 37 | + |
| 38 | +class Client: |
| 39 | + """Client for the GenAI SDK. |
| 40 | +
|
| 41 | + Use this client to interact with Vertex-specific Gemini features. |
| 42 | + """ |
| 43 | + |
| 44 | + def __init__( |
| 45 | + self, |
| 46 | + *, |
| 47 | + credentials: Optional[google.auth.credentials.Credentials] = None, |
| 48 | + project: Optional[str] = None, |
| 49 | + location: Optional[str] = None, |
| 50 | + debug_config: Optional[client.DebugConfig] = None, |
| 51 | + http_options: Optional[Union[types.HttpOptions, types.HttpOptionsDict]] = None, |
| 52 | + ): |
| 53 | + """Initializes the client. |
| 54 | +
|
| 55 | + Args: |
| 56 | + credentials (google.auth.credentials.Credentials): The credentials to use |
| 57 | + for authentication when calling the Vertex AI APIs. Credentials can be |
| 58 | + obtained from environment variables and default credentials. For more |
| 59 | + information, see `Set up Application Default Credentials |
| 60 | + <https://cloud.google.com/docs/authentication/provide-credentials-adc>`_. |
| 61 | + project (str): The `Google Cloud project ID |
| 62 | + <https://cloud.google.com/vertex-ai/docs/start/cloud-environment>`_ to |
| 63 | + use for quota. Can be obtained from environment variables (for example, |
| 64 | + ``GOOGLE_CLOUD_PROJECT``). |
| 65 | + location (str): The `location |
| 66 | + <https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations>`_ |
| 67 | + to send API requests to (for example, ``us-central1``). Can be obtained |
| 68 | + from environment variables. |
| 69 | + debug_config (DebugConfig): Config settings that control network behavior |
| 70 | + of the client. This is typically used when running test code. |
| 71 | + http_options (Union[HttpOptions, HttpOptionsDict]): Http options to use |
| 72 | + for the client. |
| 73 | + """ |
| 74 | + |
| 75 | + self._debug_config = debug_config or client.DebugConfig() |
| 76 | + if isinstance(http_options, dict): |
| 77 | + http_options = types.HttpOptions(**http_options) |
| 78 | + |
| 79 | + self._api_client = client.Client._get_api_client( |
| 80 | + vertexai=True, |
| 81 | + credentials=credentials, |
| 82 | + project=project, |
| 83 | + location=location, |
| 84 | + debug_config=self._debug_config, |
| 85 | + http_options=http_options, |
| 86 | + ) |
| 87 | + |
| 88 | + self._evals = Evals(self._api_client) |
| 89 | + |
| 90 | + @property |
| 91 | + def evals(self) -> Evals: |
| 92 | + return self._evals |
0 commit comments