koichi12 commited on
Commit
ef732b7
·
verified ·
1 Parent(s): 441a1f2

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/__pycache__/__init__.cpython-311.pyc +0 -0
  2. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/cache_service/__pycache__/__init__.cpython-311.pyc +0 -0
  3. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/discuss_service/__init__.py +22 -0
  4. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/discuss_service/async_client.py +740 -0
  5. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/discuss_service/client.py +1128 -0
  6. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/discuss_service/transports/grpc.py +431 -0
  7. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/__init__.py +22 -0
  8. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/__pycache__/__init__.cpython-311.pyc +0 -0
  9. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/__pycache__/async_client.cpython-311.pyc +0 -0
  10. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/__pycache__/client.cpython-311.pyc +0 -0
  11. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/__pycache__/pagers.cpython-311.pyc +0 -0
  12. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/async_client.py +1261 -0
  13. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/client.py +1646 -0
  14. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/pagers.py +353 -0
  15. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/transports/__init__.py +36 -0
  16. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/transports/__pycache__/__init__.cpython-311.pyc +0 -0
  17. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/transports/__pycache__/base.cpython-311.pyc +0 -0
  18. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/transports/__pycache__/grpc.cpython-311.pyc +0 -0
  19. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/transports/__pycache__/grpc_asyncio.cpython-311.pyc +0 -0
  20. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/transports/__pycache__/rest.cpython-311.pyc +0 -0
  21. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/transports/__pycache__/rest_base.cpython-311.pyc +0 -0
  22. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/transports/base.py +353 -0
  23. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/transports/grpc.py +582 -0
  24. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/transports/grpc_asyncio.py +718 -0
  25. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/transports/rest.py +1819 -0
  26. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/transports/rest_base.py +476 -0
  27. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/__init__.py +22 -0
  28. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/__pycache__/__init__.cpython-311.pyc +0 -0
  29. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/__pycache__/async_client.cpython-311.pyc +0 -0
  30. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/__pycache__/client.cpython-311.pyc +0 -0
  31. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/__pycache__/pagers.cpython-311.pyc +0 -0
  32. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/async_client.py +1150 -0
  33. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/client.py +1532 -0
  34. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/pagers.py +197 -0
  35. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/transports/__init__.py +36 -0
  36. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/transports/__pycache__/__init__.cpython-311.pyc +0 -0
  37. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/transports/__pycache__/base.cpython-311.pyc +0 -0
  38. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/transports/__pycache__/grpc.cpython-311.pyc +0 -0
  39. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/transports/__pycache__/grpc_asyncio.cpython-311.pyc +0 -0
  40. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/transports/__pycache__/rest.cpython-311.pyc +0 -0
  41. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/transports/__pycache__/rest_base.cpython-311.pyc +0 -0
  42. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/transports/base.py +317 -0
  43. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/transports/grpc.py +541 -0
  44. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/transports/grpc_asyncio.py +649 -0
  45. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/transports/rest.py +1671 -0
  46. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/transports/rest_base.py +493 -0
  47. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/prediction_service/__init__.py +22 -0
  48. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/prediction_service/__pycache__/__init__.cpython-311.pyc +0 -0
  49. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/prediction_service/__pycache__/async_client.cpython-311.pyc +0 -0
  50. .venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/prediction_service/__pycache__/client.cpython-311.pyc +0 -0
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (217 Bytes). View file
 
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/cache_service/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (402 Bytes). View file
 
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/discuss_service/__init__.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ from .async_client import DiscussServiceAsyncClient
17
+ from .client import DiscussServiceClient
18
+
19
+ __all__ = (
20
+ "DiscussServiceClient",
21
+ "DiscussServiceAsyncClient",
22
+ )
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/discuss_service/async_client.py ADDED
@@ -0,0 +1,740 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ from collections import OrderedDict
17
+ import logging as std_logging
18
+ import re
19
+ from typing import (
20
+ Callable,
21
+ Dict,
22
+ Mapping,
23
+ MutableMapping,
24
+ MutableSequence,
25
+ Optional,
26
+ Sequence,
27
+ Tuple,
28
+ Type,
29
+ Union,
30
+ )
31
+
32
+ from google.api_core import exceptions as core_exceptions
33
+ from google.api_core import gapic_v1
34
+ from google.api_core import retry_async as retries
35
+ from google.api_core.client_options import ClientOptions
36
+ from google.auth import credentials as ga_credentials # type: ignore
37
+ from google.oauth2 import service_account # type: ignore
38
+
39
+ from google.ai.generativelanguage_v1beta import gapic_version as package_version
40
+
41
+ try:
42
+ OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None]
43
+ except AttributeError: # pragma: NO COVER
44
+ OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore
45
+
46
+ from google.longrunning import operations_pb2 # type: ignore
47
+
48
+ from google.ai.generativelanguage_v1beta.types import discuss_service, safety
49
+
50
+ from .client import DiscussServiceClient
51
+ from .transports.base import DEFAULT_CLIENT_INFO, DiscussServiceTransport
52
+ from .transports.grpc_asyncio import DiscussServiceGrpcAsyncIOTransport
53
+
54
+ try:
55
+ from google.api_core import client_logging # type: ignore
56
+
57
+ CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
58
+ except ImportError: # pragma: NO COVER
59
+ CLIENT_LOGGING_SUPPORTED = False
60
+
61
+ _LOGGER = std_logging.getLogger(__name__)
62
+
63
+
64
+ class DiscussServiceAsyncClient:
65
+ """An API for using Generative Language Models (GLMs) in dialog
66
+ applications.
67
+ Also known as large language models (LLMs), this API provides
68
+ models that are trained for multi-turn dialog.
69
+ """
70
+
71
+ _client: DiscussServiceClient
72
+
73
+ # Copy defaults from the synchronous client for use here.
74
+ # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead.
75
+ DEFAULT_ENDPOINT = DiscussServiceClient.DEFAULT_ENDPOINT
76
+ DEFAULT_MTLS_ENDPOINT = DiscussServiceClient.DEFAULT_MTLS_ENDPOINT
77
+ _DEFAULT_ENDPOINT_TEMPLATE = DiscussServiceClient._DEFAULT_ENDPOINT_TEMPLATE
78
+ _DEFAULT_UNIVERSE = DiscussServiceClient._DEFAULT_UNIVERSE
79
+
80
+ model_path = staticmethod(DiscussServiceClient.model_path)
81
+ parse_model_path = staticmethod(DiscussServiceClient.parse_model_path)
82
+ common_billing_account_path = staticmethod(
83
+ DiscussServiceClient.common_billing_account_path
84
+ )
85
+ parse_common_billing_account_path = staticmethod(
86
+ DiscussServiceClient.parse_common_billing_account_path
87
+ )
88
+ common_folder_path = staticmethod(DiscussServiceClient.common_folder_path)
89
+ parse_common_folder_path = staticmethod(
90
+ DiscussServiceClient.parse_common_folder_path
91
+ )
92
+ common_organization_path = staticmethod(
93
+ DiscussServiceClient.common_organization_path
94
+ )
95
+ parse_common_organization_path = staticmethod(
96
+ DiscussServiceClient.parse_common_organization_path
97
+ )
98
+ common_project_path = staticmethod(DiscussServiceClient.common_project_path)
99
+ parse_common_project_path = staticmethod(
100
+ DiscussServiceClient.parse_common_project_path
101
+ )
102
+ common_location_path = staticmethod(DiscussServiceClient.common_location_path)
103
+ parse_common_location_path = staticmethod(
104
+ DiscussServiceClient.parse_common_location_path
105
+ )
106
+
107
+ @classmethod
108
+ def from_service_account_info(cls, info: dict, *args, **kwargs):
109
+ """Creates an instance of this client using the provided credentials
110
+ info.
111
+
112
+ Args:
113
+ info (dict): The service account private key info.
114
+ args: Additional arguments to pass to the constructor.
115
+ kwargs: Additional arguments to pass to the constructor.
116
+
117
+ Returns:
118
+ DiscussServiceAsyncClient: The constructed client.
119
+ """
120
+ return DiscussServiceClient.from_service_account_info.__func__(DiscussServiceAsyncClient, info, *args, **kwargs) # type: ignore
121
+
122
+ @classmethod
123
+ def from_service_account_file(cls, filename: str, *args, **kwargs):
124
+ """Creates an instance of this client using the provided credentials
125
+ file.
126
+
127
+ Args:
128
+ filename (str): The path to the service account private key json
129
+ file.
130
+ args: Additional arguments to pass to the constructor.
131
+ kwargs: Additional arguments to pass to the constructor.
132
+
133
+ Returns:
134
+ DiscussServiceAsyncClient: The constructed client.
135
+ """
136
+ return DiscussServiceClient.from_service_account_file.__func__(DiscussServiceAsyncClient, filename, *args, **kwargs) # type: ignore
137
+
138
+ from_service_account_json = from_service_account_file
139
+
140
+ @classmethod
141
+ def get_mtls_endpoint_and_cert_source(
142
+ cls, client_options: Optional[ClientOptions] = None
143
+ ):
144
+ """Return the API endpoint and client cert source for mutual TLS.
145
+
146
+ The client cert source is determined in the following order:
147
+ (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
148
+ client cert source is None.
149
+ (2) if `client_options.client_cert_source` is provided, use the provided one; if the
150
+ default client cert source exists, use the default one; otherwise the client cert
151
+ source is None.
152
+
153
+ The API endpoint is determined in the following order:
154
+ (1) if `client_options.api_endpoint` if provided, use the provided one.
155
+ (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
156
+ default mTLS endpoint; if the environment variable is "never", use the default API
157
+ endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
158
+ use the default API endpoint.
159
+
160
+ More details can be found at https://google.aip.dev/auth/4114.
161
+
162
+ Args:
163
+ client_options (google.api_core.client_options.ClientOptions): Custom options for the
164
+ client. Only the `api_endpoint` and `client_cert_source` properties may be used
165
+ in this method.
166
+
167
+ Returns:
168
+ Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
169
+ client cert source to use.
170
+
171
+ Raises:
172
+ google.auth.exceptions.MutualTLSChannelError: If any errors happen.
173
+ """
174
+ return DiscussServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore
175
+
176
+ @property
177
+ def transport(self) -> DiscussServiceTransport:
178
+ """Returns the transport used by the client instance.
179
+
180
+ Returns:
181
+ DiscussServiceTransport: The transport used by the client instance.
182
+ """
183
+ return self._client.transport
184
+
185
+ @property
186
+ def api_endpoint(self):
187
+ """Return the API endpoint used by the client instance.
188
+
189
+ Returns:
190
+ str: The API endpoint used by the client instance.
191
+ """
192
+ return self._client._api_endpoint
193
+
194
+ @property
195
+ def universe_domain(self) -> str:
196
+ """Return the universe domain used by the client instance.
197
+
198
+ Returns:
199
+ str: The universe domain used
200
+ by the client instance.
201
+ """
202
+ return self._client._universe_domain
203
+
204
+ get_transport_class = DiscussServiceClient.get_transport_class
205
+
206
+ def __init__(
207
+ self,
208
+ *,
209
+ credentials: Optional[ga_credentials.Credentials] = None,
210
+ transport: Optional[
211
+ Union[str, DiscussServiceTransport, Callable[..., DiscussServiceTransport]]
212
+ ] = "grpc_asyncio",
213
+ client_options: Optional[ClientOptions] = None,
214
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
215
+ ) -> None:
216
+ """Instantiates the discuss service async client.
217
+
218
+ Args:
219
+ credentials (Optional[google.auth.credentials.Credentials]): The
220
+ authorization credentials to attach to requests. These
221
+ credentials identify the application to the service; if none
222
+ are specified, the client will attempt to ascertain the
223
+ credentials from the environment.
224
+ transport (Optional[Union[str,DiscussServiceTransport,Callable[..., DiscussServiceTransport]]]):
225
+ The transport to use, or a Callable that constructs and returns a new transport to use.
226
+ If a Callable is given, it will be called with the same set of initialization
227
+ arguments as used in the DiscussServiceTransport constructor.
228
+ If set to None, a transport is chosen automatically.
229
+ client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]):
230
+ Custom options for the client.
231
+
232
+ 1. The ``api_endpoint`` property can be used to override the
233
+ default endpoint provided by the client when ``transport`` is
234
+ not explicitly provided. Only if this property is not set and
235
+ ``transport`` was not explicitly provided, the endpoint is
236
+ determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment
237
+ variable, which have one of the following values:
238
+ "always" (always use the default mTLS endpoint), "never" (always
239
+ use the default regular endpoint) and "auto" (auto-switch to the
240
+ default mTLS endpoint if client certificate is present; this is
241
+ the default value).
242
+
243
+ 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
244
+ is "true", then the ``client_cert_source`` property can be used
245
+ to provide a client certificate for mTLS transport. If
246
+ not provided, the default SSL client certificate will be used if
247
+ present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
248
+ set, no client certificate will be used.
249
+
250
+ 3. The ``universe_domain`` property can be used to override the
251
+ default "googleapis.com" universe. Note that ``api_endpoint``
252
+ property still takes precedence; and ``universe_domain`` is
253
+ currently not supported for mTLS.
254
+
255
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
256
+ The client info used to send a user-agent string along with
257
+ API requests. If ``None``, then default info will be used.
258
+ Generally, you only need to set this if you're developing
259
+ your own client library.
260
+
261
+ Raises:
262
+ google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
263
+ creation failed for any reason.
264
+ """
265
+ self._client = DiscussServiceClient(
266
+ credentials=credentials,
267
+ transport=transport,
268
+ client_options=client_options,
269
+ client_info=client_info,
270
+ )
271
+
272
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
273
+ std_logging.DEBUG
274
+ ): # pragma: NO COVER
275
+ _LOGGER.debug(
276
+ "Created client `google.ai.generativelanguage_v1beta.DiscussServiceAsyncClient`.",
277
+ extra={
278
+ "serviceName": "google.ai.generativelanguage.v1beta.DiscussService",
279
+ "universeDomain": getattr(
280
+ self._client._transport._credentials, "universe_domain", ""
281
+ ),
282
+ "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}",
283
+ "credentialsInfo": getattr(
284
+ self.transport._credentials, "get_cred_info", lambda: None
285
+ )(),
286
+ }
287
+ if hasattr(self._client._transport, "_credentials")
288
+ else {
289
+ "serviceName": "google.ai.generativelanguage.v1beta.DiscussService",
290
+ "credentialsType": None,
291
+ },
292
+ )
293
+
294
+ async def generate_message(
295
+ self,
296
+ request: Optional[Union[discuss_service.GenerateMessageRequest, dict]] = None,
297
+ *,
298
+ model: Optional[str] = None,
299
+ prompt: Optional[discuss_service.MessagePrompt] = None,
300
+ temperature: Optional[float] = None,
301
+ candidate_count: Optional[int] = None,
302
+ top_p: Optional[float] = None,
303
+ top_k: Optional[int] = None,
304
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
305
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
306
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
307
+ ) -> discuss_service.GenerateMessageResponse:
308
+ r"""Generates a response from the model given an input
309
+ ``MessagePrompt``.
310
+
311
+ .. code-block:: python
312
+
313
+ # This snippet has been automatically generated and should be regarded as a
314
+ # code template only.
315
+ # It will require modifications to work:
316
+ # - It may require correct/in-range values for request initialization.
317
+ # - It may require specifying regional endpoints when creating the service
318
+ # client as shown in:
319
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
320
+ from google.ai import generativelanguage_v1beta
321
+
322
+ async def sample_generate_message():
323
+ # Create a client
324
+ client = generativelanguage_v1beta.DiscussServiceAsyncClient()
325
+
326
+ # Initialize request argument(s)
327
+ prompt = generativelanguage_v1beta.MessagePrompt()
328
+ prompt.messages.content = "content_value"
329
+
330
+ request = generativelanguage_v1beta.GenerateMessageRequest(
331
+ model="model_value",
332
+ prompt=prompt,
333
+ )
334
+
335
+ # Make the request
336
+ response = await client.generate_message(request=request)
337
+
338
+ # Handle the response
339
+ print(response)
340
+
341
+ Args:
342
+ request (Optional[Union[google.ai.generativelanguage_v1beta.types.GenerateMessageRequest, dict]]):
343
+ The request object. Request to generate a message
344
+ response from the model.
345
+ model (:class:`str`):
346
+ Required. The name of the model to use.
347
+
348
+ Format: ``name=models/{model}``.
349
+
350
+ This corresponds to the ``model`` field
351
+ on the ``request`` instance; if ``request`` is provided, this
352
+ should not be set.
353
+ prompt (:class:`google.ai.generativelanguage_v1beta.types.MessagePrompt`):
354
+ Required. The structured textual
355
+ input given to the model as a prompt.
356
+ Given a
357
+ prompt, the model will return what it
358
+ predicts is the next message in the
359
+ discussion.
360
+
361
+ This corresponds to the ``prompt`` field
362
+ on the ``request`` instance; if ``request`` is provided, this
363
+ should not be set.
364
+ temperature (:class:`float`):
365
+ Optional. Controls the randomness of the output.
366
+
367
+ Values can range over ``[0.0,1.0]``, inclusive. A value
368
+ closer to ``1.0`` will produce responses that are more
369
+ varied, while a value closer to ``0.0`` will typically
370
+ result in less surprising responses from the model.
371
+
372
+ This corresponds to the ``temperature`` field
373
+ on the ``request`` instance; if ``request`` is provided, this
374
+ should not be set.
375
+ candidate_count (:class:`int`):
376
+ Optional. The number of generated response messages to
377
+ return.
378
+
379
+ This value must be between ``[1, 8]``, inclusive. If
380
+ unset, this will default to ``1``.
381
+
382
+ This corresponds to the ``candidate_count`` field
383
+ on the ``request`` instance; if ``request`` is provided, this
384
+ should not be set.
385
+ top_p (:class:`float`):
386
+ Optional. The maximum cumulative probability of tokens
387
+ to consider when sampling.
388
+
389
+ The model uses combined Top-k and nucleus sampling.
390
+
391
+ Nucleus sampling considers the smallest set of tokens
392
+ whose probability sum is at least ``top_p``.
393
+
394
+ This corresponds to the ``top_p`` field
395
+ on the ``request`` instance; if ``request`` is provided, this
396
+ should not be set.
397
+ top_k (:class:`int`):
398
+ Optional. The maximum number of tokens to consider when
399
+ sampling.
400
+
401
+ The model uses combined Top-k and nucleus sampling.
402
+
403
+ Top-k sampling considers the set of ``top_k`` most
404
+ probable tokens.
405
+
406
+ This corresponds to the ``top_k`` field
407
+ on the ``request`` instance; if ``request`` is provided, this
408
+ should not be set.
409
+ retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
410
+ should be retried.
411
+ timeout (float): The timeout for this request.
412
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
413
+ sent along with the request as metadata. Normally, each value must be of type `str`,
414
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
415
+ be of type `bytes`.
416
+
417
+ Returns:
418
+ google.ai.generativelanguage_v1beta.types.GenerateMessageResponse:
419
+ The response from the model.
420
+
421
+ This includes candidate messages and
422
+ conversation history in the form of
423
+ chronologically-ordered messages.
424
+
425
+ """
426
+ # Create or coerce a protobuf request object.
427
+ # - Quick check: If we got a request object, we should *not* have
428
+ # gotten any keyword arguments that map to the request.
429
+ has_flattened_params = any(
430
+ [model, prompt, temperature, candidate_count, top_p, top_k]
431
+ )
432
+ if request is not None and has_flattened_params:
433
+ raise ValueError(
434
+ "If the `request` argument is set, then none of "
435
+ "the individual field arguments should be set."
436
+ )
437
+
438
+ # - Use the request object if provided (there's no risk of modifying the input as
439
+ # there are no flattened fields), or create one.
440
+ if not isinstance(request, discuss_service.GenerateMessageRequest):
441
+ request = discuss_service.GenerateMessageRequest(request)
442
+
443
+ # If we have keyword arguments corresponding to fields on the
444
+ # request, apply these.
445
+ if model is not None:
446
+ request.model = model
447
+ if prompt is not None:
448
+ request.prompt = prompt
449
+ if temperature is not None:
450
+ request.temperature = temperature
451
+ if candidate_count is not None:
452
+ request.candidate_count = candidate_count
453
+ if top_p is not None:
454
+ request.top_p = top_p
455
+ if top_k is not None:
456
+ request.top_k = top_k
457
+
458
+ # Wrap the RPC method; this adds retry and timeout information,
459
+ # and friendly error handling.
460
+ rpc = self._client._transport._wrapped_methods[
461
+ self._client._transport.generate_message
462
+ ]
463
+
464
+ # Certain fields should be provided within the metadata header;
465
+ # add these here.
466
+ metadata = tuple(metadata) + (
467
+ gapic_v1.routing_header.to_grpc_metadata((("model", request.model),)),
468
+ )
469
+
470
+ # Validate the universe domain.
471
+ self._client._validate_universe_domain()
472
+
473
+ # Send the request.
474
+ response = await rpc(
475
+ request,
476
+ retry=retry,
477
+ timeout=timeout,
478
+ metadata=metadata,
479
+ )
480
+
481
+ # Done; return the response.
482
+ return response
483
+
484
+ async def count_message_tokens(
485
+ self,
486
+ request: Optional[
487
+ Union[discuss_service.CountMessageTokensRequest, dict]
488
+ ] = None,
489
+ *,
490
+ model: Optional[str] = None,
491
+ prompt: Optional[discuss_service.MessagePrompt] = None,
492
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
493
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
494
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
495
+ ) -> discuss_service.CountMessageTokensResponse:
496
+ r"""Runs a model's tokenizer on a string and returns the
497
+ token count.
498
+
499
+ .. code-block:: python
500
+
501
+ # This snippet has been automatically generated and should be regarded as a
502
+ # code template only.
503
+ # It will require modifications to work:
504
+ # - It may require correct/in-range values for request initialization.
505
+ # - It may require specifying regional endpoints when creating the service
506
+ # client as shown in:
507
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
508
+ from google.ai import generativelanguage_v1beta
509
+
510
+ async def sample_count_message_tokens():
511
+ # Create a client
512
+ client = generativelanguage_v1beta.DiscussServiceAsyncClient()
513
+
514
+ # Initialize request argument(s)
515
+ prompt = generativelanguage_v1beta.MessagePrompt()
516
+ prompt.messages.content = "content_value"
517
+
518
+ request = generativelanguage_v1beta.CountMessageTokensRequest(
519
+ model="model_value",
520
+ prompt=prompt,
521
+ )
522
+
523
+ # Make the request
524
+ response = await client.count_message_tokens(request=request)
525
+
526
+ # Handle the response
527
+ print(response)
528
+
529
+ Args:
530
+ request (Optional[Union[google.ai.generativelanguage_v1beta.types.CountMessageTokensRequest, dict]]):
531
+ The request object. Counts the number of tokens in the ``prompt`` sent to a
532
+ model.
533
+
534
+ Models may tokenize text differently, so each model may
535
+ return a different ``token_count``.
536
+ model (:class:`str`):
537
+ Required. The model's resource name. This serves as an
538
+ ID for the Model to use.
539
+
540
+ This name should match a model name returned by the
541
+ ``ListModels`` method.
542
+
543
+ Format: ``models/{model}``
544
+
545
+ This corresponds to the ``model`` field
546
+ on the ``request`` instance; if ``request`` is provided, this
547
+ should not be set.
548
+ prompt (:class:`google.ai.generativelanguage_v1beta.types.MessagePrompt`):
549
+ Required. The prompt, whose token
550
+ count is to be returned.
551
+
552
+ This corresponds to the ``prompt`` field
553
+ on the ``request`` instance; if ``request`` is provided, this
554
+ should not be set.
555
+ retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
556
+ should be retried.
557
+ timeout (float): The timeout for this request.
558
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
559
+ sent along with the request as metadata. Normally, each value must be of type `str`,
560
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
561
+ be of type `bytes`.
562
+
563
+ Returns:
564
+ google.ai.generativelanguage_v1beta.types.CountMessageTokensResponse:
565
+ A response from CountMessageTokens.
566
+
567
+ It returns the model's token_count for the prompt.
568
+
569
+ """
570
+ # Create or coerce a protobuf request object.
571
+ # - Quick check: If we got a request object, we should *not* have
572
+ # gotten any keyword arguments that map to the request.
573
+ has_flattened_params = any([model, prompt])
574
+ if request is not None and has_flattened_params:
575
+ raise ValueError(
576
+ "If the `request` argument is set, then none of "
577
+ "the individual field arguments should be set."
578
+ )
579
+
580
+ # - Use the request object if provided (there's no risk of modifying the input as
581
+ # there are no flattened fields), or create one.
582
+ if not isinstance(request, discuss_service.CountMessageTokensRequest):
583
+ request = discuss_service.CountMessageTokensRequest(request)
584
+
585
+ # If we have keyword arguments corresponding to fields on the
586
+ # request, apply these.
587
+ if model is not None:
588
+ request.model = model
589
+ if prompt is not None:
590
+ request.prompt = prompt
591
+
592
+ # Wrap the RPC method; this adds retry and timeout information,
593
+ # and friendly error handling.
594
+ rpc = self._client._transport._wrapped_methods[
595
+ self._client._transport.count_message_tokens
596
+ ]
597
+
598
+ # Certain fields should be provided within the metadata header;
599
+ # add these here.
600
+ metadata = tuple(metadata) + (
601
+ gapic_v1.routing_header.to_grpc_metadata((("model", request.model),)),
602
+ )
603
+
604
+ # Validate the universe domain.
605
+ self._client._validate_universe_domain()
606
+
607
+ # Send the request.
608
+ response = await rpc(
609
+ request,
610
+ retry=retry,
611
+ timeout=timeout,
612
+ metadata=metadata,
613
+ )
614
+
615
+ # Done; return the response.
616
+ return response
617
+
618
+ async def list_operations(
619
+ self,
620
+ request: Optional[operations_pb2.ListOperationsRequest] = None,
621
+ *,
622
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
623
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
624
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
625
+ ) -> operations_pb2.ListOperationsResponse:
626
+ r"""Lists operations that match the specified filter in the request.
627
+
628
+ Args:
629
+ request (:class:`~.operations_pb2.ListOperationsRequest`):
630
+ The request object. Request message for
631
+ `ListOperations` method.
632
+ retry (google.api_core.retry_async.AsyncRetry): Designation of what errors,
633
+ if any, should be retried.
634
+ timeout (float): The timeout for this request.
635
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
636
+ sent along with the request as metadata. Normally, each value must be of type `str`,
637
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
638
+ be of type `bytes`.
639
+ Returns:
640
+ ~.operations_pb2.ListOperationsResponse:
641
+ Response message for ``ListOperations`` method.
642
+ """
643
+ # Create or coerce a protobuf request object.
644
+ # The request isn't a proto-plus wrapped type,
645
+ # so it must be constructed via keyword expansion.
646
+ if isinstance(request, dict):
647
+ request = operations_pb2.ListOperationsRequest(**request)
648
+
649
+ # Wrap the RPC method; this adds retry and timeout information,
650
+ # and friendly error handling.
651
+ rpc = self.transport._wrapped_methods[self._client._transport.list_operations]
652
+
653
+ # Certain fields should be provided within the metadata header;
654
+ # add these here.
655
+ metadata = tuple(metadata) + (
656
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
657
+ )
658
+
659
+ # Validate the universe domain.
660
+ self._client._validate_universe_domain()
661
+
662
+ # Send the request.
663
+ response = await rpc(
664
+ request,
665
+ retry=retry,
666
+ timeout=timeout,
667
+ metadata=metadata,
668
+ )
669
+
670
+ # Done; return the response.
671
+ return response
672
+
673
+ async def get_operation(
674
+ self,
675
+ request: Optional[operations_pb2.GetOperationRequest] = None,
676
+ *,
677
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
678
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
679
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
680
+ ) -> operations_pb2.Operation:
681
+ r"""Gets the latest state of a long-running operation.
682
+
683
+ Args:
684
+ request (:class:`~.operations_pb2.GetOperationRequest`):
685
+ The request object. Request message for
686
+ `GetOperation` method.
687
+ retry (google.api_core.retry_async.AsyncRetry): Designation of what errors,
688
+ if any, should be retried.
689
+ timeout (float): The timeout for this request.
690
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
691
+ sent along with the request as metadata. Normally, each value must be of type `str`,
692
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
693
+ be of type `bytes`.
694
+ Returns:
695
+ ~.operations_pb2.Operation:
696
+ An ``Operation`` object.
697
+ """
698
+ # Create or coerce a protobuf request object.
699
+ # The request isn't a proto-plus wrapped type,
700
+ # so it must be constructed via keyword expansion.
701
+ if isinstance(request, dict):
702
+ request = operations_pb2.GetOperationRequest(**request)
703
+
704
+ # Wrap the RPC method; this adds retry and timeout information,
705
+ # and friendly error handling.
706
+ rpc = self.transport._wrapped_methods[self._client._transport.get_operation]
707
+
708
+ # Certain fields should be provided within the metadata header;
709
+ # add these here.
710
+ metadata = tuple(metadata) + (
711
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
712
+ )
713
+
714
+ # Validate the universe domain.
715
+ self._client._validate_universe_domain()
716
+
717
+ # Send the request.
718
+ response = await rpc(
719
+ request,
720
+ retry=retry,
721
+ timeout=timeout,
722
+ metadata=metadata,
723
+ )
724
+
725
+ # Done; return the response.
726
+ return response
727
+
728
+ async def __aenter__(self) -> "DiscussServiceAsyncClient":
729
+ return self
730
+
731
+ async def __aexit__(self, exc_type, exc, tb):
732
+ await self.transport.close()
733
+
734
+
735
+ DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
736
+ gapic_version=package_version.__version__
737
+ )
738
+
739
+
740
+ __all__ = ("DiscussServiceAsyncClient",)
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/discuss_service/client.py ADDED
@@ -0,0 +1,1128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ from collections import OrderedDict
17
+ import logging as std_logging
18
+ import os
19
+ import re
20
+ from typing import (
21
+ Callable,
22
+ Dict,
23
+ Mapping,
24
+ MutableMapping,
25
+ MutableSequence,
26
+ Optional,
27
+ Sequence,
28
+ Tuple,
29
+ Type,
30
+ Union,
31
+ cast,
32
+ )
33
+ import warnings
34
+
35
+ from google.api_core import client_options as client_options_lib
36
+ from google.api_core import exceptions as core_exceptions
37
+ from google.api_core import gapic_v1
38
+ from google.api_core import retry as retries
39
+ from google.auth import credentials as ga_credentials # type: ignore
40
+ from google.auth.exceptions import MutualTLSChannelError # type: ignore
41
+ from google.auth.transport import mtls # type: ignore
42
+ from google.auth.transport.grpc import SslCredentials # type: ignore
43
+ from google.oauth2 import service_account # type: ignore
44
+
45
+ from google.ai.generativelanguage_v1beta import gapic_version as package_version
46
+
47
+ try:
48
+ OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
49
+ except AttributeError: # pragma: NO COVER
50
+ OptionalRetry = Union[retries.Retry, object, None] # type: ignore
51
+
52
+ try:
53
+ from google.api_core import client_logging # type: ignore
54
+
55
+ CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
56
+ except ImportError: # pragma: NO COVER
57
+ CLIENT_LOGGING_SUPPORTED = False
58
+
59
+ _LOGGER = std_logging.getLogger(__name__)
60
+
61
+ from google.longrunning import operations_pb2 # type: ignore
62
+
63
+ from google.ai.generativelanguage_v1beta.types import discuss_service, safety
64
+
65
+ from .transports.base import DEFAULT_CLIENT_INFO, DiscussServiceTransport
66
+ from .transports.grpc import DiscussServiceGrpcTransport
67
+ from .transports.grpc_asyncio import DiscussServiceGrpcAsyncIOTransport
68
+ from .transports.rest import DiscussServiceRestTransport
69
+
70
+
71
+ class DiscussServiceClientMeta(type):
72
+ """Metaclass for the DiscussService client.
73
+
74
+ This provides class-level methods for building and retrieving
75
+ support objects (e.g. transport) without polluting the client instance
76
+ objects.
77
+ """
78
+
79
+ _transport_registry = (
80
+ OrderedDict()
81
+ ) # type: Dict[str, Type[DiscussServiceTransport]]
82
+ _transport_registry["grpc"] = DiscussServiceGrpcTransport
83
+ _transport_registry["grpc_asyncio"] = DiscussServiceGrpcAsyncIOTransport
84
+ _transport_registry["rest"] = DiscussServiceRestTransport
85
+
86
+ def get_transport_class(
87
+ cls,
88
+ label: Optional[str] = None,
89
+ ) -> Type[DiscussServiceTransport]:
90
+ """Returns an appropriate transport class.
91
+
92
+ Args:
93
+ label: The name of the desired transport. If none is
94
+ provided, then the first transport in the registry is used.
95
+
96
+ Returns:
97
+ The transport class to use.
98
+ """
99
+ # If a specific transport is requested, return that one.
100
+ if label:
101
+ return cls._transport_registry[label]
102
+
103
+ # No transport is requested; return the default (that is, the first one
104
+ # in the dictionary).
105
+ return next(iter(cls._transport_registry.values()))
106
+
107
+
108
+ class DiscussServiceClient(metaclass=DiscussServiceClientMeta):
109
+ """An API for using Generative Language Models (GLMs) in dialog
110
+ applications.
111
+ Also known as large language models (LLMs), this API provides
112
+ models that are trained for multi-turn dialog.
113
+ """
114
+
115
+ @staticmethod
116
+ def _get_default_mtls_endpoint(api_endpoint):
117
+ """Converts api endpoint to mTLS endpoint.
118
+
119
+ Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to
120
+ "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively.
121
+ Args:
122
+ api_endpoint (Optional[str]): the api endpoint to convert.
123
+ Returns:
124
+ str: converted mTLS api endpoint.
125
+ """
126
+ if not api_endpoint:
127
+ return api_endpoint
128
+
129
+ mtls_endpoint_re = re.compile(
130
+ r"(?P<name>[^.]+)(?P<mtls>\.mtls)?(?P<sandbox>\.sandbox)?(?P<googledomain>\.googleapis\.com)?"
131
+ )
132
+
133
+ m = mtls_endpoint_re.match(api_endpoint)
134
+ name, mtls, sandbox, googledomain = m.groups()
135
+ if mtls or not googledomain:
136
+ return api_endpoint
137
+
138
+ if sandbox:
139
+ return api_endpoint.replace(
140
+ "sandbox.googleapis.com", "mtls.sandbox.googleapis.com"
141
+ )
142
+
143
+ return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com")
144
+
145
+ # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead.
146
+ DEFAULT_ENDPOINT = "generativelanguage.googleapis.com"
147
+ DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore
148
+ DEFAULT_ENDPOINT
149
+ )
150
+
151
+ _DEFAULT_ENDPOINT_TEMPLATE = "generativelanguage.{UNIVERSE_DOMAIN}"
152
+ _DEFAULT_UNIVERSE = "googleapis.com"
153
+
154
+ @classmethod
155
+ def from_service_account_info(cls, info: dict, *args, **kwargs):
156
+ """Creates an instance of this client using the provided credentials
157
+ info.
158
+
159
+ Args:
160
+ info (dict): The service account private key info.
161
+ args: Additional arguments to pass to the constructor.
162
+ kwargs: Additional arguments to pass to the constructor.
163
+
164
+ Returns:
165
+ DiscussServiceClient: The constructed client.
166
+ """
167
+ credentials = service_account.Credentials.from_service_account_info(info)
168
+ kwargs["credentials"] = credentials
169
+ return cls(*args, **kwargs)
170
+
171
+ @classmethod
172
+ def from_service_account_file(cls, filename: str, *args, **kwargs):
173
+ """Creates an instance of this client using the provided credentials
174
+ file.
175
+
176
+ Args:
177
+ filename (str): The path to the service account private key json
178
+ file.
179
+ args: Additional arguments to pass to the constructor.
180
+ kwargs: Additional arguments to pass to the constructor.
181
+
182
+ Returns:
183
+ DiscussServiceClient: The constructed client.
184
+ """
185
+ credentials = service_account.Credentials.from_service_account_file(filename)
186
+ kwargs["credentials"] = credentials
187
+ return cls(*args, **kwargs)
188
+
189
+ from_service_account_json = from_service_account_file
190
+
191
+ @property
192
+ def transport(self) -> DiscussServiceTransport:
193
+ """Returns the transport used by the client instance.
194
+
195
+ Returns:
196
+ DiscussServiceTransport: The transport used by the client
197
+ instance.
198
+ """
199
+ return self._transport
200
+
201
+ @staticmethod
202
+ def model_path(
203
+ model: str,
204
+ ) -> str:
205
+ """Returns a fully-qualified model string."""
206
+ return "models/{model}".format(
207
+ model=model,
208
+ )
209
+
210
+ @staticmethod
211
+ def parse_model_path(path: str) -> Dict[str, str]:
212
+ """Parses a model path into its component segments."""
213
+ m = re.match(r"^models/(?P<model>.+?)$", path)
214
+ return m.groupdict() if m else {}
215
+
216
+ @staticmethod
217
+ def common_billing_account_path(
218
+ billing_account: str,
219
+ ) -> str:
220
+ """Returns a fully-qualified billing_account string."""
221
+ return "billingAccounts/{billing_account}".format(
222
+ billing_account=billing_account,
223
+ )
224
+
225
+ @staticmethod
226
+ def parse_common_billing_account_path(path: str) -> Dict[str, str]:
227
+ """Parse a billing_account path into its component segments."""
228
+ m = re.match(r"^billingAccounts/(?P<billing_account>.+?)$", path)
229
+ return m.groupdict() if m else {}
230
+
231
+ @staticmethod
232
+ def common_folder_path(
233
+ folder: str,
234
+ ) -> str:
235
+ """Returns a fully-qualified folder string."""
236
+ return "folders/{folder}".format(
237
+ folder=folder,
238
+ )
239
+
240
+ @staticmethod
241
+ def parse_common_folder_path(path: str) -> Dict[str, str]:
242
+ """Parse a folder path into its component segments."""
243
+ m = re.match(r"^folders/(?P<folder>.+?)$", path)
244
+ return m.groupdict() if m else {}
245
+
246
+ @staticmethod
247
+ def common_organization_path(
248
+ organization: str,
249
+ ) -> str:
250
+ """Returns a fully-qualified organization string."""
251
+ return "organizations/{organization}".format(
252
+ organization=organization,
253
+ )
254
+
255
+ @staticmethod
256
+ def parse_common_organization_path(path: str) -> Dict[str, str]:
257
+ """Parse a organization path into its component segments."""
258
+ m = re.match(r"^organizations/(?P<organization>.+?)$", path)
259
+ return m.groupdict() if m else {}
260
+
261
+ @staticmethod
262
+ def common_project_path(
263
+ project: str,
264
+ ) -> str:
265
+ """Returns a fully-qualified project string."""
266
+ return "projects/{project}".format(
267
+ project=project,
268
+ )
269
+
270
+ @staticmethod
271
+ def parse_common_project_path(path: str) -> Dict[str, str]:
272
+ """Parse a project path into its component segments."""
273
+ m = re.match(r"^projects/(?P<project>.+?)$", path)
274
+ return m.groupdict() if m else {}
275
+
276
+ @staticmethod
277
+ def common_location_path(
278
+ project: str,
279
+ location: str,
280
+ ) -> str:
281
+ """Returns a fully-qualified location string."""
282
+ return "projects/{project}/locations/{location}".format(
283
+ project=project,
284
+ location=location,
285
+ )
286
+
287
+ @staticmethod
288
+ def parse_common_location_path(path: str) -> Dict[str, str]:
289
+ """Parse a location path into its component segments."""
290
+ m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path)
291
+ return m.groupdict() if m else {}
292
+
293
+ @classmethod
294
+ def get_mtls_endpoint_and_cert_source(
295
+ cls, client_options: Optional[client_options_lib.ClientOptions] = None
296
+ ):
297
+ """Deprecated. Return the API endpoint and client cert source for mutual TLS.
298
+
299
+ The client cert source is determined in the following order:
300
+ (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
301
+ client cert source is None.
302
+ (2) if `client_options.client_cert_source` is provided, use the provided one; if the
303
+ default client cert source exists, use the default one; otherwise the client cert
304
+ source is None.
305
+
306
+ The API endpoint is determined in the following order:
307
+ (1) if `client_options.api_endpoint` if provided, use the provided one.
308
+ (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
309
+ default mTLS endpoint; if the environment variable is "never", use the default API
310
+ endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
311
+ use the default API endpoint.
312
+
313
+ More details can be found at https://google.aip.dev/auth/4114.
314
+
315
+ Args:
316
+ client_options (google.api_core.client_options.ClientOptions): Custom options for the
317
+ client. Only the `api_endpoint` and `client_cert_source` properties may be used
318
+ in this method.
319
+
320
+ Returns:
321
+ Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
322
+ client cert source to use.
323
+
324
+ Raises:
325
+ google.auth.exceptions.MutualTLSChannelError: If any errors happen.
326
+ """
327
+
328
+ warnings.warn(
329
+ "get_mtls_endpoint_and_cert_source is deprecated. Use the api_endpoint property instead.",
330
+ DeprecationWarning,
331
+ )
332
+ if client_options is None:
333
+ client_options = client_options_lib.ClientOptions()
334
+ use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")
335
+ use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
336
+ if use_client_cert not in ("true", "false"):
337
+ raise ValueError(
338
+ "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
339
+ )
340
+ if use_mtls_endpoint not in ("auto", "never", "always"):
341
+ raise MutualTLSChannelError(
342
+ "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
343
+ )
344
+
345
+ # Figure out the client cert source to use.
346
+ client_cert_source = None
347
+ if use_client_cert == "true":
348
+ if client_options.client_cert_source:
349
+ client_cert_source = client_options.client_cert_source
350
+ elif mtls.has_default_client_cert_source():
351
+ client_cert_source = mtls.default_client_cert_source()
352
+
353
+ # Figure out which api endpoint to use.
354
+ if client_options.api_endpoint is not None:
355
+ api_endpoint = client_options.api_endpoint
356
+ elif use_mtls_endpoint == "always" or (
357
+ use_mtls_endpoint == "auto" and client_cert_source
358
+ ):
359
+ api_endpoint = cls.DEFAULT_MTLS_ENDPOINT
360
+ else:
361
+ api_endpoint = cls.DEFAULT_ENDPOINT
362
+
363
+ return api_endpoint, client_cert_source
364
+
365
+ @staticmethod
366
+ def _read_environment_variables():
367
+ """Returns the environment variables used by the client.
368
+
369
+ Returns:
370
+ Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE,
371
+ GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables.
372
+
373
+ Raises:
374
+ ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not
375
+ any of ["true", "false"].
376
+ google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT
377
+ is not any of ["auto", "never", "always"].
378
+ """
379
+ use_client_cert = os.getenv(
380
+ "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
381
+ ).lower()
382
+ use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower()
383
+ universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN")
384
+ if use_client_cert not in ("true", "false"):
385
+ raise ValueError(
386
+ "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
387
+ )
388
+ if use_mtls_endpoint not in ("auto", "never", "always"):
389
+ raise MutualTLSChannelError(
390
+ "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
391
+ )
392
+ return use_client_cert == "true", use_mtls_endpoint, universe_domain_env
393
+
394
+ @staticmethod
395
+ def _get_client_cert_source(provided_cert_source, use_cert_flag):
396
+ """Return the client cert source to be used by the client.
397
+
398
+ Args:
399
+ provided_cert_source (bytes): The client certificate source provided.
400
+ use_cert_flag (bool): A flag indicating whether to use the client certificate.
401
+
402
+ Returns:
403
+ bytes or None: The client cert source to be used by the client.
404
+ """
405
+ client_cert_source = None
406
+ if use_cert_flag:
407
+ if provided_cert_source:
408
+ client_cert_source = provided_cert_source
409
+ elif mtls.has_default_client_cert_source():
410
+ client_cert_source = mtls.default_client_cert_source()
411
+ return client_cert_source
412
+
413
+ @staticmethod
414
+ def _get_api_endpoint(
415
+ api_override, client_cert_source, universe_domain, use_mtls_endpoint
416
+ ):
417
+ """Return the API endpoint used by the client.
418
+
419
+ Args:
420
+ api_override (str): The API endpoint override. If specified, this is always
421
+ the return value of this function and the other arguments are not used.
422
+ client_cert_source (bytes): The client certificate source used by the client.
423
+ universe_domain (str): The universe domain used by the client.
424
+ use_mtls_endpoint (str): How to use the mTLS endpoint, which depends also on the other parameters.
425
+ Possible values are "always", "auto", or "never".
426
+
427
+ Returns:
428
+ str: The API endpoint to be used by the client.
429
+ """
430
+ if api_override is not None:
431
+ api_endpoint = api_override
432
+ elif use_mtls_endpoint == "always" or (
433
+ use_mtls_endpoint == "auto" and client_cert_source
434
+ ):
435
+ _default_universe = DiscussServiceClient._DEFAULT_UNIVERSE
436
+ if universe_domain != _default_universe:
437
+ raise MutualTLSChannelError(
438
+ f"mTLS is not supported in any universe other than {_default_universe}."
439
+ )
440
+ api_endpoint = DiscussServiceClient.DEFAULT_MTLS_ENDPOINT
441
+ else:
442
+ api_endpoint = DiscussServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(
443
+ UNIVERSE_DOMAIN=universe_domain
444
+ )
445
+ return api_endpoint
446
+
447
+ @staticmethod
448
+ def _get_universe_domain(
449
+ client_universe_domain: Optional[str], universe_domain_env: Optional[str]
450
+ ) -> str:
451
+ """Return the universe domain used by the client.
452
+
453
+ Args:
454
+ client_universe_domain (Optional[str]): The universe domain configured via the client options.
455
+ universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable.
456
+
457
+ Returns:
458
+ str: The universe domain to be used by the client.
459
+
460
+ Raises:
461
+ ValueError: If the universe domain is an empty string.
462
+ """
463
+ universe_domain = DiscussServiceClient._DEFAULT_UNIVERSE
464
+ if client_universe_domain is not None:
465
+ universe_domain = client_universe_domain
466
+ elif universe_domain_env is not None:
467
+ universe_domain = universe_domain_env
468
+ if len(universe_domain.strip()) == 0:
469
+ raise ValueError("Universe Domain cannot be an empty string.")
470
+ return universe_domain
471
+
472
+ def _validate_universe_domain(self):
473
+ """Validates client's and credentials' universe domains are consistent.
474
+
475
+ Returns:
476
+ bool: True iff the configured universe domain is valid.
477
+
478
+ Raises:
479
+ ValueError: If the configured universe domain is not valid.
480
+ """
481
+
482
+ # NOTE (b/349488459): universe validation is disabled until further notice.
483
+ return True
484
+
485
+ @property
486
+ def api_endpoint(self):
487
+ """Return the API endpoint used by the client instance.
488
+
489
+ Returns:
490
+ str: The API endpoint used by the client instance.
491
+ """
492
+ return self._api_endpoint
493
+
494
+ @property
495
+ def universe_domain(self) -> str:
496
+ """Return the universe domain used by the client instance.
497
+
498
+ Returns:
499
+ str: The universe domain used by the client instance.
500
+ """
501
+ return self._universe_domain
502
+
503
+ def __init__(
504
+ self,
505
+ *,
506
+ credentials: Optional[ga_credentials.Credentials] = None,
507
+ transport: Optional[
508
+ Union[str, DiscussServiceTransport, Callable[..., DiscussServiceTransport]]
509
+ ] = None,
510
+ client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None,
511
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
512
+ ) -> None:
513
+ """Instantiates the discuss service client.
514
+
515
+ Args:
516
+ credentials (Optional[google.auth.credentials.Credentials]): The
517
+ authorization credentials to attach to requests. These
518
+ credentials identify the application to the service; if none
519
+ are specified, the client will attempt to ascertain the
520
+ credentials from the environment.
521
+ transport (Optional[Union[str,DiscussServiceTransport,Callable[..., DiscussServiceTransport]]]):
522
+ The transport to use, or a Callable that constructs and returns a new transport.
523
+ If a Callable is given, it will be called with the same set of initialization
524
+ arguments as used in the DiscussServiceTransport constructor.
525
+ If set to None, a transport is chosen automatically.
526
+ client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]):
527
+ Custom options for the client.
528
+
529
+ 1. The ``api_endpoint`` property can be used to override the
530
+ default endpoint provided by the client when ``transport`` is
531
+ not explicitly provided. Only if this property is not set and
532
+ ``transport`` was not explicitly provided, the endpoint is
533
+ determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment
534
+ variable, which have one of the following values:
535
+ "always" (always use the default mTLS endpoint), "never" (always
536
+ use the default regular endpoint) and "auto" (auto-switch to the
537
+ default mTLS endpoint if client certificate is present; this is
538
+ the default value).
539
+
540
+ 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
541
+ is "true", then the ``client_cert_source`` property can be used
542
+ to provide a client certificate for mTLS transport. If
543
+ not provided, the default SSL client certificate will be used if
544
+ present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
545
+ set, no client certificate will be used.
546
+
547
+ 3. The ``universe_domain`` property can be used to override the
548
+ default "googleapis.com" universe. Note that the ``api_endpoint``
549
+ property still takes precedence; and ``universe_domain`` is
550
+ currently not supported for mTLS.
551
+
552
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
553
+ The client info used to send a user-agent string along with
554
+ API requests. If ``None``, then default info will be used.
555
+ Generally, you only need to set this if you're developing
556
+ your own client library.
557
+
558
+ Raises:
559
+ google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
560
+ creation failed for any reason.
561
+ """
562
+ self._client_options = client_options
563
+ if isinstance(self._client_options, dict):
564
+ self._client_options = client_options_lib.from_dict(self._client_options)
565
+ if self._client_options is None:
566
+ self._client_options = client_options_lib.ClientOptions()
567
+ self._client_options = cast(
568
+ client_options_lib.ClientOptions, self._client_options
569
+ )
570
+
571
+ universe_domain_opt = getattr(self._client_options, "universe_domain", None)
572
+
573
+ (
574
+ self._use_client_cert,
575
+ self._use_mtls_endpoint,
576
+ self._universe_domain_env,
577
+ ) = DiscussServiceClient._read_environment_variables()
578
+ self._client_cert_source = DiscussServiceClient._get_client_cert_source(
579
+ self._client_options.client_cert_source, self._use_client_cert
580
+ )
581
+ self._universe_domain = DiscussServiceClient._get_universe_domain(
582
+ universe_domain_opt, self._universe_domain_env
583
+ )
584
+ self._api_endpoint = None # updated below, depending on `transport`
585
+
586
+ # Initialize the universe domain validation.
587
+ self._is_universe_domain_valid = False
588
+
589
+ if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER
590
+ # Setup logging.
591
+ client_logging.initialize_logging()
592
+
593
+ api_key_value = getattr(self._client_options, "api_key", None)
594
+ if api_key_value and credentials:
595
+ raise ValueError(
596
+ "client_options.api_key and credentials are mutually exclusive"
597
+ )
598
+
599
+ # Save or instantiate the transport.
600
+ # Ordinarily, we provide the transport, but allowing a custom transport
601
+ # instance provides an extensibility point for unusual situations.
602
+ transport_provided = isinstance(transport, DiscussServiceTransport)
603
+ if transport_provided:
604
+ # transport is a DiscussServiceTransport instance.
605
+ if credentials or self._client_options.credentials_file or api_key_value:
606
+ raise ValueError(
607
+ "When providing a transport instance, "
608
+ "provide its credentials directly."
609
+ )
610
+ if self._client_options.scopes:
611
+ raise ValueError(
612
+ "When providing a transport instance, provide its scopes "
613
+ "directly."
614
+ )
615
+ self._transport = cast(DiscussServiceTransport, transport)
616
+ self._api_endpoint = self._transport.host
617
+
618
+ self._api_endpoint = (
619
+ self._api_endpoint
620
+ or DiscussServiceClient._get_api_endpoint(
621
+ self._client_options.api_endpoint,
622
+ self._client_cert_source,
623
+ self._universe_domain,
624
+ self._use_mtls_endpoint,
625
+ )
626
+ )
627
+
628
+ if not transport_provided:
629
+ import google.auth._default # type: ignore
630
+
631
+ if api_key_value and hasattr(
632
+ google.auth._default, "get_api_key_credentials"
633
+ ):
634
+ credentials = google.auth._default.get_api_key_credentials(
635
+ api_key_value
636
+ )
637
+
638
+ transport_init: Union[
639
+ Type[DiscussServiceTransport], Callable[..., DiscussServiceTransport]
640
+ ] = (
641
+ DiscussServiceClient.get_transport_class(transport)
642
+ if isinstance(transport, str) or transport is None
643
+ else cast(Callable[..., DiscussServiceTransport], transport)
644
+ )
645
+ # initialize with the provided callable or the passed in class
646
+ self._transport = transport_init(
647
+ credentials=credentials,
648
+ credentials_file=self._client_options.credentials_file,
649
+ host=self._api_endpoint,
650
+ scopes=self._client_options.scopes,
651
+ client_cert_source_for_mtls=self._client_cert_source,
652
+ quota_project_id=self._client_options.quota_project_id,
653
+ client_info=client_info,
654
+ always_use_jwt_access=True,
655
+ api_audience=self._client_options.api_audience,
656
+ )
657
+
658
+ if "async" not in str(self._transport):
659
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
660
+ std_logging.DEBUG
661
+ ): # pragma: NO COVER
662
+ _LOGGER.debug(
663
+ "Created client `google.ai.generativelanguage_v1beta.DiscussServiceClient`.",
664
+ extra={
665
+ "serviceName": "google.ai.generativelanguage.v1beta.DiscussService",
666
+ "universeDomain": getattr(
667
+ self._transport._credentials, "universe_domain", ""
668
+ ),
669
+ "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}",
670
+ "credentialsInfo": getattr(
671
+ self.transport._credentials, "get_cred_info", lambda: None
672
+ )(),
673
+ }
674
+ if hasattr(self._transport, "_credentials")
675
+ else {
676
+ "serviceName": "google.ai.generativelanguage.v1beta.DiscussService",
677
+ "credentialsType": None,
678
+ },
679
+ )
680
+
681
+ def generate_message(
682
+ self,
683
+ request: Optional[Union[discuss_service.GenerateMessageRequest, dict]] = None,
684
+ *,
685
+ model: Optional[str] = None,
686
+ prompt: Optional[discuss_service.MessagePrompt] = None,
687
+ temperature: Optional[float] = None,
688
+ candidate_count: Optional[int] = None,
689
+ top_p: Optional[float] = None,
690
+ top_k: Optional[int] = None,
691
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
692
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
693
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
694
+ ) -> discuss_service.GenerateMessageResponse:
695
+ r"""Generates a response from the model given an input
696
+ ``MessagePrompt``.
697
+
698
+ .. code-block:: python
699
+
700
+ # This snippet has been automatically generated and should be regarded as a
701
+ # code template only.
702
+ # It will require modifications to work:
703
+ # - It may require correct/in-range values for request initialization.
704
+ # - It may require specifying regional endpoints when creating the service
705
+ # client as shown in:
706
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
707
+ from google.ai import generativelanguage_v1beta
708
+
709
+ def sample_generate_message():
710
+ # Create a client
711
+ client = generativelanguage_v1beta.DiscussServiceClient()
712
+
713
+ # Initialize request argument(s)
714
+ prompt = generativelanguage_v1beta.MessagePrompt()
715
+ prompt.messages.content = "content_value"
716
+
717
+ request = generativelanguage_v1beta.GenerateMessageRequest(
718
+ model="model_value",
719
+ prompt=prompt,
720
+ )
721
+
722
+ # Make the request
723
+ response = client.generate_message(request=request)
724
+
725
+ # Handle the response
726
+ print(response)
727
+
728
+ Args:
729
+ request (Union[google.ai.generativelanguage_v1beta.types.GenerateMessageRequest, dict]):
730
+ The request object. Request to generate a message
731
+ response from the model.
732
+ model (str):
733
+ Required. The name of the model to use.
734
+
735
+ Format: ``name=models/{model}``.
736
+
737
+ This corresponds to the ``model`` field
738
+ on the ``request`` instance; if ``request`` is provided, this
739
+ should not be set.
740
+ prompt (google.ai.generativelanguage_v1beta.types.MessagePrompt):
741
+ Required. The structured textual
742
+ input given to the model as a prompt.
743
+ Given a
744
+ prompt, the model will return what it
745
+ predicts is the next message in the
746
+ discussion.
747
+
748
+ This corresponds to the ``prompt`` field
749
+ on the ``request`` instance; if ``request`` is provided, this
750
+ should not be set.
751
+ temperature (float):
752
+ Optional. Controls the randomness of the output.
753
+
754
+ Values can range over ``[0.0,1.0]``, inclusive. A value
755
+ closer to ``1.0`` will produce responses that are more
756
+ varied, while a value closer to ``0.0`` will typically
757
+ result in less surprising responses from the model.
758
+
759
+ This corresponds to the ``temperature`` field
760
+ on the ``request`` instance; if ``request`` is provided, this
761
+ should not be set.
762
+ candidate_count (int):
763
+ Optional. The number of generated response messages to
764
+ return.
765
+
766
+ This value must be between ``[1, 8]``, inclusive. If
767
+ unset, this will default to ``1``.
768
+
769
+ This corresponds to the ``candidate_count`` field
770
+ on the ``request`` instance; if ``request`` is provided, this
771
+ should not be set.
772
+ top_p (float):
773
+ Optional. The maximum cumulative probability of tokens
774
+ to consider when sampling.
775
+
776
+ The model uses combined Top-k and nucleus sampling.
777
+
778
+ Nucleus sampling considers the smallest set of tokens
779
+ whose probability sum is at least ``top_p``.
780
+
781
+ This corresponds to the ``top_p`` field
782
+ on the ``request`` instance; if ``request`` is provided, this
783
+ should not be set.
784
+ top_k (int):
785
+ Optional. The maximum number of tokens to consider when
786
+ sampling.
787
+
788
+ The model uses combined Top-k and nucleus sampling.
789
+
790
+ Top-k sampling considers the set of ``top_k`` most
791
+ probable tokens.
792
+
793
+ This corresponds to the ``top_k`` field
794
+ on the ``request`` instance; if ``request`` is provided, this
795
+ should not be set.
796
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
797
+ should be retried.
798
+ timeout (float): The timeout for this request.
799
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
800
+ sent along with the request as metadata. Normally, each value must be of type `str`,
801
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
802
+ be of type `bytes`.
803
+
804
+ Returns:
805
+ google.ai.generativelanguage_v1beta.types.GenerateMessageResponse:
806
+ The response from the model.
807
+
808
+ This includes candidate messages and
809
+ conversation history in the form of
810
+ chronologically-ordered messages.
811
+
812
+ """
813
+ # Create or coerce a protobuf request object.
814
+ # - Quick check: If we got a request object, we should *not* have
815
+ # gotten any keyword arguments that map to the request.
816
+ has_flattened_params = any(
817
+ [model, prompt, temperature, candidate_count, top_p, top_k]
818
+ )
819
+ if request is not None and has_flattened_params:
820
+ raise ValueError(
821
+ "If the `request` argument is set, then none of "
822
+ "the individual field arguments should be set."
823
+ )
824
+
825
+ # - Use the request object if provided (there's no risk of modifying the input as
826
+ # there are no flattened fields), or create one.
827
+ if not isinstance(request, discuss_service.GenerateMessageRequest):
828
+ request = discuss_service.GenerateMessageRequest(request)
829
+ # If we have keyword arguments corresponding to fields on the
830
+ # request, apply these.
831
+ if model is not None:
832
+ request.model = model
833
+ if prompt is not None:
834
+ request.prompt = prompt
835
+ if temperature is not None:
836
+ request.temperature = temperature
837
+ if candidate_count is not None:
838
+ request.candidate_count = candidate_count
839
+ if top_p is not None:
840
+ request.top_p = top_p
841
+ if top_k is not None:
842
+ request.top_k = top_k
843
+
844
+ # Wrap the RPC method; this adds retry and timeout information,
845
+ # and friendly error handling.
846
+ rpc = self._transport._wrapped_methods[self._transport.generate_message]
847
+
848
+ # Certain fields should be provided within the metadata header;
849
+ # add these here.
850
+ metadata = tuple(metadata) + (
851
+ gapic_v1.routing_header.to_grpc_metadata((("model", request.model),)),
852
+ )
853
+
854
+ # Validate the universe domain.
855
+ self._validate_universe_domain()
856
+
857
+ # Send the request.
858
+ response = rpc(
859
+ request,
860
+ retry=retry,
861
+ timeout=timeout,
862
+ metadata=metadata,
863
+ )
864
+
865
+ # Done; return the response.
866
+ return response
867
+
868
+ def count_message_tokens(
869
+ self,
870
+ request: Optional[
871
+ Union[discuss_service.CountMessageTokensRequest, dict]
872
+ ] = None,
873
+ *,
874
+ model: Optional[str] = None,
875
+ prompt: Optional[discuss_service.MessagePrompt] = None,
876
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
877
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
878
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
879
+ ) -> discuss_service.CountMessageTokensResponse:
880
+ r"""Runs a model's tokenizer on a string and returns the
881
+ token count.
882
+
883
+ .. code-block:: python
884
+
885
+ # This snippet has been automatically generated and should be regarded as a
886
+ # code template only.
887
+ # It will require modifications to work:
888
+ # - It may require correct/in-range values for request initialization.
889
+ # - It may require specifying regional endpoints when creating the service
890
+ # client as shown in:
891
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
892
+ from google.ai import generativelanguage_v1beta
893
+
894
+ def sample_count_message_tokens():
895
+ # Create a client
896
+ client = generativelanguage_v1beta.DiscussServiceClient()
897
+
898
+ # Initialize request argument(s)
899
+ prompt = generativelanguage_v1beta.MessagePrompt()
900
+ prompt.messages.content = "content_value"
901
+
902
+ request = generativelanguage_v1beta.CountMessageTokensRequest(
903
+ model="model_value",
904
+ prompt=prompt,
905
+ )
906
+
907
+ # Make the request
908
+ response = client.count_message_tokens(request=request)
909
+
910
+ # Handle the response
911
+ print(response)
912
+
913
+ Args:
914
+ request (Union[google.ai.generativelanguage_v1beta.types.CountMessageTokensRequest, dict]):
915
+ The request object. Counts the number of tokens in the ``prompt`` sent to a
916
+ model.
917
+
918
+ Models may tokenize text differently, so each model may
919
+ return a different ``token_count``.
920
+ model (str):
921
+ Required. The model's resource name. This serves as an
922
+ ID for the Model to use.
923
+
924
+ This name should match a model name returned by the
925
+ ``ListModels`` method.
926
+
927
+ Format: ``models/{model}``
928
+
929
+ This corresponds to the ``model`` field
930
+ on the ``request`` instance; if ``request`` is provided, this
931
+ should not be set.
932
+ prompt (google.ai.generativelanguage_v1beta.types.MessagePrompt):
933
+ Required. The prompt, whose token
934
+ count is to be returned.
935
+
936
+ This corresponds to the ``prompt`` field
937
+ on the ``request`` instance; if ``request`` is provided, this
938
+ should not be set.
939
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
940
+ should be retried.
941
+ timeout (float): The timeout for this request.
942
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
943
+ sent along with the request as metadata. Normally, each value must be of type `str`,
944
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
945
+ be of type `bytes`.
946
+
947
+ Returns:
948
+ google.ai.generativelanguage_v1beta.types.CountMessageTokensResponse:
949
+ A response from CountMessageTokens.
950
+
951
+ It returns the model's token_count for the prompt.
952
+
953
+ """
954
+ # Create or coerce a protobuf request object.
955
+ # - Quick check: If we got a request object, we should *not* have
956
+ # gotten any keyword arguments that map to the request.
957
+ has_flattened_params = any([model, prompt])
958
+ if request is not None and has_flattened_params:
959
+ raise ValueError(
960
+ "If the `request` argument is set, then none of "
961
+ "the individual field arguments should be set."
962
+ )
963
+
964
+ # - Use the request object if provided (there's no risk of modifying the input as
965
+ # there are no flattened fields), or create one.
966
+ if not isinstance(request, discuss_service.CountMessageTokensRequest):
967
+ request = discuss_service.CountMessageTokensRequest(request)
968
+ # If we have keyword arguments corresponding to fields on the
969
+ # request, apply these.
970
+ if model is not None:
971
+ request.model = model
972
+ if prompt is not None:
973
+ request.prompt = prompt
974
+
975
+ # Wrap the RPC method; this adds retry and timeout information,
976
+ # and friendly error handling.
977
+ rpc = self._transport._wrapped_methods[self._transport.count_message_tokens]
978
+
979
+ # Certain fields should be provided within the metadata header;
980
+ # add these here.
981
+ metadata = tuple(metadata) + (
982
+ gapic_v1.routing_header.to_grpc_metadata((("model", request.model),)),
983
+ )
984
+
985
+ # Validate the universe domain.
986
+ self._validate_universe_domain()
987
+
988
+ # Send the request.
989
+ response = rpc(
990
+ request,
991
+ retry=retry,
992
+ timeout=timeout,
993
+ metadata=metadata,
994
+ )
995
+
996
+ # Done; return the response.
997
+ return response
998
+
999
+ def __enter__(self) -> "DiscussServiceClient":
1000
+ return self
1001
+
1002
+ def __exit__(self, type, value, traceback):
1003
+ """Releases underlying transport's resources.
1004
+
1005
+ .. warning::
1006
+ ONLY use as a context manager if the transport is NOT shared
1007
+ with other clients! Exiting the with block will CLOSE the transport
1008
+ and may cause errors in other clients!
1009
+ """
1010
+ self.transport.close()
1011
+
1012
+ def list_operations(
1013
+ self,
1014
+ request: Optional[operations_pb2.ListOperationsRequest] = None,
1015
+ *,
1016
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1017
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1018
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1019
+ ) -> operations_pb2.ListOperationsResponse:
1020
+ r"""Lists operations that match the specified filter in the request.
1021
+
1022
+ Args:
1023
+ request (:class:`~.operations_pb2.ListOperationsRequest`):
1024
+ The request object. Request message for
1025
+ `ListOperations` method.
1026
+ retry (google.api_core.retry.Retry): Designation of what errors,
1027
+ if any, should be retried.
1028
+ timeout (float): The timeout for this request.
1029
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1030
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1031
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1032
+ be of type `bytes`.
1033
+ Returns:
1034
+ ~.operations_pb2.ListOperationsResponse:
1035
+ Response message for ``ListOperations`` method.
1036
+ """
1037
+ # Create or coerce a protobuf request object.
1038
+ # The request isn't a proto-plus wrapped type,
1039
+ # so it must be constructed via keyword expansion.
1040
+ if isinstance(request, dict):
1041
+ request = operations_pb2.ListOperationsRequest(**request)
1042
+
1043
+ # Wrap the RPC method; this adds retry and timeout information,
1044
+ # and friendly error handling.
1045
+ rpc = self._transport._wrapped_methods[self._transport.list_operations]
1046
+
1047
+ # Certain fields should be provided within the metadata header;
1048
+ # add these here.
1049
+ metadata = tuple(metadata) + (
1050
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1051
+ )
1052
+
1053
+ # Validate the universe domain.
1054
+ self._validate_universe_domain()
1055
+
1056
+ # Send the request.
1057
+ response = rpc(
1058
+ request,
1059
+ retry=retry,
1060
+ timeout=timeout,
1061
+ metadata=metadata,
1062
+ )
1063
+
1064
+ # Done; return the response.
1065
+ return response
1066
+
1067
+ def get_operation(
1068
+ self,
1069
+ request: Optional[operations_pb2.GetOperationRequest] = None,
1070
+ *,
1071
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1072
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1073
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1074
+ ) -> operations_pb2.Operation:
1075
+ r"""Gets the latest state of a long-running operation.
1076
+
1077
+ Args:
1078
+ request (:class:`~.operations_pb2.GetOperationRequest`):
1079
+ The request object. Request message for
1080
+ `GetOperation` method.
1081
+ retry (google.api_core.retry.Retry): Designation of what errors,
1082
+ if any, should be retried.
1083
+ timeout (float): The timeout for this request.
1084
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1085
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1086
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1087
+ be of type `bytes`.
1088
+ Returns:
1089
+ ~.operations_pb2.Operation:
1090
+ An ``Operation`` object.
1091
+ """
1092
+ # Create or coerce a protobuf request object.
1093
+ # The request isn't a proto-plus wrapped type,
1094
+ # so it must be constructed via keyword expansion.
1095
+ if isinstance(request, dict):
1096
+ request = operations_pb2.GetOperationRequest(**request)
1097
+
1098
+ # Wrap the RPC method; this adds retry and timeout information,
1099
+ # and friendly error handling.
1100
+ rpc = self._transport._wrapped_methods[self._transport.get_operation]
1101
+
1102
+ # Certain fields should be provided within the metadata header;
1103
+ # add these here.
1104
+ metadata = tuple(metadata) + (
1105
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1106
+ )
1107
+
1108
+ # Validate the universe domain.
1109
+ self._validate_universe_domain()
1110
+
1111
+ # Send the request.
1112
+ response = rpc(
1113
+ request,
1114
+ retry=retry,
1115
+ timeout=timeout,
1116
+ metadata=metadata,
1117
+ )
1118
+
1119
+ # Done; return the response.
1120
+ return response
1121
+
1122
+
1123
+ DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
1124
+ gapic_version=package_version.__version__
1125
+ )
1126
+
1127
+
1128
+ __all__ = ("DiscussServiceClient",)
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/discuss_service/transports/grpc.py ADDED
@@ -0,0 +1,431 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ import json
17
+ import logging as std_logging
18
+ import pickle
19
+ from typing import Callable, Dict, Optional, Sequence, Tuple, Union
20
+ import warnings
21
+
22
+ from google.api_core import gapic_v1, grpc_helpers
23
+ import google.auth # type: ignore
24
+ from google.auth import credentials as ga_credentials # type: ignore
25
+ from google.auth.transport.grpc import SslCredentials # type: ignore
26
+ from google.longrunning import operations_pb2 # type: ignore
27
+ from google.protobuf.json_format import MessageToJson
28
+ import google.protobuf.message
29
+ import grpc # type: ignore
30
+ import proto # type: ignore
31
+
32
+ from google.ai.generativelanguage_v1beta.types import discuss_service
33
+
34
+ from .base import DEFAULT_CLIENT_INFO, DiscussServiceTransport
35
+
36
+ try:
37
+ from google.api_core import client_logging # type: ignore
38
+
39
+ CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
40
+ except ImportError: # pragma: NO COVER
41
+ CLIENT_LOGGING_SUPPORTED = False
42
+
43
+ _LOGGER = std_logging.getLogger(__name__)
44
+
45
+
46
+ class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER
47
+ def intercept_unary_unary(self, continuation, client_call_details, request):
48
+ logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
49
+ std_logging.DEBUG
50
+ )
51
+ if logging_enabled: # pragma: NO COVER
52
+ request_metadata = client_call_details.metadata
53
+ if isinstance(request, proto.Message):
54
+ request_payload = type(request).to_json(request)
55
+ elif isinstance(request, google.protobuf.message.Message):
56
+ request_payload = MessageToJson(request)
57
+ else:
58
+ request_payload = f"{type(request).__name__}: {pickle.dumps(request)}"
59
+
60
+ request_metadata = {
61
+ key: value.decode("utf-8") if isinstance(value, bytes) else value
62
+ for key, value in request_metadata
63
+ }
64
+ grpc_request = {
65
+ "payload": request_payload,
66
+ "requestMethod": "grpc",
67
+ "metadata": dict(request_metadata),
68
+ }
69
+ _LOGGER.debug(
70
+ f"Sending request for {client_call_details.method}",
71
+ extra={
72
+ "serviceName": "google.ai.generativelanguage.v1beta.DiscussService",
73
+ "rpcName": client_call_details.method,
74
+ "request": grpc_request,
75
+ "metadata": grpc_request["metadata"],
76
+ },
77
+ )
78
+
79
+ response = continuation(client_call_details, request)
80
+ if logging_enabled: # pragma: NO COVER
81
+ response_metadata = response.trailing_metadata()
82
+ # Convert gRPC metadata `<class 'grpc.aio._metadata.Metadata'>` to list of tuples
83
+ metadata = (
84
+ dict([(k, str(v)) for k, v in response_metadata])
85
+ if response_metadata
86
+ else None
87
+ )
88
+ result = response.result()
89
+ if isinstance(result, proto.Message):
90
+ response_payload = type(result).to_json(result)
91
+ elif isinstance(result, google.protobuf.message.Message):
92
+ response_payload = MessageToJson(result)
93
+ else:
94
+ response_payload = f"{type(result).__name__}: {pickle.dumps(result)}"
95
+ grpc_response = {
96
+ "payload": response_payload,
97
+ "metadata": metadata,
98
+ "status": "OK",
99
+ }
100
+ _LOGGER.debug(
101
+ f"Received response for {client_call_details.method}.",
102
+ extra={
103
+ "serviceName": "google.ai.generativelanguage.v1beta.DiscussService",
104
+ "rpcName": client_call_details.method,
105
+ "response": grpc_response,
106
+ "metadata": grpc_response["metadata"],
107
+ },
108
+ )
109
+ return response
110
+
111
+
112
+ class DiscussServiceGrpcTransport(DiscussServiceTransport):
113
+ """gRPC backend transport for DiscussService.
114
+
115
+ An API for using Generative Language Models (GLMs) in dialog
116
+ applications.
117
+ Also known as large language models (LLMs), this API provides
118
+ models that are trained for multi-turn dialog.
119
+
120
+ This class defines the same methods as the primary client, so the
121
+ primary client can load the underlying transport implementation
122
+ and call it.
123
+
124
+ It sends protocol buffers over the wire using gRPC (which is built on
125
+ top of HTTP/2); the ``grpcio`` package must be installed.
126
+ """
127
+
128
+ _stubs: Dict[str, Callable]
129
+
130
+ def __init__(
131
+ self,
132
+ *,
133
+ host: str = "generativelanguage.googleapis.com",
134
+ credentials: Optional[ga_credentials.Credentials] = None,
135
+ credentials_file: Optional[str] = None,
136
+ scopes: Optional[Sequence[str]] = None,
137
+ channel: Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]] = None,
138
+ api_mtls_endpoint: Optional[str] = None,
139
+ client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
140
+ ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None,
141
+ client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
142
+ quota_project_id: Optional[str] = None,
143
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
144
+ always_use_jwt_access: Optional[bool] = False,
145
+ api_audience: Optional[str] = None,
146
+ ) -> None:
147
+ """Instantiate the transport.
148
+
149
+ Args:
150
+ host (Optional[str]):
151
+ The hostname to connect to (default: 'generativelanguage.googleapis.com').
152
+ credentials (Optional[google.auth.credentials.Credentials]): The
153
+ authorization credentials to attach to requests. These
154
+ credentials identify the application to the service; if none
155
+ are specified, the client will attempt to ascertain the
156
+ credentials from the environment.
157
+ This argument is ignored if a ``channel`` instance is provided.
158
+ credentials_file (Optional[str]): A file with credentials that can
159
+ be loaded with :func:`google.auth.load_credentials_from_file`.
160
+ This argument is ignored if a ``channel`` instance is provided.
161
+ scopes (Optional(Sequence[str])): A list of scopes. This argument is
162
+ ignored if a ``channel`` instance is provided.
163
+ channel (Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]]):
164
+ A ``Channel`` instance through which to make calls, or a Callable
165
+ that constructs and returns one. If set to None, ``self.create_channel``
166
+ is used to create the channel. If a Callable is given, it will be called
167
+ with the same arguments as used in ``self.create_channel``.
168
+ api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint.
169
+ If provided, it overrides the ``host`` argument and tries to create
170
+ a mutual TLS channel with client SSL credentials from
171
+ ``client_cert_source`` or application default SSL credentials.
172
+ client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]):
173
+ Deprecated. A callback to provide client SSL certificate bytes and
174
+ private key bytes, both in PEM format. It is ignored if
175
+ ``api_mtls_endpoint`` is None.
176
+ ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials
177
+ for the grpc channel. It is ignored if a ``channel`` instance is provided.
178
+ client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]):
179
+ A callback to provide client certificate bytes and private key bytes,
180
+ both in PEM format. It is used to configure a mutual TLS channel. It is
181
+ ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided.
182
+ quota_project_id (Optional[str]): An optional project to use for billing
183
+ and quota.
184
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
185
+ The client info used to send a user-agent string along with
186
+ API requests. If ``None``, then default info will be used.
187
+ Generally, you only need to set this if you're developing
188
+ your own client library.
189
+ always_use_jwt_access (Optional[bool]): Whether self signed JWT should
190
+ be used for service account credentials.
191
+
192
+ Raises:
193
+ google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
194
+ creation failed for any reason.
195
+ google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
196
+ and ``credentials_file`` are passed.
197
+ """
198
+ self._grpc_channel = None
199
+ self._ssl_channel_credentials = ssl_channel_credentials
200
+ self._stubs: Dict[str, Callable] = {}
201
+
202
+ if api_mtls_endpoint:
203
+ warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
204
+ if client_cert_source:
205
+ warnings.warn("client_cert_source is deprecated", DeprecationWarning)
206
+
207
+ if isinstance(channel, grpc.Channel):
208
+ # Ignore credentials if a channel was passed.
209
+ credentials = None
210
+ self._ignore_credentials = True
211
+ # If a channel was explicitly provided, set it.
212
+ self._grpc_channel = channel
213
+ self._ssl_channel_credentials = None
214
+
215
+ else:
216
+ if api_mtls_endpoint:
217
+ host = api_mtls_endpoint
218
+
219
+ # Create SSL credentials with client_cert_source or application
220
+ # default SSL credentials.
221
+ if client_cert_source:
222
+ cert, key = client_cert_source()
223
+ self._ssl_channel_credentials = grpc.ssl_channel_credentials(
224
+ certificate_chain=cert, private_key=key
225
+ )
226
+ else:
227
+ self._ssl_channel_credentials = SslCredentials().ssl_credentials
228
+
229
+ else:
230
+ if client_cert_source_for_mtls and not ssl_channel_credentials:
231
+ cert, key = client_cert_source_for_mtls()
232
+ self._ssl_channel_credentials = grpc.ssl_channel_credentials(
233
+ certificate_chain=cert, private_key=key
234
+ )
235
+
236
+ # The base transport sets the host, credentials and scopes
237
+ super().__init__(
238
+ host=host,
239
+ credentials=credentials,
240
+ credentials_file=credentials_file,
241
+ scopes=scopes,
242
+ quota_project_id=quota_project_id,
243
+ client_info=client_info,
244
+ always_use_jwt_access=always_use_jwt_access,
245
+ api_audience=api_audience,
246
+ )
247
+
248
+ if not self._grpc_channel:
249
+ # initialize with the provided callable or the default channel
250
+ channel_init = channel or type(self).create_channel
251
+ self._grpc_channel = channel_init(
252
+ self._host,
253
+ # use the credentials which are saved
254
+ credentials=self._credentials,
255
+ # Set ``credentials_file`` to ``None`` here as
256
+ # the credentials that we saved earlier should be used.
257
+ credentials_file=None,
258
+ scopes=self._scopes,
259
+ ssl_credentials=self._ssl_channel_credentials,
260
+ quota_project_id=quota_project_id,
261
+ options=[
262
+ ("grpc.max_send_message_length", -1),
263
+ ("grpc.max_receive_message_length", -1),
264
+ ],
265
+ )
266
+
267
+ self._interceptor = _LoggingClientInterceptor()
268
+ self._logged_channel = grpc.intercept_channel(
269
+ self._grpc_channel, self._interceptor
270
+ )
271
+
272
+ # Wrap messages. This must be done after self._logged_channel exists
273
+ self._prep_wrapped_messages(client_info)
274
+
275
+ @classmethod
276
+ def create_channel(
277
+ cls,
278
+ host: str = "generativelanguage.googleapis.com",
279
+ credentials: Optional[ga_credentials.Credentials] = None,
280
+ credentials_file: Optional[str] = None,
281
+ scopes: Optional[Sequence[str]] = None,
282
+ quota_project_id: Optional[str] = None,
283
+ **kwargs,
284
+ ) -> grpc.Channel:
285
+ """Create and return a gRPC channel object.
286
+ Args:
287
+ host (Optional[str]): The host for the channel to use.
288
+ credentials (Optional[~.Credentials]): The
289
+ authorization credentials to attach to requests. These
290
+ credentials identify this application to the service. If
291
+ none are specified, the client will attempt to ascertain
292
+ the credentials from the environment.
293
+ credentials_file (Optional[str]): A file with credentials that can
294
+ be loaded with :func:`google.auth.load_credentials_from_file`.
295
+ This argument is mutually exclusive with credentials.
296
+ scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
297
+ service. These are only used when credentials are not specified and
298
+ are passed to :func:`google.auth.default`.
299
+ quota_project_id (Optional[str]): An optional project to use for billing
300
+ and quota.
301
+ kwargs (Optional[dict]): Keyword arguments, which are passed to the
302
+ channel creation.
303
+ Returns:
304
+ grpc.Channel: A gRPC channel object.
305
+
306
+ Raises:
307
+ google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
308
+ and ``credentials_file`` are passed.
309
+ """
310
+
311
+ return grpc_helpers.create_channel(
312
+ host,
313
+ credentials=credentials,
314
+ credentials_file=credentials_file,
315
+ quota_project_id=quota_project_id,
316
+ default_scopes=cls.AUTH_SCOPES,
317
+ scopes=scopes,
318
+ default_host=cls.DEFAULT_HOST,
319
+ **kwargs,
320
+ )
321
+
322
+ @property
323
+ def grpc_channel(self) -> grpc.Channel:
324
+ """Return the channel designed to connect to this service."""
325
+ return self._grpc_channel
326
+
327
+ @property
328
+ def generate_message(
329
+ self,
330
+ ) -> Callable[
331
+ [discuss_service.GenerateMessageRequest],
332
+ discuss_service.GenerateMessageResponse,
333
+ ]:
334
+ r"""Return a callable for the generate message method over gRPC.
335
+
336
+ Generates a response from the model given an input
337
+ ``MessagePrompt``.
338
+
339
+ Returns:
340
+ Callable[[~.GenerateMessageRequest],
341
+ ~.GenerateMessageResponse]:
342
+ A function that, when called, will call the underlying RPC
343
+ on the server.
344
+ """
345
+ # Generate a "stub function" on-the-fly which will actually make
346
+ # the request.
347
+ # gRPC handles serialization and deserialization, so we just need
348
+ # to pass in the functions for each.
349
+ if "generate_message" not in self._stubs:
350
+ self._stubs["generate_message"] = self._logged_channel.unary_unary(
351
+ "/google.ai.generativelanguage.v1beta.DiscussService/GenerateMessage",
352
+ request_serializer=discuss_service.GenerateMessageRequest.serialize,
353
+ response_deserializer=discuss_service.GenerateMessageResponse.deserialize,
354
+ )
355
+ return self._stubs["generate_message"]
356
+
357
+ @property
358
+ def count_message_tokens(
359
+ self,
360
+ ) -> Callable[
361
+ [discuss_service.CountMessageTokensRequest],
362
+ discuss_service.CountMessageTokensResponse,
363
+ ]:
364
+ r"""Return a callable for the count message tokens method over gRPC.
365
+
366
+ Runs a model's tokenizer on a string and returns the
367
+ token count.
368
+
369
+ Returns:
370
+ Callable[[~.CountMessageTokensRequest],
371
+ ~.CountMessageTokensResponse]:
372
+ A function that, when called, will call the underlying RPC
373
+ on the server.
374
+ """
375
+ # Generate a "stub function" on-the-fly which will actually make
376
+ # the request.
377
+ # gRPC handles serialization and deserialization, so we just need
378
+ # to pass in the functions for each.
379
+ if "count_message_tokens" not in self._stubs:
380
+ self._stubs["count_message_tokens"] = self._logged_channel.unary_unary(
381
+ "/google.ai.generativelanguage.v1beta.DiscussService/CountMessageTokens",
382
+ request_serializer=discuss_service.CountMessageTokensRequest.serialize,
383
+ response_deserializer=discuss_service.CountMessageTokensResponse.deserialize,
384
+ )
385
+ return self._stubs["count_message_tokens"]
386
+
387
+ def close(self):
388
+ self._logged_channel.close()
389
+
390
+ @property
391
+ def get_operation(
392
+ self,
393
+ ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]:
394
+ r"""Return a callable for the get_operation method over gRPC."""
395
+ # Generate a "stub function" on-the-fly which will actually make
396
+ # the request.
397
+ # gRPC handles serialization and deserialization, so we just need
398
+ # to pass in the functions for each.
399
+ if "get_operation" not in self._stubs:
400
+ self._stubs["get_operation"] = self._logged_channel.unary_unary(
401
+ "/google.longrunning.Operations/GetOperation",
402
+ request_serializer=operations_pb2.GetOperationRequest.SerializeToString,
403
+ response_deserializer=operations_pb2.Operation.FromString,
404
+ )
405
+ return self._stubs["get_operation"]
406
+
407
+ @property
408
+ def list_operations(
409
+ self,
410
+ ) -> Callable[
411
+ [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse
412
+ ]:
413
+ r"""Return a callable for the list_operations method over gRPC."""
414
+ # Generate a "stub function" on-the-fly which will actually make
415
+ # the request.
416
+ # gRPC handles serialization and deserialization, so we just need
417
+ # to pass in the functions for each.
418
+ if "list_operations" not in self._stubs:
419
+ self._stubs["list_operations"] = self._logged_channel.unary_unary(
420
+ "/google.longrunning.Operations/ListOperations",
421
+ request_serializer=operations_pb2.ListOperationsRequest.SerializeToString,
422
+ response_deserializer=operations_pb2.ListOperationsResponse.FromString,
423
+ )
424
+ return self._stubs["list_operations"]
425
+
426
+ @property
427
+ def kind(self) -> str:
428
+ return "grpc"
429
+
430
+
431
+ __all__ = ("DiscussServiceGrpcTransport",)
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/__init__.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ from .async_client import ModelServiceAsyncClient
17
+ from .client import ModelServiceClient
18
+
19
+ __all__ = (
20
+ "ModelServiceClient",
21
+ "ModelServiceAsyncClient",
22
+ )
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (402 Bytes). View file
 
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/__pycache__/async_client.cpython-311.pyc ADDED
Binary file (49.9 kB). View file
 
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/__pycache__/client.cpython-311.pyc ADDED
Binary file (66.1 kB). View file
 
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/__pycache__/pagers.cpython-311.pyc ADDED
Binary file (18.2 kB). View file
 
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/async_client.py ADDED
@@ -0,0 +1,1261 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ from collections import OrderedDict
17
+ import logging as std_logging
18
+ import re
19
+ from typing import (
20
+ Callable,
21
+ Dict,
22
+ Mapping,
23
+ MutableMapping,
24
+ MutableSequence,
25
+ Optional,
26
+ Sequence,
27
+ Tuple,
28
+ Type,
29
+ Union,
30
+ )
31
+
32
+ from google.api_core import exceptions as core_exceptions
33
+ from google.api_core import gapic_v1
34
+ from google.api_core import retry_async as retries
35
+ from google.api_core.client_options import ClientOptions
36
+ from google.auth import credentials as ga_credentials # type: ignore
37
+ from google.oauth2 import service_account # type: ignore
38
+
39
+ from google.ai.generativelanguage_v1beta import gapic_version as package_version
40
+
41
+ try:
42
+ OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None]
43
+ except AttributeError: # pragma: NO COVER
44
+ OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore
45
+
46
+ from google.api_core import operation # type: ignore
47
+ from google.api_core import operation_async # type: ignore
48
+ from google.longrunning import operations_pb2 # type: ignore
49
+ from google.protobuf import field_mask_pb2 # type: ignore
50
+ from google.protobuf import timestamp_pb2 # type: ignore
51
+
52
+ from google.ai.generativelanguage_v1beta.services.model_service import pagers
53
+ from google.ai.generativelanguage_v1beta.types import tuned_model as gag_tuned_model
54
+ from google.ai.generativelanguage_v1beta.types import model, model_service
55
+ from google.ai.generativelanguage_v1beta.types import tuned_model
56
+
57
+ from .client import ModelServiceClient
58
+ from .transports.base import DEFAULT_CLIENT_INFO, ModelServiceTransport
59
+ from .transports.grpc_asyncio import ModelServiceGrpcAsyncIOTransport
60
+
61
+ try:
62
+ from google.api_core import client_logging # type: ignore
63
+
64
+ CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
65
+ except ImportError: # pragma: NO COVER
66
+ CLIENT_LOGGING_SUPPORTED = False
67
+
68
+ _LOGGER = std_logging.getLogger(__name__)
69
+
70
+
71
+ class ModelServiceAsyncClient:
72
+ """Provides methods for getting metadata information about
73
+ Generative Models.
74
+ """
75
+
76
+ _client: ModelServiceClient
77
+
78
+ # Copy defaults from the synchronous client for use here.
79
+ # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead.
80
+ DEFAULT_ENDPOINT = ModelServiceClient.DEFAULT_ENDPOINT
81
+ DEFAULT_MTLS_ENDPOINT = ModelServiceClient.DEFAULT_MTLS_ENDPOINT
82
+ _DEFAULT_ENDPOINT_TEMPLATE = ModelServiceClient._DEFAULT_ENDPOINT_TEMPLATE
83
+ _DEFAULT_UNIVERSE = ModelServiceClient._DEFAULT_UNIVERSE
84
+
85
+ model_path = staticmethod(ModelServiceClient.model_path)
86
+ parse_model_path = staticmethod(ModelServiceClient.parse_model_path)
87
+ tuned_model_path = staticmethod(ModelServiceClient.tuned_model_path)
88
+ parse_tuned_model_path = staticmethod(ModelServiceClient.parse_tuned_model_path)
89
+ common_billing_account_path = staticmethod(
90
+ ModelServiceClient.common_billing_account_path
91
+ )
92
+ parse_common_billing_account_path = staticmethod(
93
+ ModelServiceClient.parse_common_billing_account_path
94
+ )
95
+ common_folder_path = staticmethod(ModelServiceClient.common_folder_path)
96
+ parse_common_folder_path = staticmethod(ModelServiceClient.parse_common_folder_path)
97
+ common_organization_path = staticmethod(ModelServiceClient.common_organization_path)
98
+ parse_common_organization_path = staticmethod(
99
+ ModelServiceClient.parse_common_organization_path
100
+ )
101
+ common_project_path = staticmethod(ModelServiceClient.common_project_path)
102
+ parse_common_project_path = staticmethod(
103
+ ModelServiceClient.parse_common_project_path
104
+ )
105
+ common_location_path = staticmethod(ModelServiceClient.common_location_path)
106
+ parse_common_location_path = staticmethod(
107
+ ModelServiceClient.parse_common_location_path
108
+ )
109
+
110
+ @classmethod
111
+ def from_service_account_info(cls, info: dict, *args, **kwargs):
112
+ """Creates an instance of this client using the provided credentials
113
+ info.
114
+
115
+ Args:
116
+ info (dict): The service account private key info.
117
+ args: Additional arguments to pass to the constructor.
118
+ kwargs: Additional arguments to pass to the constructor.
119
+
120
+ Returns:
121
+ ModelServiceAsyncClient: The constructed client.
122
+ """
123
+ return ModelServiceClient.from_service_account_info.__func__(ModelServiceAsyncClient, info, *args, **kwargs) # type: ignore
124
+
125
+ @classmethod
126
+ def from_service_account_file(cls, filename: str, *args, **kwargs):
127
+ """Creates an instance of this client using the provided credentials
128
+ file.
129
+
130
+ Args:
131
+ filename (str): The path to the service account private key json
132
+ file.
133
+ args: Additional arguments to pass to the constructor.
134
+ kwargs: Additional arguments to pass to the constructor.
135
+
136
+ Returns:
137
+ ModelServiceAsyncClient: The constructed client.
138
+ """
139
+ return ModelServiceClient.from_service_account_file.__func__(ModelServiceAsyncClient, filename, *args, **kwargs) # type: ignore
140
+
141
+ from_service_account_json = from_service_account_file
142
+
143
+ @classmethod
144
+ def get_mtls_endpoint_and_cert_source(
145
+ cls, client_options: Optional[ClientOptions] = None
146
+ ):
147
+ """Return the API endpoint and client cert source for mutual TLS.
148
+
149
+ The client cert source is determined in the following order:
150
+ (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
151
+ client cert source is None.
152
+ (2) if `client_options.client_cert_source` is provided, use the provided one; if the
153
+ default client cert source exists, use the default one; otherwise the client cert
154
+ source is None.
155
+
156
+ The API endpoint is determined in the following order:
157
+ (1) if `client_options.api_endpoint` if provided, use the provided one.
158
+ (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
159
+ default mTLS endpoint; if the environment variable is "never", use the default API
160
+ endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
161
+ use the default API endpoint.
162
+
163
+ More details can be found at https://google.aip.dev/auth/4114.
164
+
165
+ Args:
166
+ client_options (google.api_core.client_options.ClientOptions): Custom options for the
167
+ client. Only the `api_endpoint` and `client_cert_source` properties may be used
168
+ in this method.
169
+
170
+ Returns:
171
+ Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
172
+ client cert source to use.
173
+
174
+ Raises:
175
+ google.auth.exceptions.MutualTLSChannelError: If any errors happen.
176
+ """
177
+ return ModelServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore
178
+
179
+ @property
180
+ def transport(self) -> ModelServiceTransport:
181
+ """Returns the transport used by the client instance.
182
+
183
+ Returns:
184
+ ModelServiceTransport: The transport used by the client instance.
185
+ """
186
+ return self._client.transport
187
+
188
+ @property
189
+ def api_endpoint(self):
190
+ """Return the API endpoint used by the client instance.
191
+
192
+ Returns:
193
+ str: The API endpoint used by the client instance.
194
+ """
195
+ return self._client._api_endpoint
196
+
197
+ @property
198
+ def universe_domain(self) -> str:
199
+ """Return the universe domain used by the client instance.
200
+
201
+ Returns:
202
+ str: The universe domain used
203
+ by the client instance.
204
+ """
205
+ return self._client._universe_domain
206
+
207
+ get_transport_class = ModelServiceClient.get_transport_class
208
+
209
+ def __init__(
210
+ self,
211
+ *,
212
+ credentials: Optional[ga_credentials.Credentials] = None,
213
+ transport: Optional[
214
+ Union[str, ModelServiceTransport, Callable[..., ModelServiceTransport]]
215
+ ] = "grpc_asyncio",
216
+ client_options: Optional[ClientOptions] = None,
217
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
218
+ ) -> None:
219
+ """Instantiates the model service async client.
220
+
221
+ Args:
222
+ credentials (Optional[google.auth.credentials.Credentials]): The
223
+ authorization credentials to attach to requests. These
224
+ credentials identify the application to the service; if none
225
+ are specified, the client will attempt to ascertain the
226
+ credentials from the environment.
227
+ transport (Optional[Union[str,ModelServiceTransport,Callable[..., ModelServiceTransport]]]):
228
+ The transport to use, or a Callable that constructs and returns a new transport to use.
229
+ If a Callable is given, it will be called with the same set of initialization
230
+ arguments as used in the ModelServiceTransport constructor.
231
+ If set to None, a transport is chosen automatically.
232
+ client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]):
233
+ Custom options for the client.
234
+
235
+ 1. The ``api_endpoint`` property can be used to override the
236
+ default endpoint provided by the client when ``transport`` is
237
+ not explicitly provided. Only if this property is not set and
238
+ ``transport`` was not explicitly provided, the endpoint is
239
+ determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment
240
+ variable, which have one of the following values:
241
+ "always" (always use the default mTLS endpoint), "never" (always
242
+ use the default regular endpoint) and "auto" (auto-switch to the
243
+ default mTLS endpoint if client certificate is present; this is
244
+ the default value).
245
+
246
+ 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
247
+ is "true", then the ``client_cert_source`` property can be used
248
+ to provide a client certificate for mTLS transport. If
249
+ not provided, the default SSL client certificate will be used if
250
+ present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
251
+ set, no client certificate will be used.
252
+
253
+ 3. The ``universe_domain`` property can be used to override the
254
+ default "googleapis.com" universe. Note that ``api_endpoint``
255
+ property still takes precedence; and ``universe_domain`` is
256
+ currently not supported for mTLS.
257
+
258
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
259
+ The client info used to send a user-agent string along with
260
+ API requests. If ``None``, then default info will be used.
261
+ Generally, you only need to set this if you're developing
262
+ your own client library.
263
+
264
+ Raises:
265
+ google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
266
+ creation failed for any reason.
267
+ """
268
+ self._client = ModelServiceClient(
269
+ credentials=credentials,
270
+ transport=transport,
271
+ client_options=client_options,
272
+ client_info=client_info,
273
+ )
274
+
275
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
276
+ std_logging.DEBUG
277
+ ): # pragma: NO COVER
278
+ _LOGGER.debug(
279
+ "Created client `google.ai.generativelanguage_v1beta.ModelServiceAsyncClient`.",
280
+ extra={
281
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
282
+ "universeDomain": getattr(
283
+ self._client._transport._credentials, "universe_domain", ""
284
+ ),
285
+ "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}",
286
+ "credentialsInfo": getattr(
287
+ self.transport._credentials, "get_cred_info", lambda: None
288
+ )(),
289
+ }
290
+ if hasattr(self._client._transport, "_credentials")
291
+ else {
292
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
293
+ "credentialsType": None,
294
+ },
295
+ )
296
+
297
+ async def get_model(
298
+ self,
299
+ request: Optional[Union[model_service.GetModelRequest, dict]] = None,
300
+ *,
301
+ name: Optional[str] = None,
302
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
303
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
304
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
305
+ ) -> model.Model:
306
+ r"""Gets information about a specific ``Model`` such as its version
307
+ number, token limits,
308
+ `parameters <https://ai.google.dev/gemini-api/docs/models/generative-models#model-parameters>`__
309
+ and other metadata. Refer to the `Gemini models
310
+ guide <https://ai.google.dev/gemini-api/docs/models/gemini>`__
311
+ for detailed model information.
312
+
313
+ .. code-block:: python
314
+
315
+ # This snippet has been automatically generated and should be regarded as a
316
+ # code template only.
317
+ # It will require modifications to work:
318
+ # - It may require correct/in-range values for request initialization.
319
+ # - It may require specifying regional endpoints when creating the service
320
+ # client as shown in:
321
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
322
+ from google.ai import generativelanguage_v1beta
323
+
324
+ async def sample_get_model():
325
+ # Create a client
326
+ client = generativelanguage_v1beta.ModelServiceAsyncClient()
327
+
328
+ # Initialize request argument(s)
329
+ request = generativelanguage_v1beta.GetModelRequest(
330
+ name="name_value",
331
+ )
332
+
333
+ # Make the request
334
+ response = await client.get_model(request=request)
335
+
336
+ # Handle the response
337
+ print(response)
338
+
339
+ Args:
340
+ request (Optional[Union[google.ai.generativelanguage_v1beta.types.GetModelRequest, dict]]):
341
+ The request object. Request for getting information about
342
+ a specific Model.
343
+ name (:class:`str`):
344
+ Required. The resource name of the model.
345
+
346
+ This name should match a model name returned by the
347
+ ``ListModels`` method.
348
+
349
+ Format: ``models/{model}``
350
+
351
+ This corresponds to the ``name`` field
352
+ on the ``request`` instance; if ``request`` is provided, this
353
+ should not be set.
354
+ retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
355
+ should be retried.
356
+ timeout (float): The timeout for this request.
357
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
358
+ sent along with the request as metadata. Normally, each value must be of type `str`,
359
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
360
+ be of type `bytes`.
361
+
362
+ Returns:
363
+ google.ai.generativelanguage_v1beta.types.Model:
364
+ Information about a Generative
365
+ Language Model.
366
+
367
+ """
368
+ # Create or coerce a protobuf request object.
369
+ # - Quick check: If we got a request object, we should *not* have
370
+ # gotten any keyword arguments that map to the request.
371
+ has_flattened_params = any([name])
372
+ if request is not None and has_flattened_params:
373
+ raise ValueError(
374
+ "If the `request` argument is set, then none of "
375
+ "the individual field arguments should be set."
376
+ )
377
+
378
+ # - Use the request object if provided (there's no risk of modifying the input as
379
+ # there are no flattened fields), or create one.
380
+ if not isinstance(request, model_service.GetModelRequest):
381
+ request = model_service.GetModelRequest(request)
382
+
383
+ # If we have keyword arguments corresponding to fields on the
384
+ # request, apply these.
385
+ if name is not None:
386
+ request.name = name
387
+
388
+ # Wrap the RPC method; this adds retry and timeout information,
389
+ # and friendly error handling.
390
+ rpc = self._client._transport._wrapped_methods[
391
+ self._client._transport.get_model
392
+ ]
393
+
394
+ # Certain fields should be provided within the metadata header;
395
+ # add these here.
396
+ metadata = tuple(metadata) + (
397
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
398
+ )
399
+
400
+ # Validate the universe domain.
401
+ self._client._validate_universe_domain()
402
+
403
+ # Send the request.
404
+ response = await rpc(
405
+ request,
406
+ retry=retry,
407
+ timeout=timeout,
408
+ metadata=metadata,
409
+ )
410
+
411
+ # Done; return the response.
412
+ return response
413
+
414
+ async def list_models(
415
+ self,
416
+ request: Optional[Union[model_service.ListModelsRequest, dict]] = None,
417
+ *,
418
+ page_size: Optional[int] = None,
419
+ page_token: Optional[str] = None,
420
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
421
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
422
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
423
+ ) -> pagers.ListModelsAsyncPager:
424
+ r"""Lists the
425
+ ```Model``\ s <https://ai.google.dev/gemini-api/docs/models/gemini>`__
426
+ available through the Gemini API.
427
+
428
+ .. code-block:: python
429
+
430
+ # This snippet has been automatically generated and should be regarded as a
431
+ # code template only.
432
+ # It will require modifications to work:
433
+ # - It may require correct/in-range values for request initialization.
434
+ # - It may require specifying regional endpoints when creating the service
435
+ # client as shown in:
436
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
437
+ from google.ai import generativelanguage_v1beta
438
+
439
+ async def sample_list_models():
440
+ # Create a client
441
+ client = generativelanguage_v1beta.ModelServiceAsyncClient()
442
+
443
+ # Initialize request argument(s)
444
+ request = generativelanguage_v1beta.ListModelsRequest(
445
+ )
446
+
447
+ # Make the request
448
+ page_result = client.list_models(request=request)
449
+
450
+ # Handle the response
451
+ async for response in page_result:
452
+ print(response)
453
+
454
+ Args:
455
+ request (Optional[Union[google.ai.generativelanguage_v1beta.types.ListModelsRequest, dict]]):
456
+ The request object. Request for listing all Models.
457
+ page_size (:class:`int`):
458
+ The maximum number of ``Models`` to return (per page).
459
+
460
+ If unspecified, 50 models will be returned per page.
461
+ This method returns at most 1000 models per page, even
462
+ if you pass a larger page_size.
463
+
464
+ This corresponds to the ``page_size`` field
465
+ on the ``request`` instance; if ``request`` is provided, this
466
+ should not be set.
467
+ page_token (:class:`str`):
468
+ A page token, received from a previous ``ListModels``
469
+ call.
470
+
471
+ Provide the ``page_token`` returned by one request as an
472
+ argument to the next request to retrieve the next page.
473
+
474
+ When paginating, all other parameters provided to
475
+ ``ListModels`` must match the call that provided the
476
+ page token.
477
+
478
+ This corresponds to the ``page_token`` field
479
+ on the ``request`` instance; if ``request`` is provided, this
480
+ should not be set.
481
+ retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
482
+ should be retried.
483
+ timeout (float): The timeout for this request.
484
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
485
+ sent along with the request as metadata. Normally, each value must be of type `str`,
486
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
487
+ be of type `bytes`.
488
+
489
+ Returns:
490
+ google.ai.generativelanguage_v1beta.services.model_service.pagers.ListModelsAsyncPager:
491
+ Response from ListModel containing a paginated list of
492
+ Models.
493
+
494
+ Iterating over this object will yield results and
495
+ resolve additional pages automatically.
496
+
497
+ """
498
+ # Create or coerce a protobuf request object.
499
+ # - Quick check: If we got a request object, we should *not* have
500
+ # gotten any keyword arguments that map to the request.
501
+ has_flattened_params = any([page_size, page_token])
502
+ if request is not None and has_flattened_params:
503
+ raise ValueError(
504
+ "If the `request` argument is set, then none of "
505
+ "the individual field arguments should be set."
506
+ )
507
+
508
+ # - Use the request object if provided (there's no risk of modifying the input as
509
+ # there are no flattened fields), or create one.
510
+ if not isinstance(request, model_service.ListModelsRequest):
511
+ request = model_service.ListModelsRequest(request)
512
+
513
+ # If we have keyword arguments corresponding to fields on the
514
+ # request, apply these.
515
+ if page_size is not None:
516
+ request.page_size = page_size
517
+ if page_token is not None:
518
+ request.page_token = page_token
519
+
520
+ # Wrap the RPC method; this adds retry and timeout information,
521
+ # and friendly error handling.
522
+ rpc = self._client._transport._wrapped_methods[
523
+ self._client._transport.list_models
524
+ ]
525
+
526
+ # Validate the universe domain.
527
+ self._client._validate_universe_domain()
528
+
529
+ # Send the request.
530
+ response = await rpc(
531
+ request,
532
+ retry=retry,
533
+ timeout=timeout,
534
+ metadata=metadata,
535
+ )
536
+
537
+ # This method is paged; wrap the response in a pager, which provides
538
+ # an `__aiter__` convenience method.
539
+ response = pagers.ListModelsAsyncPager(
540
+ method=rpc,
541
+ request=request,
542
+ response=response,
543
+ retry=retry,
544
+ timeout=timeout,
545
+ metadata=metadata,
546
+ )
547
+
548
+ # Done; return the response.
549
+ return response
550
+
551
+ async def get_tuned_model(
552
+ self,
553
+ request: Optional[Union[model_service.GetTunedModelRequest, dict]] = None,
554
+ *,
555
+ name: Optional[str] = None,
556
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
557
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
558
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
559
+ ) -> tuned_model.TunedModel:
560
+ r"""Gets information about a specific TunedModel.
561
+
562
+ .. code-block:: python
563
+
564
+ # This snippet has been automatically generated and should be regarded as a
565
+ # code template only.
566
+ # It will require modifications to work:
567
+ # - It may require correct/in-range values for request initialization.
568
+ # - It may require specifying regional endpoints when creating the service
569
+ # client as shown in:
570
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
571
+ from google.ai import generativelanguage_v1beta
572
+
573
+ async def sample_get_tuned_model():
574
+ # Create a client
575
+ client = generativelanguage_v1beta.ModelServiceAsyncClient()
576
+
577
+ # Initialize request argument(s)
578
+ request = generativelanguage_v1beta.GetTunedModelRequest(
579
+ name="name_value",
580
+ )
581
+
582
+ # Make the request
583
+ response = await client.get_tuned_model(request=request)
584
+
585
+ # Handle the response
586
+ print(response)
587
+
588
+ Args:
589
+ request (Optional[Union[google.ai.generativelanguage_v1beta.types.GetTunedModelRequest, dict]]):
590
+ The request object. Request for getting information about
591
+ a specific Model.
592
+ name (:class:`str`):
593
+ Required. The resource name of the model.
594
+
595
+ Format: ``tunedModels/my-model-id``
596
+
597
+ This corresponds to the ``name`` field
598
+ on the ``request`` instance; if ``request`` is provided, this
599
+ should not be set.
600
+ retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
601
+ should be retried.
602
+ timeout (float): The timeout for this request.
603
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
604
+ sent along with the request as metadata. Normally, each value must be of type `str`,
605
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
606
+ be of type `bytes`.
607
+
608
+ Returns:
609
+ google.ai.generativelanguage_v1beta.types.TunedModel:
610
+ A fine-tuned model created using
611
+ ModelService.CreateTunedModel.
612
+
613
+ """
614
+ # Create or coerce a protobuf request object.
615
+ # - Quick check: If we got a request object, we should *not* have
616
+ # gotten any keyword arguments that map to the request.
617
+ has_flattened_params = any([name])
618
+ if request is not None and has_flattened_params:
619
+ raise ValueError(
620
+ "If the `request` argument is set, then none of "
621
+ "the individual field arguments should be set."
622
+ )
623
+
624
+ # - Use the request object if provided (there's no risk of modifying the input as
625
+ # there are no flattened fields), or create one.
626
+ if not isinstance(request, model_service.GetTunedModelRequest):
627
+ request = model_service.GetTunedModelRequest(request)
628
+
629
+ # If we have keyword arguments corresponding to fields on the
630
+ # request, apply these.
631
+ if name is not None:
632
+ request.name = name
633
+
634
+ # Wrap the RPC method; this adds retry and timeout information,
635
+ # and friendly error handling.
636
+ rpc = self._client._transport._wrapped_methods[
637
+ self._client._transport.get_tuned_model
638
+ ]
639
+
640
+ # Certain fields should be provided within the metadata header;
641
+ # add these here.
642
+ metadata = tuple(metadata) + (
643
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
644
+ )
645
+
646
+ # Validate the universe domain.
647
+ self._client._validate_universe_domain()
648
+
649
+ # Send the request.
650
+ response = await rpc(
651
+ request,
652
+ retry=retry,
653
+ timeout=timeout,
654
+ metadata=metadata,
655
+ )
656
+
657
+ # Done; return the response.
658
+ return response
659
+
660
+ async def list_tuned_models(
661
+ self,
662
+ request: Optional[Union[model_service.ListTunedModelsRequest, dict]] = None,
663
+ *,
664
+ page_size: Optional[int] = None,
665
+ page_token: Optional[str] = None,
666
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
667
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
668
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
669
+ ) -> pagers.ListTunedModelsAsyncPager:
670
+ r"""Lists created tuned models.
671
+
672
+ .. code-block:: python
673
+
674
+ # This snippet has been automatically generated and should be regarded as a
675
+ # code template only.
676
+ # It will require modifications to work:
677
+ # - It may require correct/in-range values for request initialization.
678
+ # - It may require specifying regional endpoints when creating the service
679
+ # client as shown in:
680
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
681
+ from google.ai import generativelanguage_v1beta
682
+
683
+ async def sample_list_tuned_models():
684
+ # Create a client
685
+ client = generativelanguage_v1beta.ModelServiceAsyncClient()
686
+
687
+ # Initialize request argument(s)
688
+ request = generativelanguage_v1beta.ListTunedModelsRequest(
689
+ )
690
+
691
+ # Make the request
692
+ page_result = client.list_tuned_models(request=request)
693
+
694
+ # Handle the response
695
+ async for response in page_result:
696
+ print(response)
697
+
698
+ Args:
699
+ request (Optional[Union[google.ai.generativelanguage_v1beta.types.ListTunedModelsRequest, dict]]):
700
+ The request object. Request for listing TunedModels.
701
+ page_size (:class:`int`):
702
+ Optional. The maximum number of ``TunedModels`` to
703
+ return (per page). The service may return fewer tuned
704
+ models.
705
+
706
+ If unspecified, at most 10 tuned models will be
707
+ returned. This method returns at most 1000 models per
708
+ page, even if you pass a larger page_size.
709
+
710
+ This corresponds to the ``page_size`` field
711
+ on the ``request`` instance; if ``request`` is provided, this
712
+ should not be set.
713
+ page_token (:class:`str`):
714
+ Optional. A page token, received from a previous
715
+ ``ListTunedModels`` call.
716
+
717
+ Provide the ``page_token`` returned by one request as an
718
+ argument to the next request to retrieve the next page.
719
+
720
+ When paginating, all other parameters provided to
721
+ ``ListTunedModels`` must match the call that provided
722
+ the page token.
723
+
724
+ This corresponds to the ``page_token`` field
725
+ on the ``request`` instance; if ``request`` is provided, this
726
+ should not be set.
727
+ retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
728
+ should be retried.
729
+ timeout (float): The timeout for this request.
730
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
731
+ sent along with the request as metadata. Normally, each value must be of type `str`,
732
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
733
+ be of type `bytes`.
734
+
735
+ Returns:
736
+ google.ai.generativelanguage_v1beta.services.model_service.pagers.ListTunedModelsAsyncPager:
737
+ Response from ListTunedModels containing a paginated
738
+ list of Models.
739
+
740
+ Iterating over this object will yield results and
741
+ resolve additional pages automatically.
742
+
743
+ """
744
+ # Create or coerce a protobuf request object.
745
+ # - Quick check: If we got a request object, we should *not* have
746
+ # gotten any keyword arguments that map to the request.
747
+ has_flattened_params = any([page_size, page_token])
748
+ if request is not None and has_flattened_params:
749
+ raise ValueError(
750
+ "If the `request` argument is set, then none of "
751
+ "the individual field arguments should be set."
752
+ )
753
+
754
+ # - Use the request object if provided (there's no risk of modifying the input as
755
+ # there are no flattened fields), or create one.
756
+ if not isinstance(request, model_service.ListTunedModelsRequest):
757
+ request = model_service.ListTunedModelsRequest(request)
758
+
759
+ # If we have keyword arguments corresponding to fields on the
760
+ # request, apply these.
761
+ if page_size is not None:
762
+ request.page_size = page_size
763
+ if page_token is not None:
764
+ request.page_token = page_token
765
+
766
+ # Wrap the RPC method; this adds retry and timeout information,
767
+ # and friendly error handling.
768
+ rpc = self._client._transport._wrapped_methods[
769
+ self._client._transport.list_tuned_models
770
+ ]
771
+
772
+ # Validate the universe domain.
773
+ self._client._validate_universe_domain()
774
+
775
+ # Send the request.
776
+ response = await rpc(
777
+ request,
778
+ retry=retry,
779
+ timeout=timeout,
780
+ metadata=metadata,
781
+ )
782
+
783
+ # This method is paged; wrap the response in a pager, which provides
784
+ # an `__aiter__` convenience method.
785
+ response = pagers.ListTunedModelsAsyncPager(
786
+ method=rpc,
787
+ request=request,
788
+ response=response,
789
+ retry=retry,
790
+ timeout=timeout,
791
+ metadata=metadata,
792
+ )
793
+
794
+ # Done; return the response.
795
+ return response
796
+
797
+ async def create_tuned_model(
798
+ self,
799
+ request: Optional[Union[model_service.CreateTunedModelRequest, dict]] = None,
800
+ *,
801
+ tuned_model: Optional[gag_tuned_model.TunedModel] = None,
802
+ tuned_model_id: Optional[str] = None,
803
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
804
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
805
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
806
+ ) -> operation_async.AsyncOperation:
807
+ r"""Creates a tuned model. Check intermediate tuning progress (if
808
+ any) through the [google.longrunning.Operations] service.
809
+
810
+ Access status and results through the Operations service.
811
+ Example: GET /v1/tunedModels/az2mb0bpw6i/operations/000-111-222
812
+
813
+ .. code-block:: python
814
+
815
+ # This snippet has been automatically generated and should be regarded as a
816
+ # code template only.
817
+ # It will require modifications to work:
818
+ # - It may require correct/in-range values for request initialization.
819
+ # - It may require specifying regional endpoints when creating the service
820
+ # client as shown in:
821
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
822
+ from google.ai import generativelanguage_v1beta
823
+
824
+ async def sample_create_tuned_model():
825
+ # Create a client
826
+ client = generativelanguage_v1beta.ModelServiceAsyncClient()
827
+
828
+ # Initialize request argument(s)
829
+ request = generativelanguage_v1beta.CreateTunedModelRequest(
830
+ )
831
+
832
+ # Make the request
833
+ operation = client.create_tuned_model(request=request)
834
+
835
+ print("Waiting for operation to complete...")
836
+
837
+ response = (await operation).result()
838
+
839
+ # Handle the response
840
+ print(response)
841
+
842
+ Args:
843
+ request (Optional[Union[google.ai.generativelanguage_v1beta.types.CreateTunedModelRequest, dict]]):
844
+ The request object. Request to create a TunedModel.
845
+ tuned_model (:class:`google.ai.generativelanguage_v1beta.types.TunedModel`):
846
+ Required. The tuned model to create.
847
+ This corresponds to the ``tuned_model`` field
848
+ on the ``request`` instance; if ``request`` is provided, this
849
+ should not be set.
850
+ tuned_model_id (:class:`str`):
851
+ Optional. The unique id for the tuned model if
852
+ specified. This value should be up to 40 characters, the
853
+ first character must be a letter, the last could be a
854
+ letter or a number. The id must match the regular
855
+ expression: ``[a-z]([a-z0-9-]{0,38}[a-z0-9])?``.
856
+
857
+ This corresponds to the ``tuned_model_id`` field
858
+ on the ``request`` instance; if ``request`` is provided, this
859
+ should not be set.
860
+ retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
861
+ should be retried.
862
+ timeout (float): The timeout for this request.
863
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
864
+ sent along with the request as metadata. Normally, each value must be of type `str`,
865
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
866
+ be of type `bytes`.
867
+
868
+ Returns:
869
+ google.api_core.operation_async.AsyncOperation:
870
+ An object representing a long-running operation.
871
+
872
+ The result type for the operation will be
873
+ :class:`google.ai.generativelanguage_v1beta.types.TunedModel`
874
+ A fine-tuned model created using
875
+ ModelService.CreateTunedModel.
876
+
877
+ """
878
+ # Create or coerce a protobuf request object.
879
+ # - Quick check: If we got a request object, we should *not* have
880
+ # gotten any keyword arguments that map to the request.
881
+ has_flattened_params = any([tuned_model, tuned_model_id])
882
+ if request is not None and has_flattened_params:
883
+ raise ValueError(
884
+ "If the `request` argument is set, then none of "
885
+ "the individual field arguments should be set."
886
+ )
887
+
888
+ # - Use the request object if provided (there's no risk of modifying the input as
889
+ # there are no flattened fields), or create one.
890
+ if not isinstance(request, model_service.CreateTunedModelRequest):
891
+ request = model_service.CreateTunedModelRequest(request)
892
+
893
+ # If we have keyword arguments corresponding to fields on the
894
+ # request, apply these.
895
+ if tuned_model is not None:
896
+ request.tuned_model = tuned_model
897
+ if tuned_model_id is not None:
898
+ request.tuned_model_id = tuned_model_id
899
+
900
+ # Wrap the RPC method; this adds retry and timeout information,
901
+ # and friendly error handling.
902
+ rpc = self._client._transport._wrapped_methods[
903
+ self._client._transport.create_tuned_model
904
+ ]
905
+
906
+ # Validate the universe domain.
907
+ self._client._validate_universe_domain()
908
+
909
+ # Send the request.
910
+ response = await rpc(
911
+ request,
912
+ retry=retry,
913
+ timeout=timeout,
914
+ metadata=metadata,
915
+ )
916
+
917
+ # Wrap the response in an operation future.
918
+ response = operation_async.from_gapic(
919
+ response,
920
+ self._client._transport.operations_client,
921
+ gag_tuned_model.TunedModel,
922
+ metadata_type=model_service.CreateTunedModelMetadata,
923
+ )
924
+
925
+ # Done; return the response.
926
+ return response
927
+
928
+ async def update_tuned_model(
929
+ self,
930
+ request: Optional[Union[model_service.UpdateTunedModelRequest, dict]] = None,
931
+ *,
932
+ tuned_model: Optional[gag_tuned_model.TunedModel] = None,
933
+ update_mask: Optional[field_mask_pb2.FieldMask] = None,
934
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
935
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
936
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
937
+ ) -> gag_tuned_model.TunedModel:
938
+ r"""Updates a tuned model.
939
+
940
+ .. code-block:: python
941
+
942
+ # This snippet has been automatically generated and should be regarded as a
943
+ # code template only.
944
+ # It will require modifications to work:
945
+ # - It may require correct/in-range values for request initialization.
946
+ # - It may require specifying regional endpoints when creating the service
947
+ # client as shown in:
948
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
949
+ from google.ai import generativelanguage_v1beta
950
+
951
+ async def sample_update_tuned_model():
952
+ # Create a client
953
+ client = generativelanguage_v1beta.ModelServiceAsyncClient()
954
+
955
+ # Initialize request argument(s)
956
+ request = generativelanguage_v1beta.UpdateTunedModelRequest(
957
+ )
958
+
959
+ # Make the request
960
+ response = await client.update_tuned_model(request=request)
961
+
962
+ # Handle the response
963
+ print(response)
964
+
965
+ Args:
966
+ request (Optional[Union[google.ai.generativelanguage_v1beta.types.UpdateTunedModelRequest, dict]]):
967
+ The request object. Request to update a TunedModel.
968
+ tuned_model (:class:`google.ai.generativelanguage_v1beta.types.TunedModel`):
969
+ Required. The tuned model to update.
970
+ This corresponds to the ``tuned_model`` field
971
+ on the ``request`` instance; if ``request`` is provided, this
972
+ should not be set.
973
+ update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`):
974
+ Optional. The list of fields to
975
+ update.
976
+
977
+ This corresponds to the ``update_mask`` field
978
+ on the ``request`` instance; if ``request`` is provided, this
979
+ should not be set.
980
+ retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
981
+ should be retried.
982
+ timeout (float): The timeout for this request.
983
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
984
+ sent along with the request as metadata. Normally, each value must be of type `str`,
985
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
986
+ be of type `bytes`.
987
+
988
+ Returns:
989
+ google.ai.generativelanguage_v1beta.types.TunedModel:
990
+ A fine-tuned model created using
991
+ ModelService.CreateTunedModel.
992
+
993
+ """
994
+ # Create or coerce a protobuf request object.
995
+ # - Quick check: If we got a request object, we should *not* have
996
+ # gotten any keyword arguments that map to the request.
997
+ has_flattened_params = any([tuned_model, update_mask])
998
+ if request is not None and has_flattened_params:
999
+ raise ValueError(
1000
+ "If the `request` argument is set, then none of "
1001
+ "the individual field arguments should be set."
1002
+ )
1003
+
1004
+ # - Use the request object if provided (there's no risk of modifying the input as
1005
+ # there are no flattened fields), or create one.
1006
+ if not isinstance(request, model_service.UpdateTunedModelRequest):
1007
+ request = model_service.UpdateTunedModelRequest(request)
1008
+
1009
+ # If we have keyword arguments corresponding to fields on the
1010
+ # request, apply these.
1011
+ if tuned_model is not None:
1012
+ request.tuned_model = tuned_model
1013
+ if update_mask is not None:
1014
+ request.update_mask = update_mask
1015
+
1016
+ # Wrap the RPC method; this adds retry and timeout information,
1017
+ # and friendly error handling.
1018
+ rpc = self._client._transport._wrapped_methods[
1019
+ self._client._transport.update_tuned_model
1020
+ ]
1021
+
1022
+ # Certain fields should be provided within the metadata header;
1023
+ # add these here.
1024
+ metadata = tuple(metadata) + (
1025
+ gapic_v1.routing_header.to_grpc_metadata(
1026
+ (("tuned_model.name", request.tuned_model.name),)
1027
+ ),
1028
+ )
1029
+
1030
+ # Validate the universe domain.
1031
+ self._client._validate_universe_domain()
1032
+
1033
+ # Send the request.
1034
+ response = await rpc(
1035
+ request,
1036
+ retry=retry,
1037
+ timeout=timeout,
1038
+ metadata=metadata,
1039
+ )
1040
+
1041
+ # Done; return the response.
1042
+ return response
1043
+
1044
+ async def delete_tuned_model(
1045
+ self,
1046
+ request: Optional[Union[model_service.DeleteTunedModelRequest, dict]] = None,
1047
+ *,
1048
+ name: Optional[str] = None,
1049
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1050
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1051
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1052
+ ) -> None:
1053
+ r"""Deletes a tuned model.
1054
+
1055
+ .. code-block:: python
1056
+
1057
+ # This snippet has been automatically generated and should be regarded as a
1058
+ # code template only.
1059
+ # It will require modifications to work:
1060
+ # - It may require correct/in-range values for request initialization.
1061
+ # - It may require specifying regional endpoints when creating the service
1062
+ # client as shown in:
1063
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1064
+ from google.ai import generativelanguage_v1beta
1065
+
1066
+ async def sample_delete_tuned_model():
1067
+ # Create a client
1068
+ client = generativelanguage_v1beta.ModelServiceAsyncClient()
1069
+
1070
+ # Initialize request argument(s)
1071
+ request = generativelanguage_v1beta.DeleteTunedModelRequest(
1072
+ name="name_value",
1073
+ )
1074
+
1075
+ # Make the request
1076
+ await client.delete_tuned_model(request=request)
1077
+
1078
+ Args:
1079
+ request (Optional[Union[google.ai.generativelanguage_v1beta.types.DeleteTunedModelRequest, dict]]):
1080
+ The request object. Request to delete a TunedModel.
1081
+ name (:class:`str`):
1082
+ Required. The resource name of the model. Format:
1083
+ ``tunedModels/my-model-id``
1084
+
1085
+ This corresponds to the ``name`` field
1086
+ on the ``request`` instance; if ``request`` is provided, this
1087
+ should not be set.
1088
+ retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
1089
+ should be retried.
1090
+ timeout (float): The timeout for this request.
1091
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1092
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1093
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1094
+ be of type `bytes`.
1095
+ """
1096
+ # Create or coerce a protobuf request object.
1097
+ # - Quick check: If we got a request object, we should *not* have
1098
+ # gotten any keyword arguments that map to the request.
1099
+ has_flattened_params = any([name])
1100
+ if request is not None and has_flattened_params:
1101
+ raise ValueError(
1102
+ "If the `request` argument is set, then none of "
1103
+ "the individual field arguments should be set."
1104
+ )
1105
+
1106
+ # - Use the request object if provided (there's no risk of modifying the input as
1107
+ # there are no flattened fields), or create one.
1108
+ if not isinstance(request, model_service.DeleteTunedModelRequest):
1109
+ request = model_service.DeleteTunedModelRequest(request)
1110
+
1111
+ # If we have keyword arguments corresponding to fields on the
1112
+ # request, apply these.
1113
+ if name is not None:
1114
+ request.name = name
1115
+
1116
+ # Wrap the RPC method; this adds retry and timeout information,
1117
+ # and friendly error handling.
1118
+ rpc = self._client._transport._wrapped_methods[
1119
+ self._client._transport.delete_tuned_model
1120
+ ]
1121
+
1122
+ # Certain fields should be provided within the metadata header;
1123
+ # add these here.
1124
+ metadata = tuple(metadata) + (
1125
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1126
+ )
1127
+
1128
+ # Validate the universe domain.
1129
+ self._client._validate_universe_domain()
1130
+
1131
+ # Send the request.
1132
+ await rpc(
1133
+ request,
1134
+ retry=retry,
1135
+ timeout=timeout,
1136
+ metadata=metadata,
1137
+ )
1138
+
1139
+ async def list_operations(
1140
+ self,
1141
+ request: Optional[operations_pb2.ListOperationsRequest] = None,
1142
+ *,
1143
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1144
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1145
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1146
+ ) -> operations_pb2.ListOperationsResponse:
1147
+ r"""Lists operations that match the specified filter in the request.
1148
+
1149
+ Args:
1150
+ request (:class:`~.operations_pb2.ListOperationsRequest`):
1151
+ The request object. Request message for
1152
+ `ListOperations` method.
1153
+ retry (google.api_core.retry_async.AsyncRetry): Designation of what errors,
1154
+ if any, should be retried.
1155
+ timeout (float): The timeout for this request.
1156
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1157
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1158
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1159
+ be of type `bytes`.
1160
+ Returns:
1161
+ ~.operations_pb2.ListOperationsResponse:
1162
+ Response message for ``ListOperations`` method.
1163
+ """
1164
+ # Create or coerce a protobuf request object.
1165
+ # The request isn't a proto-plus wrapped type,
1166
+ # so it must be constructed via keyword expansion.
1167
+ if isinstance(request, dict):
1168
+ request = operations_pb2.ListOperationsRequest(**request)
1169
+
1170
+ # Wrap the RPC method; this adds retry and timeout information,
1171
+ # and friendly error handling.
1172
+ rpc = self.transport._wrapped_methods[self._client._transport.list_operations]
1173
+
1174
+ # Certain fields should be provided within the metadata header;
1175
+ # add these here.
1176
+ metadata = tuple(metadata) + (
1177
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1178
+ )
1179
+
1180
+ # Validate the universe domain.
1181
+ self._client._validate_universe_domain()
1182
+
1183
+ # Send the request.
1184
+ response = await rpc(
1185
+ request,
1186
+ retry=retry,
1187
+ timeout=timeout,
1188
+ metadata=metadata,
1189
+ )
1190
+
1191
+ # Done; return the response.
1192
+ return response
1193
+
1194
+ async def get_operation(
1195
+ self,
1196
+ request: Optional[operations_pb2.GetOperationRequest] = None,
1197
+ *,
1198
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1199
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1200
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1201
+ ) -> operations_pb2.Operation:
1202
+ r"""Gets the latest state of a long-running operation.
1203
+
1204
+ Args:
1205
+ request (:class:`~.operations_pb2.GetOperationRequest`):
1206
+ The request object. Request message for
1207
+ `GetOperation` method.
1208
+ retry (google.api_core.retry_async.AsyncRetry): Designation of what errors,
1209
+ if any, should be retried.
1210
+ timeout (float): The timeout for this request.
1211
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1212
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1213
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1214
+ be of type `bytes`.
1215
+ Returns:
1216
+ ~.operations_pb2.Operation:
1217
+ An ``Operation`` object.
1218
+ """
1219
+ # Create or coerce a protobuf request object.
1220
+ # The request isn't a proto-plus wrapped type,
1221
+ # so it must be constructed via keyword expansion.
1222
+ if isinstance(request, dict):
1223
+ request = operations_pb2.GetOperationRequest(**request)
1224
+
1225
+ # Wrap the RPC method; this adds retry and timeout information,
1226
+ # and friendly error handling.
1227
+ rpc = self.transport._wrapped_methods[self._client._transport.get_operation]
1228
+
1229
+ # Certain fields should be provided within the metadata header;
1230
+ # add these here.
1231
+ metadata = tuple(metadata) + (
1232
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1233
+ )
1234
+
1235
+ # Validate the universe domain.
1236
+ self._client._validate_universe_domain()
1237
+
1238
+ # Send the request.
1239
+ response = await rpc(
1240
+ request,
1241
+ retry=retry,
1242
+ timeout=timeout,
1243
+ metadata=metadata,
1244
+ )
1245
+
1246
+ # Done; return the response.
1247
+ return response
1248
+
1249
+ async def __aenter__(self) -> "ModelServiceAsyncClient":
1250
+ return self
1251
+
1252
+ async def __aexit__(self, exc_type, exc, tb):
1253
+ await self.transport.close()
1254
+
1255
+
1256
+ DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
1257
+ gapic_version=package_version.__version__
1258
+ )
1259
+
1260
+
1261
+ __all__ = ("ModelServiceAsyncClient",)
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/client.py ADDED
@@ -0,0 +1,1646 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ from collections import OrderedDict
17
+ import logging as std_logging
18
+ import os
19
+ import re
20
+ from typing import (
21
+ Callable,
22
+ Dict,
23
+ Mapping,
24
+ MutableMapping,
25
+ MutableSequence,
26
+ Optional,
27
+ Sequence,
28
+ Tuple,
29
+ Type,
30
+ Union,
31
+ cast,
32
+ )
33
+ import warnings
34
+
35
+ from google.api_core import client_options as client_options_lib
36
+ from google.api_core import exceptions as core_exceptions
37
+ from google.api_core import gapic_v1
38
+ from google.api_core import retry as retries
39
+ from google.auth import credentials as ga_credentials # type: ignore
40
+ from google.auth.exceptions import MutualTLSChannelError # type: ignore
41
+ from google.auth.transport import mtls # type: ignore
42
+ from google.auth.transport.grpc import SslCredentials # type: ignore
43
+ from google.oauth2 import service_account # type: ignore
44
+
45
+ from google.ai.generativelanguage_v1beta import gapic_version as package_version
46
+
47
+ try:
48
+ OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
49
+ except AttributeError: # pragma: NO COVER
50
+ OptionalRetry = Union[retries.Retry, object, None] # type: ignore
51
+
52
+ try:
53
+ from google.api_core import client_logging # type: ignore
54
+
55
+ CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
56
+ except ImportError: # pragma: NO COVER
57
+ CLIENT_LOGGING_SUPPORTED = False
58
+
59
+ _LOGGER = std_logging.getLogger(__name__)
60
+
61
+ from google.api_core import operation # type: ignore
62
+ from google.api_core import operation_async # type: ignore
63
+ from google.longrunning import operations_pb2 # type: ignore
64
+ from google.protobuf import field_mask_pb2 # type: ignore
65
+ from google.protobuf import timestamp_pb2 # type: ignore
66
+
67
+ from google.ai.generativelanguage_v1beta.services.model_service import pagers
68
+ from google.ai.generativelanguage_v1beta.types import tuned_model as gag_tuned_model
69
+ from google.ai.generativelanguage_v1beta.types import model, model_service
70
+ from google.ai.generativelanguage_v1beta.types import tuned_model
71
+
72
+ from .transports.base import DEFAULT_CLIENT_INFO, ModelServiceTransport
73
+ from .transports.grpc import ModelServiceGrpcTransport
74
+ from .transports.grpc_asyncio import ModelServiceGrpcAsyncIOTransport
75
+ from .transports.rest import ModelServiceRestTransport
76
+
77
+
78
+ class ModelServiceClientMeta(type):
79
+ """Metaclass for the ModelService client.
80
+
81
+ This provides class-level methods for building and retrieving
82
+ support objects (e.g. transport) without polluting the client instance
83
+ objects.
84
+ """
85
+
86
+ _transport_registry = OrderedDict() # type: Dict[str, Type[ModelServiceTransport]]
87
+ _transport_registry["grpc"] = ModelServiceGrpcTransport
88
+ _transport_registry["grpc_asyncio"] = ModelServiceGrpcAsyncIOTransport
89
+ _transport_registry["rest"] = ModelServiceRestTransport
90
+
91
+ def get_transport_class(
92
+ cls,
93
+ label: Optional[str] = None,
94
+ ) -> Type[ModelServiceTransport]:
95
+ """Returns an appropriate transport class.
96
+
97
+ Args:
98
+ label: The name of the desired transport. If none is
99
+ provided, then the first transport in the registry is used.
100
+
101
+ Returns:
102
+ The transport class to use.
103
+ """
104
+ # If a specific transport is requested, return that one.
105
+ if label:
106
+ return cls._transport_registry[label]
107
+
108
+ # No transport is requested; return the default (that is, the first one
109
+ # in the dictionary).
110
+ return next(iter(cls._transport_registry.values()))
111
+
112
+
113
+ class ModelServiceClient(metaclass=ModelServiceClientMeta):
114
+ """Provides methods for getting metadata information about
115
+ Generative Models.
116
+ """
117
+
118
+ @staticmethod
119
+ def _get_default_mtls_endpoint(api_endpoint):
120
+ """Converts api endpoint to mTLS endpoint.
121
+
122
+ Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to
123
+ "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively.
124
+ Args:
125
+ api_endpoint (Optional[str]): the api endpoint to convert.
126
+ Returns:
127
+ str: converted mTLS api endpoint.
128
+ """
129
+ if not api_endpoint:
130
+ return api_endpoint
131
+
132
+ mtls_endpoint_re = re.compile(
133
+ r"(?P<name>[^.]+)(?P<mtls>\.mtls)?(?P<sandbox>\.sandbox)?(?P<googledomain>\.googleapis\.com)?"
134
+ )
135
+
136
+ m = mtls_endpoint_re.match(api_endpoint)
137
+ name, mtls, sandbox, googledomain = m.groups()
138
+ if mtls or not googledomain:
139
+ return api_endpoint
140
+
141
+ if sandbox:
142
+ return api_endpoint.replace(
143
+ "sandbox.googleapis.com", "mtls.sandbox.googleapis.com"
144
+ )
145
+
146
+ return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com")
147
+
148
+ # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead.
149
+ DEFAULT_ENDPOINT = "generativelanguage.googleapis.com"
150
+ DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore
151
+ DEFAULT_ENDPOINT
152
+ )
153
+
154
+ _DEFAULT_ENDPOINT_TEMPLATE = "generativelanguage.{UNIVERSE_DOMAIN}"
155
+ _DEFAULT_UNIVERSE = "googleapis.com"
156
+
157
+ @classmethod
158
+ def from_service_account_info(cls, info: dict, *args, **kwargs):
159
+ """Creates an instance of this client using the provided credentials
160
+ info.
161
+
162
+ Args:
163
+ info (dict): The service account private key info.
164
+ args: Additional arguments to pass to the constructor.
165
+ kwargs: Additional arguments to pass to the constructor.
166
+
167
+ Returns:
168
+ ModelServiceClient: The constructed client.
169
+ """
170
+ credentials = service_account.Credentials.from_service_account_info(info)
171
+ kwargs["credentials"] = credentials
172
+ return cls(*args, **kwargs)
173
+
174
+ @classmethod
175
+ def from_service_account_file(cls, filename: str, *args, **kwargs):
176
+ """Creates an instance of this client using the provided credentials
177
+ file.
178
+
179
+ Args:
180
+ filename (str): The path to the service account private key json
181
+ file.
182
+ args: Additional arguments to pass to the constructor.
183
+ kwargs: Additional arguments to pass to the constructor.
184
+
185
+ Returns:
186
+ ModelServiceClient: The constructed client.
187
+ """
188
+ credentials = service_account.Credentials.from_service_account_file(filename)
189
+ kwargs["credentials"] = credentials
190
+ return cls(*args, **kwargs)
191
+
192
+ from_service_account_json = from_service_account_file
193
+
194
+ @property
195
+ def transport(self) -> ModelServiceTransport:
196
+ """Returns the transport used by the client instance.
197
+
198
+ Returns:
199
+ ModelServiceTransport: The transport used by the client
200
+ instance.
201
+ """
202
+ return self._transport
203
+
204
+ @staticmethod
205
+ def model_path(
206
+ model: str,
207
+ ) -> str:
208
+ """Returns a fully-qualified model string."""
209
+ return "models/{model}".format(
210
+ model=model,
211
+ )
212
+
213
+ @staticmethod
214
+ def parse_model_path(path: str) -> Dict[str, str]:
215
+ """Parses a model path into its component segments."""
216
+ m = re.match(r"^models/(?P<model>.+?)$", path)
217
+ return m.groupdict() if m else {}
218
+
219
+ @staticmethod
220
+ def tuned_model_path(
221
+ tuned_model: str,
222
+ ) -> str:
223
+ """Returns a fully-qualified tuned_model string."""
224
+ return "tunedModels/{tuned_model}".format(
225
+ tuned_model=tuned_model,
226
+ )
227
+
228
+ @staticmethod
229
+ def parse_tuned_model_path(path: str) -> Dict[str, str]:
230
+ """Parses a tuned_model path into its component segments."""
231
+ m = re.match(r"^tunedModels/(?P<tuned_model>.+?)$", path)
232
+ return m.groupdict() if m else {}
233
+
234
+ @staticmethod
235
+ def common_billing_account_path(
236
+ billing_account: str,
237
+ ) -> str:
238
+ """Returns a fully-qualified billing_account string."""
239
+ return "billingAccounts/{billing_account}".format(
240
+ billing_account=billing_account,
241
+ )
242
+
243
+ @staticmethod
244
+ def parse_common_billing_account_path(path: str) -> Dict[str, str]:
245
+ """Parse a billing_account path into its component segments."""
246
+ m = re.match(r"^billingAccounts/(?P<billing_account>.+?)$", path)
247
+ return m.groupdict() if m else {}
248
+
249
+ @staticmethod
250
+ def common_folder_path(
251
+ folder: str,
252
+ ) -> str:
253
+ """Returns a fully-qualified folder string."""
254
+ return "folders/{folder}".format(
255
+ folder=folder,
256
+ )
257
+
258
+ @staticmethod
259
+ def parse_common_folder_path(path: str) -> Dict[str, str]:
260
+ """Parse a folder path into its component segments."""
261
+ m = re.match(r"^folders/(?P<folder>.+?)$", path)
262
+ return m.groupdict() if m else {}
263
+
264
+ @staticmethod
265
+ def common_organization_path(
266
+ organization: str,
267
+ ) -> str:
268
+ """Returns a fully-qualified organization string."""
269
+ return "organizations/{organization}".format(
270
+ organization=organization,
271
+ )
272
+
273
+ @staticmethod
274
+ def parse_common_organization_path(path: str) -> Dict[str, str]:
275
+ """Parse a organization path into its component segments."""
276
+ m = re.match(r"^organizations/(?P<organization>.+?)$", path)
277
+ return m.groupdict() if m else {}
278
+
279
+ @staticmethod
280
+ def common_project_path(
281
+ project: str,
282
+ ) -> str:
283
+ """Returns a fully-qualified project string."""
284
+ return "projects/{project}".format(
285
+ project=project,
286
+ )
287
+
288
+ @staticmethod
289
+ def parse_common_project_path(path: str) -> Dict[str, str]:
290
+ """Parse a project path into its component segments."""
291
+ m = re.match(r"^projects/(?P<project>.+?)$", path)
292
+ return m.groupdict() if m else {}
293
+
294
+ @staticmethod
295
+ def common_location_path(
296
+ project: str,
297
+ location: str,
298
+ ) -> str:
299
+ """Returns a fully-qualified location string."""
300
+ return "projects/{project}/locations/{location}".format(
301
+ project=project,
302
+ location=location,
303
+ )
304
+
305
+ @staticmethod
306
+ def parse_common_location_path(path: str) -> Dict[str, str]:
307
+ """Parse a location path into its component segments."""
308
+ m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path)
309
+ return m.groupdict() if m else {}
310
+
311
+ @classmethod
312
+ def get_mtls_endpoint_and_cert_source(
313
+ cls, client_options: Optional[client_options_lib.ClientOptions] = None
314
+ ):
315
+ """Deprecated. Return the API endpoint and client cert source for mutual TLS.
316
+
317
+ The client cert source is determined in the following order:
318
+ (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
319
+ client cert source is None.
320
+ (2) if `client_options.client_cert_source` is provided, use the provided one; if the
321
+ default client cert source exists, use the default one; otherwise the client cert
322
+ source is None.
323
+
324
+ The API endpoint is determined in the following order:
325
+ (1) if `client_options.api_endpoint` if provided, use the provided one.
326
+ (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
327
+ default mTLS endpoint; if the environment variable is "never", use the default API
328
+ endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
329
+ use the default API endpoint.
330
+
331
+ More details can be found at https://google.aip.dev/auth/4114.
332
+
333
+ Args:
334
+ client_options (google.api_core.client_options.ClientOptions): Custom options for the
335
+ client. Only the `api_endpoint` and `client_cert_source` properties may be used
336
+ in this method.
337
+
338
+ Returns:
339
+ Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
340
+ client cert source to use.
341
+
342
+ Raises:
343
+ google.auth.exceptions.MutualTLSChannelError: If any errors happen.
344
+ """
345
+
346
+ warnings.warn(
347
+ "get_mtls_endpoint_and_cert_source is deprecated. Use the api_endpoint property instead.",
348
+ DeprecationWarning,
349
+ )
350
+ if client_options is None:
351
+ client_options = client_options_lib.ClientOptions()
352
+ use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")
353
+ use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
354
+ if use_client_cert not in ("true", "false"):
355
+ raise ValueError(
356
+ "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
357
+ )
358
+ if use_mtls_endpoint not in ("auto", "never", "always"):
359
+ raise MutualTLSChannelError(
360
+ "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
361
+ )
362
+
363
+ # Figure out the client cert source to use.
364
+ client_cert_source = None
365
+ if use_client_cert == "true":
366
+ if client_options.client_cert_source:
367
+ client_cert_source = client_options.client_cert_source
368
+ elif mtls.has_default_client_cert_source():
369
+ client_cert_source = mtls.default_client_cert_source()
370
+
371
+ # Figure out which api endpoint to use.
372
+ if client_options.api_endpoint is not None:
373
+ api_endpoint = client_options.api_endpoint
374
+ elif use_mtls_endpoint == "always" or (
375
+ use_mtls_endpoint == "auto" and client_cert_source
376
+ ):
377
+ api_endpoint = cls.DEFAULT_MTLS_ENDPOINT
378
+ else:
379
+ api_endpoint = cls.DEFAULT_ENDPOINT
380
+
381
+ return api_endpoint, client_cert_source
382
+
383
+ @staticmethod
384
+ def _read_environment_variables():
385
+ """Returns the environment variables used by the client.
386
+
387
+ Returns:
388
+ Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE,
389
+ GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables.
390
+
391
+ Raises:
392
+ ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not
393
+ any of ["true", "false"].
394
+ google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT
395
+ is not any of ["auto", "never", "always"].
396
+ """
397
+ use_client_cert = os.getenv(
398
+ "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
399
+ ).lower()
400
+ use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower()
401
+ universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN")
402
+ if use_client_cert not in ("true", "false"):
403
+ raise ValueError(
404
+ "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
405
+ )
406
+ if use_mtls_endpoint not in ("auto", "never", "always"):
407
+ raise MutualTLSChannelError(
408
+ "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
409
+ )
410
+ return use_client_cert == "true", use_mtls_endpoint, universe_domain_env
411
+
412
+ @staticmethod
413
+ def _get_client_cert_source(provided_cert_source, use_cert_flag):
414
+ """Return the client cert source to be used by the client.
415
+
416
+ Args:
417
+ provided_cert_source (bytes): The client certificate source provided.
418
+ use_cert_flag (bool): A flag indicating whether to use the client certificate.
419
+
420
+ Returns:
421
+ bytes or None: The client cert source to be used by the client.
422
+ """
423
+ client_cert_source = None
424
+ if use_cert_flag:
425
+ if provided_cert_source:
426
+ client_cert_source = provided_cert_source
427
+ elif mtls.has_default_client_cert_source():
428
+ client_cert_source = mtls.default_client_cert_source()
429
+ return client_cert_source
430
+
431
+ @staticmethod
432
+ def _get_api_endpoint(
433
+ api_override, client_cert_source, universe_domain, use_mtls_endpoint
434
+ ):
435
+ """Return the API endpoint used by the client.
436
+
437
+ Args:
438
+ api_override (str): The API endpoint override. If specified, this is always
439
+ the return value of this function and the other arguments are not used.
440
+ client_cert_source (bytes): The client certificate source used by the client.
441
+ universe_domain (str): The universe domain used by the client.
442
+ use_mtls_endpoint (str): How to use the mTLS endpoint, which depends also on the other parameters.
443
+ Possible values are "always", "auto", or "never".
444
+
445
+ Returns:
446
+ str: The API endpoint to be used by the client.
447
+ """
448
+ if api_override is not None:
449
+ api_endpoint = api_override
450
+ elif use_mtls_endpoint == "always" or (
451
+ use_mtls_endpoint == "auto" and client_cert_source
452
+ ):
453
+ _default_universe = ModelServiceClient._DEFAULT_UNIVERSE
454
+ if universe_domain != _default_universe:
455
+ raise MutualTLSChannelError(
456
+ f"mTLS is not supported in any universe other than {_default_universe}."
457
+ )
458
+ api_endpoint = ModelServiceClient.DEFAULT_MTLS_ENDPOINT
459
+ else:
460
+ api_endpoint = ModelServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(
461
+ UNIVERSE_DOMAIN=universe_domain
462
+ )
463
+ return api_endpoint
464
+
465
+ @staticmethod
466
+ def _get_universe_domain(
467
+ client_universe_domain: Optional[str], universe_domain_env: Optional[str]
468
+ ) -> str:
469
+ """Return the universe domain used by the client.
470
+
471
+ Args:
472
+ client_universe_domain (Optional[str]): The universe domain configured via the client options.
473
+ universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable.
474
+
475
+ Returns:
476
+ str: The universe domain to be used by the client.
477
+
478
+ Raises:
479
+ ValueError: If the universe domain is an empty string.
480
+ """
481
+ universe_domain = ModelServiceClient._DEFAULT_UNIVERSE
482
+ if client_universe_domain is not None:
483
+ universe_domain = client_universe_domain
484
+ elif universe_domain_env is not None:
485
+ universe_domain = universe_domain_env
486
+ if len(universe_domain.strip()) == 0:
487
+ raise ValueError("Universe Domain cannot be an empty string.")
488
+ return universe_domain
489
+
490
+ def _validate_universe_domain(self):
491
+ """Validates client's and credentials' universe domains are consistent.
492
+
493
+ Returns:
494
+ bool: True iff the configured universe domain is valid.
495
+
496
+ Raises:
497
+ ValueError: If the configured universe domain is not valid.
498
+ """
499
+
500
+ # NOTE (b/349488459): universe validation is disabled until further notice.
501
+ return True
502
+
503
+ @property
504
+ def api_endpoint(self):
505
+ """Return the API endpoint used by the client instance.
506
+
507
+ Returns:
508
+ str: The API endpoint used by the client instance.
509
+ """
510
+ return self._api_endpoint
511
+
512
+ @property
513
+ def universe_domain(self) -> str:
514
+ """Return the universe domain used by the client instance.
515
+
516
+ Returns:
517
+ str: The universe domain used by the client instance.
518
+ """
519
+ return self._universe_domain
520
+
521
+ def __init__(
522
+ self,
523
+ *,
524
+ credentials: Optional[ga_credentials.Credentials] = None,
525
+ transport: Optional[
526
+ Union[str, ModelServiceTransport, Callable[..., ModelServiceTransport]]
527
+ ] = None,
528
+ client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None,
529
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
530
+ ) -> None:
531
+ """Instantiates the model service client.
532
+
533
+ Args:
534
+ credentials (Optional[google.auth.credentials.Credentials]): The
535
+ authorization credentials to attach to requests. These
536
+ credentials identify the application to the service; if none
537
+ are specified, the client will attempt to ascertain the
538
+ credentials from the environment.
539
+ transport (Optional[Union[str,ModelServiceTransport,Callable[..., ModelServiceTransport]]]):
540
+ The transport to use, or a Callable that constructs and returns a new transport.
541
+ If a Callable is given, it will be called with the same set of initialization
542
+ arguments as used in the ModelServiceTransport constructor.
543
+ If set to None, a transport is chosen automatically.
544
+ client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]):
545
+ Custom options for the client.
546
+
547
+ 1. The ``api_endpoint`` property can be used to override the
548
+ default endpoint provided by the client when ``transport`` is
549
+ not explicitly provided. Only if this property is not set and
550
+ ``transport`` was not explicitly provided, the endpoint is
551
+ determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment
552
+ variable, which have one of the following values:
553
+ "always" (always use the default mTLS endpoint), "never" (always
554
+ use the default regular endpoint) and "auto" (auto-switch to the
555
+ default mTLS endpoint if client certificate is present; this is
556
+ the default value).
557
+
558
+ 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
559
+ is "true", then the ``client_cert_source`` property can be used
560
+ to provide a client certificate for mTLS transport. If
561
+ not provided, the default SSL client certificate will be used if
562
+ present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
563
+ set, no client certificate will be used.
564
+
565
+ 3. The ``universe_domain`` property can be used to override the
566
+ default "googleapis.com" universe. Note that the ``api_endpoint``
567
+ property still takes precedence; and ``universe_domain`` is
568
+ currently not supported for mTLS.
569
+
570
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
571
+ The client info used to send a user-agent string along with
572
+ API requests. If ``None``, then default info will be used.
573
+ Generally, you only need to set this if you're developing
574
+ your own client library.
575
+
576
+ Raises:
577
+ google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
578
+ creation failed for any reason.
579
+ """
580
+ self._client_options = client_options
581
+ if isinstance(self._client_options, dict):
582
+ self._client_options = client_options_lib.from_dict(self._client_options)
583
+ if self._client_options is None:
584
+ self._client_options = client_options_lib.ClientOptions()
585
+ self._client_options = cast(
586
+ client_options_lib.ClientOptions, self._client_options
587
+ )
588
+
589
+ universe_domain_opt = getattr(self._client_options, "universe_domain", None)
590
+
591
+ (
592
+ self._use_client_cert,
593
+ self._use_mtls_endpoint,
594
+ self._universe_domain_env,
595
+ ) = ModelServiceClient._read_environment_variables()
596
+ self._client_cert_source = ModelServiceClient._get_client_cert_source(
597
+ self._client_options.client_cert_source, self._use_client_cert
598
+ )
599
+ self._universe_domain = ModelServiceClient._get_universe_domain(
600
+ universe_domain_opt, self._universe_domain_env
601
+ )
602
+ self._api_endpoint = None # updated below, depending on `transport`
603
+
604
+ # Initialize the universe domain validation.
605
+ self._is_universe_domain_valid = False
606
+
607
+ if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER
608
+ # Setup logging.
609
+ client_logging.initialize_logging()
610
+
611
+ api_key_value = getattr(self._client_options, "api_key", None)
612
+ if api_key_value and credentials:
613
+ raise ValueError(
614
+ "client_options.api_key and credentials are mutually exclusive"
615
+ )
616
+
617
+ # Save or instantiate the transport.
618
+ # Ordinarily, we provide the transport, but allowing a custom transport
619
+ # instance provides an extensibility point for unusual situations.
620
+ transport_provided = isinstance(transport, ModelServiceTransport)
621
+ if transport_provided:
622
+ # transport is a ModelServiceTransport instance.
623
+ if credentials or self._client_options.credentials_file or api_key_value:
624
+ raise ValueError(
625
+ "When providing a transport instance, "
626
+ "provide its credentials directly."
627
+ )
628
+ if self._client_options.scopes:
629
+ raise ValueError(
630
+ "When providing a transport instance, provide its scopes "
631
+ "directly."
632
+ )
633
+ self._transport = cast(ModelServiceTransport, transport)
634
+ self._api_endpoint = self._transport.host
635
+
636
+ self._api_endpoint = self._api_endpoint or ModelServiceClient._get_api_endpoint(
637
+ self._client_options.api_endpoint,
638
+ self._client_cert_source,
639
+ self._universe_domain,
640
+ self._use_mtls_endpoint,
641
+ )
642
+
643
+ if not transport_provided:
644
+ import google.auth._default # type: ignore
645
+
646
+ if api_key_value and hasattr(
647
+ google.auth._default, "get_api_key_credentials"
648
+ ):
649
+ credentials = google.auth._default.get_api_key_credentials(
650
+ api_key_value
651
+ )
652
+
653
+ transport_init: Union[
654
+ Type[ModelServiceTransport], Callable[..., ModelServiceTransport]
655
+ ] = (
656
+ ModelServiceClient.get_transport_class(transport)
657
+ if isinstance(transport, str) or transport is None
658
+ else cast(Callable[..., ModelServiceTransport], transport)
659
+ )
660
+ # initialize with the provided callable or the passed in class
661
+ self._transport = transport_init(
662
+ credentials=credentials,
663
+ credentials_file=self._client_options.credentials_file,
664
+ host=self._api_endpoint,
665
+ scopes=self._client_options.scopes,
666
+ client_cert_source_for_mtls=self._client_cert_source,
667
+ quota_project_id=self._client_options.quota_project_id,
668
+ client_info=client_info,
669
+ always_use_jwt_access=True,
670
+ api_audience=self._client_options.api_audience,
671
+ )
672
+
673
+ if "async" not in str(self._transport):
674
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
675
+ std_logging.DEBUG
676
+ ): # pragma: NO COVER
677
+ _LOGGER.debug(
678
+ "Created client `google.ai.generativelanguage_v1beta.ModelServiceClient`.",
679
+ extra={
680
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
681
+ "universeDomain": getattr(
682
+ self._transport._credentials, "universe_domain", ""
683
+ ),
684
+ "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}",
685
+ "credentialsInfo": getattr(
686
+ self.transport._credentials, "get_cred_info", lambda: None
687
+ )(),
688
+ }
689
+ if hasattr(self._transport, "_credentials")
690
+ else {
691
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
692
+ "credentialsType": None,
693
+ },
694
+ )
695
+
696
+ def get_model(
697
+ self,
698
+ request: Optional[Union[model_service.GetModelRequest, dict]] = None,
699
+ *,
700
+ name: Optional[str] = None,
701
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
702
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
703
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
704
+ ) -> model.Model:
705
+ r"""Gets information about a specific ``Model`` such as its version
706
+ number, token limits,
707
+ `parameters <https://ai.google.dev/gemini-api/docs/models/generative-models#model-parameters>`__
708
+ and other metadata. Refer to the `Gemini models
709
+ guide <https://ai.google.dev/gemini-api/docs/models/gemini>`__
710
+ for detailed model information.
711
+
712
+ .. code-block:: python
713
+
714
+ # This snippet has been automatically generated and should be regarded as a
715
+ # code template only.
716
+ # It will require modifications to work:
717
+ # - It may require correct/in-range values for request initialization.
718
+ # - It may require specifying regional endpoints when creating the service
719
+ # client as shown in:
720
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
721
+ from google.ai import generativelanguage_v1beta
722
+
723
+ def sample_get_model():
724
+ # Create a client
725
+ client = generativelanguage_v1beta.ModelServiceClient()
726
+
727
+ # Initialize request argument(s)
728
+ request = generativelanguage_v1beta.GetModelRequest(
729
+ name="name_value",
730
+ )
731
+
732
+ # Make the request
733
+ response = client.get_model(request=request)
734
+
735
+ # Handle the response
736
+ print(response)
737
+
738
+ Args:
739
+ request (Union[google.ai.generativelanguage_v1beta.types.GetModelRequest, dict]):
740
+ The request object. Request for getting information about
741
+ a specific Model.
742
+ name (str):
743
+ Required. The resource name of the model.
744
+
745
+ This name should match a model name returned by the
746
+ ``ListModels`` method.
747
+
748
+ Format: ``models/{model}``
749
+
750
+ This corresponds to the ``name`` field
751
+ on the ``request`` instance; if ``request`` is provided, this
752
+ should not be set.
753
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
754
+ should be retried.
755
+ timeout (float): The timeout for this request.
756
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
757
+ sent along with the request as metadata. Normally, each value must be of type `str`,
758
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
759
+ be of type `bytes`.
760
+
761
+ Returns:
762
+ google.ai.generativelanguage_v1beta.types.Model:
763
+ Information about a Generative
764
+ Language Model.
765
+
766
+ """
767
+ # Create or coerce a protobuf request object.
768
+ # - Quick check: If we got a request object, we should *not* have
769
+ # gotten any keyword arguments that map to the request.
770
+ has_flattened_params = any([name])
771
+ if request is not None and has_flattened_params:
772
+ raise ValueError(
773
+ "If the `request` argument is set, then none of "
774
+ "the individual field arguments should be set."
775
+ )
776
+
777
+ # - Use the request object if provided (there's no risk of modifying the input as
778
+ # there are no flattened fields), or create one.
779
+ if not isinstance(request, model_service.GetModelRequest):
780
+ request = model_service.GetModelRequest(request)
781
+ # If we have keyword arguments corresponding to fields on the
782
+ # request, apply these.
783
+ if name is not None:
784
+ request.name = name
785
+
786
+ # Wrap the RPC method; this adds retry and timeout information,
787
+ # and friendly error handling.
788
+ rpc = self._transport._wrapped_methods[self._transport.get_model]
789
+
790
+ # Certain fields should be provided within the metadata header;
791
+ # add these here.
792
+ metadata = tuple(metadata) + (
793
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
794
+ )
795
+
796
+ # Validate the universe domain.
797
+ self._validate_universe_domain()
798
+
799
+ # Send the request.
800
+ response = rpc(
801
+ request,
802
+ retry=retry,
803
+ timeout=timeout,
804
+ metadata=metadata,
805
+ )
806
+
807
+ # Done; return the response.
808
+ return response
809
+
810
+ def list_models(
811
+ self,
812
+ request: Optional[Union[model_service.ListModelsRequest, dict]] = None,
813
+ *,
814
+ page_size: Optional[int] = None,
815
+ page_token: Optional[str] = None,
816
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
817
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
818
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
819
+ ) -> pagers.ListModelsPager:
820
+ r"""Lists the
821
+ ```Model``\ s <https://ai.google.dev/gemini-api/docs/models/gemini>`__
822
+ available through the Gemini API.
823
+
824
+ .. code-block:: python
825
+
826
+ # This snippet has been automatically generated and should be regarded as a
827
+ # code template only.
828
+ # It will require modifications to work:
829
+ # - It may require correct/in-range values for request initialization.
830
+ # - It may require specifying regional endpoints when creating the service
831
+ # client as shown in:
832
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
833
+ from google.ai import generativelanguage_v1beta
834
+
835
+ def sample_list_models():
836
+ # Create a client
837
+ client = generativelanguage_v1beta.ModelServiceClient()
838
+
839
+ # Initialize request argument(s)
840
+ request = generativelanguage_v1beta.ListModelsRequest(
841
+ )
842
+
843
+ # Make the request
844
+ page_result = client.list_models(request=request)
845
+
846
+ # Handle the response
847
+ for response in page_result:
848
+ print(response)
849
+
850
+ Args:
851
+ request (Union[google.ai.generativelanguage_v1beta.types.ListModelsRequest, dict]):
852
+ The request object. Request for listing all Models.
853
+ page_size (int):
854
+ The maximum number of ``Models`` to return (per page).
855
+
856
+ If unspecified, 50 models will be returned per page.
857
+ This method returns at most 1000 models per page, even
858
+ if you pass a larger page_size.
859
+
860
+ This corresponds to the ``page_size`` field
861
+ on the ``request`` instance; if ``request`` is provided, this
862
+ should not be set.
863
+ page_token (str):
864
+ A page token, received from a previous ``ListModels``
865
+ call.
866
+
867
+ Provide the ``page_token`` returned by one request as an
868
+ argument to the next request to retrieve the next page.
869
+
870
+ When paginating, all other parameters provided to
871
+ ``ListModels`` must match the call that provided the
872
+ page token.
873
+
874
+ This corresponds to the ``page_token`` field
875
+ on the ``request`` instance; if ``request`` is provided, this
876
+ should not be set.
877
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
878
+ should be retried.
879
+ timeout (float): The timeout for this request.
880
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
881
+ sent along with the request as metadata. Normally, each value must be of type `str`,
882
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
883
+ be of type `bytes`.
884
+
885
+ Returns:
886
+ google.ai.generativelanguage_v1beta.services.model_service.pagers.ListModelsPager:
887
+ Response from ListModel containing a paginated list of
888
+ Models.
889
+
890
+ Iterating over this object will yield results and
891
+ resolve additional pages automatically.
892
+
893
+ """
894
+ # Create or coerce a protobuf request object.
895
+ # - Quick check: If we got a request object, we should *not* have
896
+ # gotten any keyword arguments that map to the request.
897
+ has_flattened_params = any([page_size, page_token])
898
+ if request is not None and has_flattened_params:
899
+ raise ValueError(
900
+ "If the `request` argument is set, then none of "
901
+ "the individual field arguments should be set."
902
+ )
903
+
904
+ # - Use the request object if provided (there's no risk of modifying the input as
905
+ # there are no flattened fields), or create one.
906
+ if not isinstance(request, model_service.ListModelsRequest):
907
+ request = model_service.ListModelsRequest(request)
908
+ # If we have keyword arguments corresponding to fields on the
909
+ # request, apply these.
910
+ if page_size is not None:
911
+ request.page_size = page_size
912
+ if page_token is not None:
913
+ request.page_token = page_token
914
+
915
+ # Wrap the RPC method; this adds retry and timeout information,
916
+ # and friendly error handling.
917
+ rpc = self._transport._wrapped_methods[self._transport.list_models]
918
+
919
+ # Validate the universe domain.
920
+ self._validate_universe_domain()
921
+
922
+ # Send the request.
923
+ response = rpc(
924
+ request,
925
+ retry=retry,
926
+ timeout=timeout,
927
+ metadata=metadata,
928
+ )
929
+
930
+ # This method is paged; wrap the response in a pager, which provides
931
+ # an `__iter__` convenience method.
932
+ response = pagers.ListModelsPager(
933
+ method=rpc,
934
+ request=request,
935
+ response=response,
936
+ retry=retry,
937
+ timeout=timeout,
938
+ metadata=metadata,
939
+ )
940
+
941
+ # Done; return the response.
942
+ return response
943
+
944
+ def get_tuned_model(
945
+ self,
946
+ request: Optional[Union[model_service.GetTunedModelRequest, dict]] = None,
947
+ *,
948
+ name: Optional[str] = None,
949
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
950
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
951
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
952
+ ) -> tuned_model.TunedModel:
953
+ r"""Gets information about a specific TunedModel.
954
+
955
+ .. code-block:: python
956
+
957
+ # This snippet has been automatically generated and should be regarded as a
958
+ # code template only.
959
+ # It will require modifications to work:
960
+ # - It may require correct/in-range values for request initialization.
961
+ # - It may require specifying regional endpoints when creating the service
962
+ # client as shown in:
963
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
964
+ from google.ai import generativelanguage_v1beta
965
+
966
+ def sample_get_tuned_model():
967
+ # Create a client
968
+ client = generativelanguage_v1beta.ModelServiceClient()
969
+
970
+ # Initialize request argument(s)
971
+ request = generativelanguage_v1beta.GetTunedModelRequest(
972
+ name="name_value",
973
+ )
974
+
975
+ # Make the request
976
+ response = client.get_tuned_model(request=request)
977
+
978
+ # Handle the response
979
+ print(response)
980
+
981
+ Args:
982
+ request (Union[google.ai.generativelanguage_v1beta.types.GetTunedModelRequest, dict]):
983
+ The request object. Request for getting information about
984
+ a specific Model.
985
+ name (str):
986
+ Required. The resource name of the model.
987
+
988
+ Format: ``tunedModels/my-model-id``
989
+
990
+ This corresponds to the ``name`` field
991
+ on the ``request`` instance; if ``request`` is provided, this
992
+ should not be set.
993
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
994
+ should be retried.
995
+ timeout (float): The timeout for this request.
996
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
997
+ sent along with the request as metadata. Normally, each value must be of type `str`,
998
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
999
+ be of type `bytes`.
1000
+
1001
+ Returns:
1002
+ google.ai.generativelanguage_v1beta.types.TunedModel:
1003
+ A fine-tuned model created using
1004
+ ModelService.CreateTunedModel.
1005
+
1006
+ """
1007
+ # Create or coerce a protobuf request object.
1008
+ # - Quick check: If we got a request object, we should *not* have
1009
+ # gotten any keyword arguments that map to the request.
1010
+ has_flattened_params = any([name])
1011
+ if request is not None and has_flattened_params:
1012
+ raise ValueError(
1013
+ "If the `request` argument is set, then none of "
1014
+ "the individual field arguments should be set."
1015
+ )
1016
+
1017
+ # - Use the request object if provided (there's no risk of modifying the input as
1018
+ # there are no flattened fields), or create one.
1019
+ if not isinstance(request, model_service.GetTunedModelRequest):
1020
+ request = model_service.GetTunedModelRequest(request)
1021
+ # If we have keyword arguments corresponding to fields on the
1022
+ # request, apply these.
1023
+ if name is not None:
1024
+ request.name = name
1025
+
1026
+ # Wrap the RPC method; this adds retry and timeout information,
1027
+ # and friendly error handling.
1028
+ rpc = self._transport._wrapped_methods[self._transport.get_tuned_model]
1029
+
1030
+ # Certain fields should be provided within the metadata header;
1031
+ # add these here.
1032
+ metadata = tuple(metadata) + (
1033
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1034
+ )
1035
+
1036
+ # Validate the universe domain.
1037
+ self._validate_universe_domain()
1038
+
1039
+ # Send the request.
1040
+ response = rpc(
1041
+ request,
1042
+ retry=retry,
1043
+ timeout=timeout,
1044
+ metadata=metadata,
1045
+ )
1046
+
1047
+ # Done; return the response.
1048
+ return response
1049
+
1050
+ def list_tuned_models(
1051
+ self,
1052
+ request: Optional[Union[model_service.ListTunedModelsRequest, dict]] = None,
1053
+ *,
1054
+ page_size: Optional[int] = None,
1055
+ page_token: Optional[str] = None,
1056
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1057
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1058
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1059
+ ) -> pagers.ListTunedModelsPager:
1060
+ r"""Lists created tuned models.
1061
+
1062
+ .. code-block:: python
1063
+
1064
+ # This snippet has been automatically generated and should be regarded as a
1065
+ # code template only.
1066
+ # It will require modifications to work:
1067
+ # - It may require correct/in-range values for request initialization.
1068
+ # - It may require specifying regional endpoints when creating the service
1069
+ # client as shown in:
1070
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1071
+ from google.ai import generativelanguage_v1beta
1072
+
1073
+ def sample_list_tuned_models():
1074
+ # Create a client
1075
+ client = generativelanguage_v1beta.ModelServiceClient()
1076
+
1077
+ # Initialize request argument(s)
1078
+ request = generativelanguage_v1beta.ListTunedModelsRequest(
1079
+ )
1080
+
1081
+ # Make the request
1082
+ page_result = client.list_tuned_models(request=request)
1083
+
1084
+ # Handle the response
1085
+ for response in page_result:
1086
+ print(response)
1087
+
1088
+ Args:
1089
+ request (Union[google.ai.generativelanguage_v1beta.types.ListTunedModelsRequest, dict]):
1090
+ The request object. Request for listing TunedModels.
1091
+ page_size (int):
1092
+ Optional. The maximum number of ``TunedModels`` to
1093
+ return (per page). The service may return fewer tuned
1094
+ models.
1095
+
1096
+ If unspecified, at most 10 tuned models will be
1097
+ returned. This method returns at most 1000 models per
1098
+ page, even if you pass a larger page_size.
1099
+
1100
+ This corresponds to the ``page_size`` field
1101
+ on the ``request`` instance; if ``request`` is provided, this
1102
+ should not be set.
1103
+ page_token (str):
1104
+ Optional. A page token, received from a previous
1105
+ ``ListTunedModels`` call.
1106
+
1107
+ Provide the ``page_token`` returned by one request as an
1108
+ argument to the next request to retrieve the next page.
1109
+
1110
+ When paginating, all other parameters provided to
1111
+ ``ListTunedModels`` must match the call that provided
1112
+ the page token.
1113
+
1114
+ This corresponds to the ``page_token`` field
1115
+ on the ``request`` instance; if ``request`` is provided, this
1116
+ should not be set.
1117
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1118
+ should be retried.
1119
+ timeout (float): The timeout for this request.
1120
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1121
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1122
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1123
+ be of type `bytes`.
1124
+
1125
+ Returns:
1126
+ google.ai.generativelanguage_v1beta.services.model_service.pagers.ListTunedModelsPager:
1127
+ Response from ListTunedModels containing a paginated
1128
+ list of Models.
1129
+
1130
+ Iterating over this object will yield results and
1131
+ resolve additional pages automatically.
1132
+
1133
+ """
1134
+ # Create or coerce a protobuf request object.
1135
+ # - Quick check: If we got a request object, we should *not* have
1136
+ # gotten any keyword arguments that map to the request.
1137
+ has_flattened_params = any([page_size, page_token])
1138
+ if request is not None and has_flattened_params:
1139
+ raise ValueError(
1140
+ "If the `request` argument is set, then none of "
1141
+ "the individual field arguments should be set."
1142
+ )
1143
+
1144
+ # - Use the request object if provided (there's no risk of modifying the input as
1145
+ # there are no flattened fields), or create one.
1146
+ if not isinstance(request, model_service.ListTunedModelsRequest):
1147
+ request = model_service.ListTunedModelsRequest(request)
1148
+ # If we have keyword arguments corresponding to fields on the
1149
+ # request, apply these.
1150
+ if page_size is not None:
1151
+ request.page_size = page_size
1152
+ if page_token is not None:
1153
+ request.page_token = page_token
1154
+
1155
+ # Wrap the RPC method; this adds retry and timeout information,
1156
+ # and friendly error handling.
1157
+ rpc = self._transport._wrapped_methods[self._transport.list_tuned_models]
1158
+
1159
+ # Validate the universe domain.
1160
+ self._validate_universe_domain()
1161
+
1162
+ # Send the request.
1163
+ response = rpc(
1164
+ request,
1165
+ retry=retry,
1166
+ timeout=timeout,
1167
+ metadata=metadata,
1168
+ )
1169
+
1170
+ # This method is paged; wrap the response in a pager, which provides
1171
+ # an `__iter__` convenience method.
1172
+ response = pagers.ListTunedModelsPager(
1173
+ method=rpc,
1174
+ request=request,
1175
+ response=response,
1176
+ retry=retry,
1177
+ timeout=timeout,
1178
+ metadata=metadata,
1179
+ )
1180
+
1181
+ # Done; return the response.
1182
+ return response
1183
+
1184
+ def create_tuned_model(
1185
+ self,
1186
+ request: Optional[Union[model_service.CreateTunedModelRequest, dict]] = None,
1187
+ *,
1188
+ tuned_model: Optional[gag_tuned_model.TunedModel] = None,
1189
+ tuned_model_id: Optional[str] = None,
1190
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1191
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1192
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1193
+ ) -> operation.Operation:
1194
+ r"""Creates a tuned model. Check intermediate tuning progress (if
1195
+ any) through the [google.longrunning.Operations] service.
1196
+
1197
+ Access status and results through the Operations service.
1198
+ Example: GET /v1/tunedModels/az2mb0bpw6i/operations/000-111-222
1199
+
1200
+ .. code-block:: python
1201
+
1202
+ # This snippet has been automatically generated and should be regarded as a
1203
+ # code template only.
1204
+ # It will require modifications to work:
1205
+ # - It may require correct/in-range values for request initialization.
1206
+ # - It may require specifying regional endpoints when creating the service
1207
+ # client as shown in:
1208
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1209
+ from google.ai import generativelanguage_v1beta
1210
+
1211
+ def sample_create_tuned_model():
1212
+ # Create a client
1213
+ client = generativelanguage_v1beta.ModelServiceClient()
1214
+
1215
+ # Initialize request argument(s)
1216
+ request = generativelanguage_v1beta.CreateTunedModelRequest(
1217
+ )
1218
+
1219
+ # Make the request
1220
+ operation = client.create_tuned_model(request=request)
1221
+
1222
+ print("Waiting for operation to complete...")
1223
+
1224
+ response = operation.result()
1225
+
1226
+ # Handle the response
1227
+ print(response)
1228
+
1229
+ Args:
1230
+ request (Union[google.ai.generativelanguage_v1beta.types.CreateTunedModelRequest, dict]):
1231
+ The request object. Request to create a TunedModel.
1232
+ tuned_model (google.ai.generativelanguage_v1beta.types.TunedModel):
1233
+ Required. The tuned model to create.
1234
+ This corresponds to the ``tuned_model`` field
1235
+ on the ``request`` instance; if ``request`` is provided, this
1236
+ should not be set.
1237
+ tuned_model_id (str):
1238
+ Optional. The unique id for the tuned model if
1239
+ specified. This value should be up to 40 characters, the
1240
+ first character must be a letter, the last could be a
1241
+ letter or a number. The id must match the regular
1242
+ expression: ``[a-z]([a-z0-9-]{0,38}[a-z0-9])?``.
1243
+
1244
+ This corresponds to the ``tuned_model_id`` field
1245
+ on the ``request`` instance; if ``request`` is provided, this
1246
+ should not be set.
1247
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1248
+ should be retried.
1249
+ timeout (float): The timeout for this request.
1250
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1251
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1252
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1253
+ be of type `bytes`.
1254
+
1255
+ Returns:
1256
+ google.api_core.operation.Operation:
1257
+ An object representing a long-running operation.
1258
+
1259
+ The result type for the operation will be
1260
+ :class:`google.ai.generativelanguage_v1beta.types.TunedModel`
1261
+ A fine-tuned model created using
1262
+ ModelService.CreateTunedModel.
1263
+
1264
+ """
1265
+ # Create or coerce a protobuf request object.
1266
+ # - Quick check: If we got a request object, we should *not* have
1267
+ # gotten any keyword arguments that map to the request.
1268
+ has_flattened_params = any([tuned_model, tuned_model_id])
1269
+ if request is not None and has_flattened_params:
1270
+ raise ValueError(
1271
+ "If the `request` argument is set, then none of "
1272
+ "the individual field arguments should be set."
1273
+ )
1274
+
1275
+ # - Use the request object if provided (there's no risk of modifying the input as
1276
+ # there are no flattened fields), or create one.
1277
+ if not isinstance(request, model_service.CreateTunedModelRequest):
1278
+ request = model_service.CreateTunedModelRequest(request)
1279
+ # If we have keyword arguments corresponding to fields on the
1280
+ # request, apply these.
1281
+ if tuned_model is not None:
1282
+ request.tuned_model = tuned_model
1283
+ if tuned_model_id is not None:
1284
+ request.tuned_model_id = tuned_model_id
1285
+
1286
+ # Wrap the RPC method; this adds retry and timeout information,
1287
+ # and friendly error handling.
1288
+ rpc = self._transport._wrapped_methods[self._transport.create_tuned_model]
1289
+
1290
+ # Validate the universe domain.
1291
+ self._validate_universe_domain()
1292
+
1293
+ # Send the request.
1294
+ response = rpc(
1295
+ request,
1296
+ retry=retry,
1297
+ timeout=timeout,
1298
+ metadata=metadata,
1299
+ )
1300
+
1301
+ # Wrap the response in an operation future.
1302
+ response = operation.from_gapic(
1303
+ response,
1304
+ self._transport.operations_client,
1305
+ gag_tuned_model.TunedModel,
1306
+ metadata_type=model_service.CreateTunedModelMetadata,
1307
+ )
1308
+
1309
+ # Done; return the response.
1310
+ return response
1311
+
1312
+ def update_tuned_model(
1313
+ self,
1314
+ request: Optional[Union[model_service.UpdateTunedModelRequest, dict]] = None,
1315
+ *,
1316
+ tuned_model: Optional[gag_tuned_model.TunedModel] = None,
1317
+ update_mask: Optional[field_mask_pb2.FieldMask] = None,
1318
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1319
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1320
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1321
+ ) -> gag_tuned_model.TunedModel:
1322
+ r"""Updates a tuned model.
1323
+
1324
+ .. code-block:: python
1325
+
1326
+ # This snippet has been automatically generated and should be regarded as a
1327
+ # code template only.
1328
+ # It will require modifications to work:
1329
+ # - It may require correct/in-range values for request initialization.
1330
+ # - It may require specifying regional endpoints when creating the service
1331
+ # client as shown in:
1332
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1333
+ from google.ai import generativelanguage_v1beta
1334
+
1335
+ def sample_update_tuned_model():
1336
+ # Create a client
1337
+ client = generativelanguage_v1beta.ModelServiceClient()
1338
+
1339
+ # Initialize request argument(s)
1340
+ request = generativelanguage_v1beta.UpdateTunedModelRequest(
1341
+ )
1342
+
1343
+ # Make the request
1344
+ response = client.update_tuned_model(request=request)
1345
+
1346
+ # Handle the response
1347
+ print(response)
1348
+
1349
+ Args:
1350
+ request (Union[google.ai.generativelanguage_v1beta.types.UpdateTunedModelRequest, dict]):
1351
+ The request object. Request to update a TunedModel.
1352
+ tuned_model (google.ai.generativelanguage_v1beta.types.TunedModel):
1353
+ Required. The tuned model to update.
1354
+ This corresponds to the ``tuned_model`` field
1355
+ on the ``request`` instance; if ``request`` is provided, this
1356
+ should not be set.
1357
+ update_mask (google.protobuf.field_mask_pb2.FieldMask):
1358
+ Optional. The list of fields to
1359
+ update.
1360
+
1361
+ This corresponds to the ``update_mask`` field
1362
+ on the ``request`` instance; if ``request`` is provided, this
1363
+ should not be set.
1364
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1365
+ should be retried.
1366
+ timeout (float): The timeout for this request.
1367
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1368
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1369
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1370
+ be of type `bytes`.
1371
+
1372
+ Returns:
1373
+ google.ai.generativelanguage_v1beta.types.TunedModel:
1374
+ A fine-tuned model created using
1375
+ ModelService.CreateTunedModel.
1376
+
1377
+ """
1378
+ # Create or coerce a protobuf request object.
1379
+ # - Quick check: If we got a request object, we should *not* have
1380
+ # gotten any keyword arguments that map to the request.
1381
+ has_flattened_params = any([tuned_model, update_mask])
1382
+ if request is not None and has_flattened_params:
1383
+ raise ValueError(
1384
+ "If the `request` argument is set, then none of "
1385
+ "the individual field arguments should be set."
1386
+ )
1387
+
1388
+ # - Use the request object if provided (there's no risk of modifying the input as
1389
+ # there are no flattened fields), or create one.
1390
+ if not isinstance(request, model_service.UpdateTunedModelRequest):
1391
+ request = model_service.UpdateTunedModelRequest(request)
1392
+ # If we have keyword arguments corresponding to fields on the
1393
+ # request, apply these.
1394
+ if tuned_model is not None:
1395
+ request.tuned_model = tuned_model
1396
+ if update_mask is not None:
1397
+ request.update_mask = update_mask
1398
+
1399
+ # Wrap the RPC method; this adds retry and timeout information,
1400
+ # and friendly error handling.
1401
+ rpc = self._transport._wrapped_methods[self._transport.update_tuned_model]
1402
+
1403
+ # Certain fields should be provided within the metadata header;
1404
+ # add these here.
1405
+ metadata = tuple(metadata) + (
1406
+ gapic_v1.routing_header.to_grpc_metadata(
1407
+ (("tuned_model.name", request.tuned_model.name),)
1408
+ ),
1409
+ )
1410
+
1411
+ # Validate the universe domain.
1412
+ self._validate_universe_domain()
1413
+
1414
+ # Send the request.
1415
+ response = rpc(
1416
+ request,
1417
+ retry=retry,
1418
+ timeout=timeout,
1419
+ metadata=metadata,
1420
+ )
1421
+
1422
+ # Done; return the response.
1423
+ return response
1424
+
1425
+ def delete_tuned_model(
1426
+ self,
1427
+ request: Optional[Union[model_service.DeleteTunedModelRequest, dict]] = None,
1428
+ *,
1429
+ name: Optional[str] = None,
1430
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1431
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1432
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1433
+ ) -> None:
1434
+ r"""Deletes a tuned model.
1435
+
1436
+ .. code-block:: python
1437
+
1438
+ # This snippet has been automatically generated and should be regarded as a
1439
+ # code template only.
1440
+ # It will require modifications to work:
1441
+ # - It may require correct/in-range values for request initialization.
1442
+ # - It may require specifying regional endpoints when creating the service
1443
+ # client as shown in:
1444
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1445
+ from google.ai import generativelanguage_v1beta
1446
+
1447
+ def sample_delete_tuned_model():
1448
+ # Create a client
1449
+ client = generativelanguage_v1beta.ModelServiceClient()
1450
+
1451
+ # Initialize request argument(s)
1452
+ request = generativelanguage_v1beta.DeleteTunedModelRequest(
1453
+ name="name_value",
1454
+ )
1455
+
1456
+ # Make the request
1457
+ client.delete_tuned_model(request=request)
1458
+
1459
+ Args:
1460
+ request (Union[google.ai.generativelanguage_v1beta.types.DeleteTunedModelRequest, dict]):
1461
+ The request object. Request to delete a TunedModel.
1462
+ name (str):
1463
+ Required. The resource name of the model. Format:
1464
+ ``tunedModels/my-model-id``
1465
+
1466
+ This corresponds to the ``name`` field
1467
+ on the ``request`` instance; if ``request`` is provided, this
1468
+ should not be set.
1469
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1470
+ should be retried.
1471
+ timeout (float): The timeout for this request.
1472
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1473
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1474
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1475
+ be of type `bytes`.
1476
+ """
1477
+ # Create or coerce a protobuf request object.
1478
+ # - Quick check: If we got a request object, we should *not* have
1479
+ # gotten any keyword arguments that map to the request.
1480
+ has_flattened_params = any([name])
1481
+ if request is not None and has_flattened_params:
1482
+ raise ValueError(
1483
+ "If the `request` argument is set, then none of "
1484
+ "the individual field arguments should be set."
1485
+ )
1486
+
1487
+ # - Use the request object if provided (there's no risk of modifying the input as
1488
+ # there are no flattened fields), or create one.
1489
+ if not isinstance(request, model_service.DeleteTunedModelRequest):
1490
+ request = model_service.DeleteTunedModelRequest(request)
1491
+ # If we have keyword arguments corresponding to fields on the
1492
+ # request, apply these.
1493
+ if name is not None:
1494
+ request.name = name
1495
+
1496
+ # Wrap the RPC method; this adds retry and timeout information,
1497
+ # and friendly error handling.
1498
+ rpc = self._transport._wrapped_methods[self._transport.delete_tuned_model]
1499
+
1500
+ # Certain fields should be provided within the metadata header;
1501
+ # add these here.
1502
+ metadata = tuple(metadata) + (
1503
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1504
+ )
1505
+
1506
+ # Validate the universe domain.
1507
+ self._validate_universe_domain()
1508
+
1509
+ # Send the request.
1510
+ rpc(
1511
+ request,
1512
+ retry=retry,
1513
+ timeout=timeout,
1514
+ metadata=metadata,
1515
+ )
1516
+
1517
+ def __enter__(self) -> "ModelServiceClient":
1518
+ return self
1519
+
1520
+ def __exit__(self, type, value, traceback):
1521
+ """Releases underlying transport's resources.
1522
+
1523
+ .. warning::
1524
+ ONLY use as a context manager if the transport is NOT shared
1525
+ with other clients! Exiting the with block will CLOSE the transport
1526
+ and may cause errors in other clients!
1527
+ """
1528
+ self.transport.close()
1529
+
1530
+ def list_operations(
1531
+ self,
1532
+ request: Optional[operations_pb2.ListOperationsRequest] = None,
1533
+ *,
1534
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1535
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1536
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1537
+ ) -> operations_pb2.ListOperationsResponse:
1538
+ r"""Lists operations that match the specified filter in the request.
1539
+
1540
+ Args:
1541
+ request (:class:`~.operations_pb2.ListOperationsRequest`):
1542
+ The request object. Request message for
1543
+ `ListOperations` method.
1544
+ retry (google.api_core.retry.Retry): Designation of what errors,
1545
+ if any, should be retried.
1546
+ timeout (float): The timeout for this request.
1547
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1548
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1549
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1550
+ be of type `bytes`.
1551
+ Returns:
1552
+ ~.operations_pb2.ListOperationsResponse:
1553
+ Response message for ``ListOperations`` method.
1554
+ """
1555
+ # Create or coerce a protobuf request object.
1556
+ # The request isn't a proto-plus wrapped type,
1557
+ # so it must be constructed via keyword expansion.
1558
+ if isinstance(request, dict):
1559
+ request = operations_pb2.ListOperationsRequest(**request)
1560
+
1561
+ # Wrap the RPC method; this adds retry and timeout information,
1562
+ # and friendly error handling.
1563
+ rpc = self._transport._wrapped_methods[self._transport.list_operations]
1564
+
1565
+ # Certain fields should be provided within the metadata header;
1566
+ # add these here.
1567
+ metadata = tuple(metadata) + (
1568
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1569
+ )
1570
+
1571
+ # Validate the universe domain.
1572
+ self._validate_universe_domain()
1573
+
1574
+ # Send the request.
1575
+ response = rpc(
1576
+ request,
1577
+ retry=retry,
1578
+ timeout=timeout,
1579
+ metadata=metadata,
1580
+ )
1581
+
1582
+ # Done; return the response.
1583
+ return response
1584
+
1585
+ def get_operation(
1586
+ self,
1587
+ request: Optional[operations_pb2.GetOperationRequest] = None,
1588
+ *,
1589
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1590
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1591
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1592
+ ) -> operations_pb2.Operation:
1593
+ r"""Gets the latest state of a long-running operation.
1594
+
1595
+ Args:
1596
+ request (:class:`~.operations_pb2.GetOperationRequest`):
1597
+ The request object. Request message for
1598
+ `GetOperation` method.
1599
+ retry (google.api_core.retry.Retry): Designation of what errors,
1600
+ if any, should be retried.
1601
+ timeout (float): The timeout for this request.
1602
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1603
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1604
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1605
+ be of type `bytes`.
1606
+ Returns:
1607
+ ~.operations_pb2.Operation:
1608
+ An ``Operation`` object.
1609
+ """
1610
+ # Create or coerce a protobuf request object.
1611
+ # The request isn't a proto-plus wrapped type,
1612
+ # so it must be constructed via keyword expansion.
1613
+ if isinstance(request, dict):
1614
+ request = operations_pb2.GetOperationRequest(**request)
1615
+
1616
+ # Wrap the RPC method; this adds retry and timeout information,
1617
+ # and friendly error handling.
1618
+ rpc = self._transport._wrapped_methods[self._transport.get_operation]
1619
+
1620
+ # Certain fields should be provided within the metadata header;
1621
+ # add these here.
1622
+ metadata = tuple(metadata) + (
1623
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1624
+ )
1625
+
1626
+ # Validate the universe domain.
1627
+ self._validate_universe_domain()
1628
+
1629
+ # Send the request.
1630
+ response = rpc(
1631
+ request,
1632
+ retry=retry,
1633
+ timeout=timeout,
1634
+ metadata=metadata,
1635
+ )
1636
+
1637
+ # Done; return the response.
1638
+ return response
1639
+
1640
+
1641
+ DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
1642
+ gapic_version=package_version.__version__
1643
+ )
1644
+
1645
+
1646
+ __all__ = ("ModelServiceClient",)
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/pagers.py ADDED
@@ -0,0 +1,353 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ from typing import (
17
+ Any,
18
+ AsyncIterator,
19
+ Awaitable,
20
+ Callable,
21
+ Iterator,
22
+ Optional,
23
+ Sequence,
24
+ Tuple,
25
+ Union,
26
+ )
27
+
28
+ from google.api_core import gapic_v1
29
+ from google.api_core import retry as retries
30
+ from google.api_core import retry_async as retries_async
31
+
32
+ try:
33
+ OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
34
+ OptionalAsyncRetry = Union[
35
+ retries_async.AsyncRetry, gapic_v1.method._MethodDefault, None
36
+ ]
37
+ except AttributeError: # pragma: NO COVER
38
+ OptionalRetry = Union[retries.Retry, object, None] # type: ignore
39
+ OptionalAsyncRetry = Union[retries_async.AsyncRetry, object, None] # type: ignore
40
+
41
+ from google.ai.generativelanguage_v1beta.types import model, model_service, tuned_model
42
+
43
+
44
+ class ListModelsPager:
45
+ """A pager for iterating through ``list_models`` requests.
46
+
47
+ This class thinly wraps an initial
48
+ :class:`google.ai.generativelanguage_v1beta.types.ListModelsResponse` object, and
49
+ provides an ``__iter__`` method to iterate through its
50
+ ``models`` field.
51
+
52
+ If there are more pages, the ``__iter__`` method will make additional
53
+ ``ListModels`` requests and continue to iterate
54
+ through the ``models`` field on the
55
+ corresponding responses.
56
+
57
+ All the usual :class:`google.ai.generativelanguage_v1beta.types.ListModelsResponse`
58
+ attributes are available on the pager. If multiple requests are made, only
59
+ the most recent response is retained, and thus used for attribute lookup.
60
+ """
61
+
62
+ def __init__(
63
+ self,
64
+ method: Callable[..., model_service.ListModelsResponse],
65
+ request: model_service.ListModelsRequest,
66
+ response: model_service.ListModelsResponse,
67
+ *,
68
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
69
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
70
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
71
+ ):
72
+ """Instantiate the pager.
73
+
74
+ Args:
75
+ method (Callable): The method that was originally called, and
76
+ which instantiated this pager.
77
+ request (google.ai.generativelanguage_v1beta.types.ListModelsRequest):
78
+ The initial request object.
79
+ response (google.ai.generativelanguage_v1beta.types.ListModelsResponse):
80
+ The initial response object.
81
+ retry (google.api_core.retry.Retry): Designation of what errors,
82
+ if any, should be retried.
83
+ timeout (float): The timeout for this request.
84
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
85
+ sent along with the request as metadata. Normally, each value must be of type `str`,
86
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
87
+ be of type `bytes`.
88
+ """
89
+ self._method = method
90
+ self._request = model_service.ListModelsRequest(request)
91
+ self._response = response
92
+ self._retry = retry
93
+ self._timeout = timeout
94
+ self._metadata = metadata
95
+
96
+ def __getattr__(self, name: str) -> Any:
97
+ return getattr(self._response, name)
98
+
99
+ @property
100
+ def pages(self) -> Iterator[model_service.ListModelsResponse]:
101
+ yield self._response
102
+ while self._response.next_page_token:
103
+ self._request.page_token = self._response.next_page_token
104
+ self._response = self._method(
105
+ self._request,
106
+ retry=self._retry,
107
+ timeout=self._timeout,
108
+ metadata=self._metadata,
109
+ )
110
+ yield self._response
111
+
112
+ def __iter__(self) -> Iterator[model.Model]:
113
+ for page in self.pages:
114
+ yield from page.models
115
+
116
+ def __repr__(self) -> str:
117
+ return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
118
+
119
+
120
+ class ListModelsAsyncPager:
121
+ """A pager for iterating through ``list_models`` requests.
122
+
123
+ This class thinly wraps an initial
124
+ :class:`google.ai.generativelanguage_v1beta.types.ListModelsResponse` object, and
125
+ provides an ``__aiter__`` method to iterate through its
126
+ ``models`` field.
127
+
128
+ If there are more pages, the ``__aiter__`` method will make additional
129
+ ``ListModels`` requests and continue to iterate
130
+ through the ``models`` field on the
131
+ corresponding responses.
132
+
133
+ All the usual :class:`google.ai.generativelanguage_v1beta.types.ListModelsResponse`
134
+ attributes are available on the pager. If multiple requests are made, only
135
+ the most recent response is retained, and thus used for attribute lookup.
136
+ """
137
+
138
+ def __init__(
139
+ self,
140
+ method: Callable[..., Awaitable[model_service.ListModelsResponse]],
141
+ request: model_service.ListModelsRequest,
142
+ response: model_service.ListModelsResponse,
143
+ *,
144
+ retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT,
145
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
146
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
147
+ ):
148
+ """Instantiates the pager.
149
+
150
+ Args:
151
+ method (Callable): The method that was originally called, and
152
+ which instantiated this pager.
153
+ request (google.ai.generativelanguage_v1beta.types.ListModelsRequest):
154
+ The initial request object.
155
+ response (google.ai.generativelanguage_v1beta.types.ListModelsResponse):
156
+ The initial response object.
157
+ retry (google.api_core.retry.AsyncRetry): Designation of what errors,
158
+ if any, should be retried.
159
+ timeout (float): The timeout for this request.
160
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
161
+ sent along with the request as metadata. Normally, each value must be of type `str`,
162
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
163
+ be of type `bytes`.
164
+ """
165
+ self._method = method
166
+ self._request = model_service.ListModelsRequest(request)
167
+ self._response = response
168
+ self._retry = retry
169
+ self._timeout = timeout
170
+ self._metadata = metadata
171
+
172
+ def __getattr__(self, name: str) -> Any:
173
+ return getattr(self._response, name)
174
+
175
+ @property
176
+ async def pages(self) -> AsyncIterator[model_service.ListModelsResponse]:
177
+ yield self._response
178
+ while self._response.next_page_token:
179
+ self._request.page_token = self._response.next_page_token
180
+ self._response = await self._method(
181
+ self._request,
182
+ retry=self._retry,
183
+ timeout=self._timeout,
184
+ metadata=self._metadata,
185
+ )
186
+ yield self._response
187
+
188
+ def __aiter__(self) -> AsyncIterator[model.Model]:
189
+ async def async_generator():
190
+ async for page in self.pages:
191
+ for response in page.models:
192
+ yield response
193
+
194
+ return async_generator()
195
+
196
+ def __repr__(self) -> str:
197
+ return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
198
+
199
+
200
+ class ListTunedModelsPager:
201
+ """A pager for iterating through ``list_tuned_models`` requests.
202
+
203
+ This class thinly wraps an initial
204
+ :class:`google.ai.generativelanguage_v1beta.types.ListTunedModelsResponse` object, and
205
+ provides an ``__iter__`` method to iterate through its
206
+ ``tuned_models`` field.
207
+
208
+ If there are more pages, the ``__iter__`` method will make additional
209
+ ``ListTunedModels`` requests and continue to iterate
210
+ through the ``tuned_models`` field on the
211
+ corresponding responses.
212
+
213
+ All the usual :class:`google.ai.generativelanguage_v1beta.types.ListTunedModelsResponse`
214
+ attributes are available on the pager. If multiple requests are made, only
215
+ the most recent response is retained, and thus used for attribute lookup.
216
+ """
217
+
218
+ def __init__(
219
+ self,
220
+ method: Callable[..., model_service.ListTunedModelsResponse],
221
+ request: model_service.ListTunedModelsRequest,
222
+ response: model_service.ListTunedModelsResponse,
223
+ *,
224
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
225
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
226
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
227
+ ):
228
+ """Instantiate the pager.
229
+
230
+ Args:
231
+ method (Callable): The method that was originally called, and
232
+ which instantiated this pager.
233
+ request (google.ai.generativelanguage_v1beta.types.ListTunedModelsRequest):
234
+ The initial request object.
235
+ response (google.ai.generativelanguage_v1beta.types.ListTunedModelsResponse):
236
+ The initial response object.
237
+ retry (google.api_core.retry.Retry): Designation of what errors,
238
+ if any, should be retried.
239
+ timeout (float): The timeout for this request.
240
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
241
+ sent along with the request as metadata. Normally, each value must be of type `str`,
242
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
243
+ be of type `bytes`.
244
+ """
245
+ self._method = method
246
+ self._request = model_service.ListTunedModelsRequest(request)
247
+ self._response = response
248
+ self._retry = retry
249
+ self._timeout = timeout
250
+ self._metadata = metadata
251
+
252
+ def __getattr__(self, name: str) -> Any:
253
+ return getattr(self._response, name)
254
+
255
+ @property
256
+ def pages(self) -> Iterator[model_service.ListTunedModelsResponse]:
257
+ yield self._response
258
+ while self._response.next_page_token:
259
+ self._request.page_token = self._response.next_page_token
260
+ self._response = self._method(
261
+ self._request,
262
+ retry=self._retry,
263
+ timeout=self._timeout,
264
+ metadata=self._metadata,
265
+ )
266
+ yield self._response
267
+
268
+ def __iter__(self) -> Iterator[tuned_model.TunedModel]:
269
+ for page in self.pages:
270
+ yield from page.tuned_models
271
+
272
+ def __repr__(self) -> str:
273
+ return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
274
+
275
+
276
+ class ListTunedModelsAsyncPager:
277
+ """A pager for iterating through ``list_tuned_models`` requests.
278
+
279
+ This class thinly wraps an initial
280
+ :class:`google.ai.generativelanguage_v1beta.types.ListTunedModelsResponse` object, and
281
+ provides an ``__aiter__`` method to iterate through its
282
+ ``tuned_models`` field.
283
+
284
+ If there are more pages, the ``__aiter__`` method will make additional
285
+ ``ListTunedModels`` requests and continue to iterate
286
+ through the ``tuned_models`` field on the
287
+ corresponding responses.
288
+
289
+ All the usual :class:`google.ai.generativelanguage_v1beta.types.ListTunedModelsResponse`
290
+ attributes are available on the pager. If multiple requests are made, only
291
+ the most recent response is retained, and thus used for attribute lookup.
292
+ """
293
+
294
+ def __init__(
295
+ self,
296
+ method: Callable[..., Awaitable[model_service.ListTunedModelsResponse]],
297
+ request: model_service.ListTunedModelsRequest,
298
+ response: model_service.ListTunedModelsResponse,
299
+ *,
300
+ retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT,
301
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
302
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
303
+ ):
304
+ """Instantiates the pager.
305
+
306
+ Args:
307
+ method (Callable): The method that was originally called, and
308
+ which instantiated this pager.
309
+ request (google.ai.generativelanguage_v1beta.types.ListTunedModelsRequest):
310
+ The initial request object.
311
+ response (google.ai.generativelanguage_v1beta.types.ListTunedModelsResponse):
312
+ The initial response object.
313
+ retry (google.api_core.retry.AsyncRetry): Designation of what errors,
314
+ if any, should be retried.
315
+ timeout (float): The timeout for this request.
316
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
317
+ sent along with the request as metadata. Normally, each value must be of type `str`,
318
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
319
+ be of type `bytes`.
320
+ """
321
+ self._method = method
322
+ self._request = model_service.ListTunedModelsRequest(request)
323
+ self._response = response
324
+ self._retry = retry
325
+ self._timeout = timeout
326
+ self._metadata = metadata
327
+
328
+ def __getattr__(self, name: str) -> Any:
329
+ return getattr(self._response, name)
330
+
331
+ @property
332
+ async def pages(self) -> AsyncIterator[model_service.ListTunedModelsResponse]:
333
+ yield self._response
334
+ while self._response.next_page_token:
335
+ self._request.page_token = self._response.next_page_token
336
+ self._response = await self._method(
337
+ self._request,
338
+ retry=self._retry,
339
+ timeout=self._timeout,
340
+ metadata=self._metadata,
341
+ )
342
+ yield self._response
343
+
344
+ def __aiter__(self) -> AsyncIterator[tuned_model.TunedModel]:
345
+ async def async_generator():
346
+ async for page in self.pages:
347
+ for response in page.tuned_models:
348
+ yield response
349
+
350
+ return async_generator()
351
+
352
+ def __repr__(self) -> str:
353
+ return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/transports/__init__.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ from collections import OrderedDict
17
+ from typing import Dict, Type
18
+
19
+ from .base import ModelServiceTransport
20
+ from .grpc import ModelServiceGrpcTransport
21
+ from .grpc_asyncio import ModelServiceGrpcAsyncIOTransport
22
+ from .rest import ModelServiceRestInterceptor, ModelServiceRestTransport
23
+
24
+ # Compile a registry of transports.
25
+ _transport_registry = OrderedDict() # type: Dict[str, Type[ModelServiceTransport]]
26
+ _transport_registry["grpc"] = ModelServiceGrpcTransport
27
+ _transport_registry["grpc_asyncio"] = ModelServiceGrpcAsyncIOTransport
28
+ _transport_registry["rest"] = ModelServiceRestTransport
29
+
30
+ __all__ = (
31
+ "ModelServiceTransport",
32
+ "ModelServiceGrpcTransport",
33
+ "ModelServiceGrpcAsyncIOTransport",
34
+ "ModelServiceRestTransport",
35
+ "ModelServiceRestInterceptor",
36
+ )
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/transports/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (895 Bytes). View file
 
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/transports/__pycache__/base.cpython-311.pyc ADDED
Binary file (12.9 kB). View file
 
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/transports/__pycache__/grpc.cpython-311.pyc ADDED
Binary file (25.5 kB). View file
 
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/transports/__pycache__/grpc_asyncio.cpython-311.pyc ADDED
Binary file (29.6 kB). View file
 
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/transports/__pycache__/rest.cpython-311.pyc ADDED
Binary file (68.3 kB). View file
 
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/transports/__pycache__/rest_base.cpython-311.pyc ADDED
Binary file (22 kB). View file
 
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/transports/base.py ADDED
@@ -0,0 +1,353 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ import abc
17
+ from typing import Awaitable, Callable, Dict, Optional, Sequence, Union
18
+
19
+ import google.api_core
20
+ from google.api_core import exceptions as core_exceptions
21
+ from google.api_core import gapic_v1, operations_v1
22
+ from google.api_core import retry as retries
23
+ import google.auth # type: ignore
24
+ from google.auth import credentials as ga_credentials # type: ignore
25
+ from google.longrunning import operations_pb2 # type: ignore
26
+ from google.oauth2 import service_account # type: ignore
27
+ from google.protobuf import empty_pb2 # type: ignore
28
+
29
+ from google.ai.generativelanguage_v1beta import gapic_version as package_version
30
+ from google.ai.generativelanguage_v1beta.types import tuned_model as gag_tuned_model
31
+ from google.ai.generativelanguage_v1beta.types import model, model_service
32
+ from google.ai.generativelanguage_v1beta.types import tuned_model
33
+
34
+ DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
35
+ gapic_version=package_version.__version__
36
+ )
37
+
38
+
39
+ class ModelServiceTransport(abc.ABC):
40
+ """Abstract transport class for ModelService."""
41
+
42
+ AUTH_SCOPES = ()
43
+
44
+ DEFAULT_HOST: str = "generativelanguage.googleapis.com"
45
+
46
+ def __init__(
47
+ self,
48
+ *,
49
+ host: str = DEFAULT_HOST,
50
+ credentials: Optional[ga_credentials.Credentials] = None,
51
+ credentials_file: Optional[str] = None,
52
+ scopes: Optional[Sequence[str]] = None,
53
+ quota_project_id: Optional[str] = None,
54
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
55
+ always_use_jwt_access: Optional[bool] = False,
56
+ api_audience: Optional[str] = None,
57
+ **kwargs,
58
+ ) -> None:
59
+ """Instantiate the transport.
60
+
61
+ Args:
62
+ host (Optional[str]):
63
+ The hostname to connect to (default: 'generativelanguage.googleapis.com').
64
+ credentials (Optional[google.auth.credentials.Credentials]): The
65
+ authorization credentials to attach to requests. These
66
+ credentials identify the application to the service; if none
67
+ are specified, the client will attempt to ascertain the
68
+ credentials from the environment.
69
+ credentials_file (Optional[str]): A file with credentials that can
70
+ be loaded with :func:`google.auth.load_credentials_from_file`.
71
+ This argument is mutually exclusive with credentials.
72
+ scopes (Optional[Sequence[str]]): A list of scopes.
73
+ quota_project_id (Optional[str]): An optional project to use for billing
74
+ and quota.
75
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
76
+ The client info used to send a user-agent string along with
77
+ API requests. If ``None``, then default info will be used.
78
+ Generally, you only need to set this if you're developing
79
+ your own client library.
80
+ always_use_jwt_access (Optional[bool]): Whether self signed JWT should
81
+ be used for service account credentials.
82
+ """
83
+
84
+ scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES}
85
+
86
+ # Save the scopes.
87
+ self._scopes = scopes
88
+ if not hasattr(self, "_ignore_credentials"):
89
+ self._ignore_credentials: bool = False
90
+
91
+ # If no credentials are provided, then determine the appropriate
92
+ # defaults.
93
+ if credentials and credentials_file:
94
+ raise core_exceptions.DuplicateCredentialArgs(
95
+ "'credentials_file' and 'credentials' are mutually exclusive"
96
+ )
97
+
98
+ if credentials_file is not None:
99
+ credentials, _ = google.auth.load_credentials_from_file(
100
+ credentials_file, **scopes_kwargs, quota_project_id=quota_project_id
101
+ )
102
+ elif credentials is None and not self._ignore_credentials:
103
+ credentials, _ = google.auth.default(
104
+ **scopes_kwargs, quota_project_id=quota_project_id
105
+ )
106
+ # Don't apply audience if the credentials file passed from user.
107
+ if hasattr(credentials, "with_gdch_audience"):
108
+ credentials = credentials.with_gdch_audience(
109
+ api_audience if api_audience else host
110
+ )
111
+
112
+ # If the credentials are service account credentials, then always try to use self signed JWT.
113
+ if (
114
+ always_use_jwt_access
115
+ and isinstance(credentials, service_account.Credentials)
116
+ and hasattr(service_account.Credentials, "with_always_use_jwt_access")
117
+ ):
118
+ credentials = credentials.with_always_use_jwt_access(True)
119
+
120
+ # Save the credentials.
121
+ self._credentials = credentials
122
+
123
+ # Save the hostname. Default to port 443 (HTTPS) if none is specified.
124
+ if ":" not in host:
125
+ host += ":443"
126
+ self._host = host
127
+
128
+ @property
129
+ def host(self):
130
+ return self._host
131
+
132
+ def _prep_wrapped_messages(self, client_info):
133
+ # Precompute the wrapped methods.
134
+ self._wrapped_methods = {
135
+ self.get_model: gapic_v1.method.wrap_method(
136
+ self.get_model,
137
+ default_retry=retries.Retry(
138
+ initial=1.0,
139
+ maximum=10.0,
140
+ multiplier=1.3,
141
+ predicate=retries.if_exception_type(
142
+ core_exceptions.ServiceUnavailable,
143
+ ),
144
+ deadline=60.0,
145
+ ),
146
+ default_timeout=60.0,
147
+ client_info=client_info,
148
+ ),
149
+ self.list_models: gapic_v1.method.wrap_method(
150
+ self.list_models,
151
+ default_retry=retries.Retry(
152
+ initial=1.0,
153
+ maximum=10.0,
154
+ multiplier=1.3,
155
+ predicate=retries.if_exception_type(
156
+ core_exceptions.ServiceUnavailable,
157
+ ),
158
+ deadline=60.0,
159
+ ),
160
+ default_timeout=60.0,
161
+ client_info=client_info,
162
+ ),
163
+ self.get_tuned_model: gapic_v1.method.wrap_method(
164
+ self.get_tuned_model,
165
+ default_retry=retries.Retry(
166
+ initial=1.0,
167
+ maximum=10.0,
168
+ multiplier=1.3,
169
+ predicate=retries.if_exception_type(
170
+ core_exceptions.ServiceUnavailable,
171
+ ),
172
+ deadline=60.0,
173
+ ),
174
+ default_timeout=60.0,
175
+ client_info=client_info,
176
+ ),
177
+ self.list_tuned_models: gapic_v1.method.wrap_method(
178
+ self.list_tuned_models,
179
+ default_retry=retries.Retry(
180
+ initial=1.0,
181
+ maximum=10.0,
182
+ multiplier=1.3,
183
+ predicate=retries.if_exception_type(
184
+ core_exceptions.ServiceUnavailable,
185
+ ),
186
+ deadline=60.0,
187
+ ),
188
+ default_timeout=60.0,
189
+ client_info=client_info,
190
+ ),
191
+ self.create_tuned_model: gapic_v1.method.wrap_method(
192
+ self.create_tuned_model,
193
+ default_retry=retries.Retry(
194
+ initial=1.0,
195
+ maximum=10.0,
196
+ multiplier=1.3,
197
+ predicate=retries.if_exception_type(
198
+ core_exceptions.ServiceUnavailable,
199
+ ),
200
+ deadline=60.0,
201
+ ),
202
+ default_timeout=60.0,
203
+ client_info=client_info,
204
+ ),
205
+ self.update_tuned_model: gapic_v1.method.wrap_method(
206
+ self.update_tuned_model,
207
+ default_retry=retries.Retry(
208
+ initial=1.0,
209
+ maximum=10.0,
210
+ multiplier=1.3,
211
+ predicate=retries.if_exception_type(
212
+ core_exceptions.ServiceUnavailable,
213
+ ),
214
+ deadline=60.0,
215
+ ),
216
+ default_timeout=60.0,
217
+ client_info=client_info,
218
+ ),
219
+ self.delete_tuned_model: gapic_v1.method.wrap_method(
220
+ self.delete_tuned_model,
221
+ default_retry=retries.Retry(
222
+ initial=1.0,
223
+ maximum=10.0,
224
+ multiplier=1.3,
225
+ predicate=retries.if_exception_type(
226
+ core_exceptions.ServiceUnavailable,
227
+ ),
228
+ deadline=60.0,
229
+ ),
230
+ default_timeout=60.0,
231
+ client_info=client_info,
232
+ ),
233
+ self.get_operation: gapic_v1.method.wrap_method(
234
+ self.get_operation,
235
+ default_timeout=None,
236
+ client_info=client_info,
237
+ ),
238
+ self.list_operations: gapic_v1.method.wrap_method(
239
+ self.list_operations,
240
+ default_timeout=None,
241
+ client_info=client_info,
242
+ ),
243
+ }
244
+
245
+ def close(self):
246
+ """Closes resources associated with the transport.
247
+
248
+ .. warning::
249
+ Only call this method if the transport is NOT shared
250
+ with other clients - this may cause errors in other clients!
251
+ """
252
+ raise NotImplementedError()
253
+
254
+ @property
255
+ def operations_client(self):
256
+ """Return the client designed to process long-running operations."""
257
+ raise NotImplementedError()
258
+
259
+ @property
260
+ def get_model(
261
+ self,
262
+ ) -> Callable[
263
+ [model_service.GetModelRequest], Union[model.Model, Awaitable[model.Model]]
264
+ ]:
265
+ raise NotImplementedError()
266
+
267
+ @property
268
+ def list_models(
269
+ self,
270
+ ) -> Callable[
271
+ [model_service.ListModelsRequest],
272
+ Union[
273
+ model_service.ListModelsResponse,
274
+ Awaitable[model_service.ListModelsResponse],
275
+ ],
276
+ ]:
277
+ raise NotImplementedError()
278
+
279
+ @property
280
+ def get_tuned_model(
281
+ self,
282
+ ) -> Callable[
283
+ [model_service.GetTunedModelRequest],
284
+ Union[tuned_model.TunedModel, Awaitable[tuned_model.TunedModel]],
285
+ ]:
286
+ raise NotImplementedError()
287
+
288
+ @property
289
+ def list_tuned_models(
290
+ self,
291
+ ) -> Callable[
292
+ [model_service.ListTunedModelsRequest],
293
+ Union[
294
+ model_service.ListTunedModelsResponse,
295
+ Awaitable[model_service.ListTunedModelsResponse],
296
+ ],
297
+ ]:
298
+ raise NotImplementedError()
299
+
300
+ @property
301
+ def create_tuned_model(
302
+ self,
303
+ ) -> Callable[
304
+ [model_service.CreateTunedModelRequest],
305
+ Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]],
306
+ ]:
307
+ raise NotImplementedError()
308
+
309
+ @property
310
+ def update_tuned_model(
311
+ self,
312
+ ) -> Callable[
313
+ [model_service.UpdateTunedModelRequest],
314
+ Union[gag_tuned_model.TunedModel, Awaitable[gag_tuned_model.TunedModel]],
315
+ ]:
316
+ raise NotImplementedError()
317
+
318
+ @property
319
+ def delete_tuned_model(
320
+ self,
321
+ ) -> Callable[
322
+ [model_service.DeleteTunedModelRequest],
323
+ Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]],
324
+ ]:
325
+ raise NotImplementedError()
326
+
327
+ @property
328
+ def list_operations(
329
+ self,
330
+ ) -> Callable[
331
+ [operations_pb2.ListOperationsRequest],
332
+ Union[
333
+ operations_pb2.ListOperationsResponse,
334
+ Awaitable[operations_pb2.ListOperationsResponse],
335
+ ],
336
+ ]:
337
+ raise NotImplementedError()
338
+
339
+ @property
340
+ def get_operation(
341
+ self,
342
+ ) -> Callable[
343
+ [operations_pb2.GetOperationRequest],
344
+ Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]],
345
+ ]:
346
+ raise NotImplementedError()
347
+
348
+ @property
349
+ def kind(self) -> str:
350
+ raise NotImplementedError()
351
+
352
+
353
+ __all__ = ("ModelServiceTransport",)
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/transports/grpc.py ADDED
@@ -0,0 +1,582 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ import json
17
+ import logging as std_logging
18
+ import pickle
19
+ from typing import Callable, Dict, Optional, Sequence, Tuple, Union
20
+ import warnings
21
+
22
+ from google.api_core import gapic_v1, grpc_helpers, operations_v1
23
+ import google.auth # type: ignore
24
+ from google.auth import credentials as ga_credentials # type: ignore
25
+ from google.auth.transport.grpc import SslCredentials # type: ignore
26
+ from google.longrunning import operations_pb2 # type: ignore
27
+ from google.protobuf import empty_pb2 # type: ignore
28
+ from google.protobuf.json_format import MessageToJson
29
+ import google.protobuf.message
30
+ import grpc # type: ignore
31
+ import proto # type: ignore
32
+
33
+ from google.ai.generativelanguage_v1beta.types import tuned_model as gag_tuned_model
34
+ from google.ai.generativelanguage_v1beta.types import model, model_service
35
+ from google.ai.generativelanguage_v1beta.types import tuned_model
36
+
37
+ from .base import DEFAULT_CLIENT_INFO, ModelServiceTransport
38
+
39
+ try:
40
+ from google.api_core import client_logging # type: ignore
41
+
42
+ CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
43
+ except ImportError: # pragma: NO COVER
44
+ CLIENT_LOGGING_SUPPORTED = False
45
+
46
+ _LOGGER = std_logging.getLogger(__name__)
47
+
48
+
49
+ class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER
50
+ def intercept_unary_unary(self, continuation, client_call_details, request):
51
+ logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
52
+ std_logging.DEBUG
53
+ )
54
+ if logging_enabled: # pragma: NO COVER
55
+ request_metadata = client_call_details.metadata
56
+ if isinstance(request, proto.Message):
57
+ request_payload = type(request).to_json(request)
58
+ elif isinstance(request, google.protobuf.message.Message):
59
+ request_payload = MessageToJson(request)
60
+ else:
61
+ request_payload = f"{type(request).__name__}: {pickle.dumps(request)}"
62
+
63
+ request_metadata = {
64
+ key: value.decode("utf-8") if isinstance(value, bytes) else value
65
+ for key, value in request_metadata
66
+ }
67
+ grpc_request = {
68
+ "payload": request_payload,
69
+ "requestMethod": "grpc",
70
+ "metadata": dict(request_metadata),
71
+ }
72
+ _LOGGER.debug(
73
+ f"Sending request for {client_call_details.method}",
74
+ extra={
75
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
76
+ "rpcName": client_call_details.method,
77
+ "request": grpc_request,
78
+ "metadata": grpc_request["metadata"],
79
+ },
80
+ )
81
+
82
+ response = continuation(client_call_details, request)
83
+ if logging_enabled: # pragma: NO COVER
84
+ response_metadata = response.trailing_metadata()
85
+ # Convert gRPC metadata `<class 'grpc.aio._metadata.Metadata'>` to list of tuples
86
+ metadata = (
87
+ dict([(k, str(v)) for k, v in response_metadata])
88
+ if response_metadata
89
+ else None
90
+ )
91
+ result = response.result()
92
+ if isinstance(result, proto.Message):
93
+ response_payload = type(result).to_json(result)
94
+ elif isinstance(result, google.protobuf.message.Message):
95
+ response_payload = MessageToJson(result)
96
+ else:
97
+ response_payload = f"{type(result).__name__}: {pickle.dumps(result)}"
98
+ grpc_response = {
99
+ "payload": response_payload,
100
+ "metadata": metadata,
101
+ "status": "OK",
102
+ }
103
+ _LOGGER.debug(
104
+ f"Received response for {client_call_details.method}.",
105
+ extra={
106
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
107
+ "rpcName": client_call_details.method,
108
+ "response": grpc_response,
109
+ "metadata": grpc_response["metadata"],
110
+ },
111
+ )
112
+ return response
113
+
114
+
115
+ class ModelServiceGrpcTransport(ModelServiceTransport):
116
+ """gRPC backend transport for ModelService.
117
+
118
+ Provides methods for getting metadata information about
119
+ Generative Models.
120
+
121
+ This class defines the same methods as the primary client, so the
122
+ primary client can load the underlying transport implementation
123
+ and call it.
124
+
125
+ It sends protocol buffers over the wire using gRPC (which is built on
126
+ top of HTTP/2); the ``grpcio`` package must be installed.
127
+ """
128
+
129
+ _stubs: Dict[str, Callable]
130
+
131
+ def __init__(
132
+ self,
133
+ *,
134
+ host: str = "generativelanguage.googleapis.com",
135
+ credentials: Optional[ga_credentials.Credentials] = None,
136
+ credentials_file: Optional[str] = None,
137
+ scopes: Optional[Sequence[str]] = None,
138
+ channel: Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]] = None,
139
+ api_mtls_endpoint: Optional[str] = None,
140
+ client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
141
+ ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None,
142
+ client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
143
+ quota_project_id: Optional[str] = None,
144
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
145
+ always_use_jwt_access: Optional[bool] = False,
146
+ api_audience: Optional[str] = None,
147
+ ) -> None:
148
+ """Instantiate the transport.
149
+
150
+ Args:
151
+ host (Optional[str]):
152
+ The hostname to connect to (default: 'generativelanguage.googleapis.com').
153
+ credentials (Optional[google.auth.credentials.Credentials]): The
154
+ authorization credentials to attach to requests. These
155
+ credentials identify the application to the service; if none
156
+ are specified, the client will attempt to ascertain the
157
+ credentials from the environment.
158
+ This argument is ignored if a ``channel`` instance is provided.
159
+ credentials_file (Optional[str]): A file with credentials that can
160
+ be loaded with :func:`google.auth.load_credentials_from_file`.
161
+ This argument is ignored if a ``channel`` instance is provided.
162
+ scopes (Optional(Sequence[str])): A list of scopes. This argument is
163
+ ignored if a ``channel`` instance is provided.
164
+ channel (Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]]):
165
+ A ``Channel`` instance through which to make calls, or a Callable
166
+ that constructs and returns one. If set to None, ``self.create_channel``
167
+ is used to create the channel. If a Callable is given, it will be called
168
+ with the same arguments as used in ``self.create_channel``.
169
+ api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint.
170
+ If provided, it overrides the ``host`` argument and tries to create
171
+ a mutual TLS channel with client SSL credentials from
172
+ ``client_cert_source`` or application default SSL credentials.
173
+ client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]):
174
+ Deprecated. A callback to provide client SSL certificate bytes and
175
+ private key bytes, both in PEM format. It is ignored if
176
+ ``api_mtls_endpoint`` is None.
177
+ ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials
178
+ for the grpc channel. It is ignored if a ``channel`` instance is provided.
179
+ client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]):
180
+ A callback to provide client certificate bytes and private key bytes,
181
+ both in PEM format. It is used to configure a mutual TLS channel. It is
182
+ ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided.
183
+ quota_project_id (Optional[str]): An optional project to use for billing
184
+ and quota.
185
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
186
+ The client info used to send a user-agent string along with
187
+ API requests. If ``None``, then default info will be used.
188
+ Generally, you only need to set this if you're developing
189
+ your own client library.
190
+ always_use_jwt_access (Optional[bool]): Whether self signed JWT should
191
+ be used for service account credentials.
192
+
193
+ Raises:
194
+ google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
195
+ creation failed for any reason.
196
+ google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
197
+ and ``credentials_file`` are passed.
198
+ """
199
+ self._grpc_channel = None
200
+ self._ssl_channel_credentials = ssl_channel_credentials
201
+ self._stubs: Dict[str, Callable] = {}
202
+ self._operations_client: Optional[operations_v1.OperationsClient] = None
203
+
204
+ if api_mtls_endpoint:
205
+ warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
206
+ if client_cert_source:
207
+ warnings.warn("client_cert_source is deprecated", DeprecationWarning)
208
+
209
+ if isinstance(channel, grpc.Channel):
210
+ # Ignore credentials if a channel was passed.
211
+ credentials = None
212
+ self._ignore_credentials = True
213
+ # If a channel was explicitly provided, set it.
214
+ self._grpc_channel = channel
215
+ self._ssl_channel_credentials = None
216
+
217
+ else:
218
+ if api_mtls_endpoint:
219
+ host = api_mtls_endpoint
220
+
221
+ # Create SSL credentials with client_cert_source or application
222
+ # default SSL credentials.
223
+ if client_cert_source:
224
+ cert, key = client_cert_source()
225
+ self._ssl_channel_credentials = grpc.ssl_channel_credentials(
226
+ certificate_chain=cert, private_key=key
227
+ )
228
+ else:
229
+ self._ssl_channel_credentials = SslCredentials().ssl_credentials
230
+
231
+ else:
232
+ if client_cert_source_for_mtls and not ssl_channel_credentials:
233
+ cert, key = client_cert_source_for_mtls()
234
+ self._ssl_channel_credentials = grpc.ssl_channel_credentials(
235
+ certificate_chain=cert, private_key=key
236
+ )
237
+
238
+ # The base transport sets the host, credentials and scopes
239
+ super().__init__(
240
+ host=host,
241
+ credentials=credentials,
242
+ credentials_file=credentials_file,
243
+ scopes=scopes,
244
+ quota_project_id=quota_project_id,
245
+ client_info=client_info,
246
+ always_use_jwt_access=always_use_jwt_access,
247
+ api_audience=api_audience,
248
+ )
249
+
250
+ if not self._grpc_channel:
251
+ # initialize with the provided callable or the default channel
252
+ channel_init = channel or type(self).create_channel
253
+ self._grpc_channel = channel_init(
254
+ self._host,
255
+ # use the credentials which are saved
256
+ credentials=self._credentials,
257
+ # Set ``credentials_file`` to ``None`` here as
258
+ # the credentials that we saved earlier should be used.
259
+ credentials_file=None,
260
+ scopes=self._scopes,
261
+ ssl_credentials=self._ssl_channel_credentials,
262
+ quota_project_id=quota_project_id,
263
+ options=[
264
+ ("grpc.max_send_message_length", -1),
265
+ ("grpc.max_receive_message_length", -1),
266
+ ],
267
+ )
268
+
269
+ self._interceptor = _LoggingClientInterceptor()
270
+ self._logged_channel = grpc.intercept_channel(
271
+ self._grpc_channel, self._interceptor
272
+ )
273
+
274
+ # Wrap messages. This must be done after self._logged_channel exists
275
+ self._prep_wrapped_messages(client_info)
276
+
277
+ @classmethod
278
+ def create_channel(
279
+ cls,
280
+ host: str = "generativelanguage.googleapis.com",
281
+ credentials: Optional[ga_credentials.Credentials] = None,
282
+ credentials_file: Optional[str] = None,
283
+ scopes: Optional[Sequence[str]] = None,
284
+ quota_project_id: Optional[str] = None,
285
+ **kwargs,
286
+ ) -> grpc.Channel:
287
+ """Create and return a gRPC channel object.
288
+ Args:
289
+ host (Optional[str]): The host for the channel to use.
290
+ credentials (Optional[~.Credentials]): The
291
+ authorization credentials to attach to requests. These
292
+ credentials identify this application to the service. If
293
+ none are specified, the client will attempt to ascertain
294
+ the credentials from the environment.
295
+ credentials_file (Optional[str]): A file with credentials that can
296
+ be loaded with :func:`google.auth.load_credentials_from_file`.
297
+ This argument is mutually exclusive with credentials.
298
+ scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
299
+ service. These are only used when credentials are not specified and
300
+ are passed to :func:`google.auth.default`.
301
+ quota_project_id (Optional[str]): An optional project to use for billing
302
+ and quota.
303
+ kwargs (Optional[dict]): Keyword arguments, which are passed to the
304
+ channel creation.
305
+ Returns:
306
+ grpc.Channel: A gRPC channel object.
307
+
308
+ Raises:
309
+ google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
310
+ and ``credentials_file`` are passed.
311
+ """
312
+
313
+ return grpc_helpers.create_channel(
314
+ host,
315
+ credentials=credentials,
316
+ credentials_file=credentials_file,
317
+ quota_project_id=quota_project_id,
318
+ default_scopes=cls.AUTH_SCOPES,
319
+ scopes=scopes,
320
+ default_host=cls.DEFAULT_HOST,
321
+ **kwargs,
322
+ )
323
+
324
+ @property
325
+ def grpc_channel(self) -> grpc.Channel:
326
+ """Return the channel designed to connect to this service."""
327
+ return self._grpc_channel
328
+
329
+ @property
330
+ def operations_client(self) -> operations_v1.OperationsClient:
331
+ """Create the client designed to process long-running operations.
332
+
333
+ This property caches on the instance; repeated calls return the same
334
+ client.
335
+ """
336
+ # Quick check: Only create a new client if we do not already have one.
337
+ if self._operations_client is None:
338
+ self._operations_client = operations_v1.OperationsClient(
339
+ self._logged_channel
340
+ )
341
+
342
+ # Return the client from cache.
343
+ return self._operations_client
344
+
345
+ @property
346
+ def get_model(self) -> Callable[[model_service.GetModelRequest], model.Model]:
347
+ r"""Return a callable for the get model method over gRPC.
348
+
349
+ Gets information about a specific ``Model`` such as its version
350
+ number, token limits,
351
+ `parameters <https://ai.google.dev/gemini-api/docs/models/generative-models#model-parameters>`__
352
+ and other metadata. Refer to the `Gemini models
353
+ guide <https://ai.google.dev/gemini-api/docs/models/gemini>`__
354
+ for detailed model information.
355
+
356
+ Returns:
357
+ Callable[[~.GetModelRequest],
358
+ ~.Model]:
359
+ A function that, when called, will call the underlying RPC
360
+ on the server.
361
+ """
362
+ # Generate a "stub function" on-the-fly which will actually make
363
+ # the request.
364
+ # gRPC handles serialization and deserialization, so we just need
365
+ # to pass in the functions for each.
366
+ if "get_model" not in self._stubs:
367
+ self._stubs["get_model"] = self._logged_channel.unary_unary(
368
+ "/google.ai.generativelanguage.v1beta.ModelService/GetModel",
369
+ request_serializer=model_service.GetModelRequest.serialize,
370
+ response_deserializer=model.Model.deserialize,
371
+ )
372
+ return self._stubs["get_model"]
373
+
374
+ @property
375
+ def list_models(
376
+ self,
377
+ ) -> Callable[[model_service.ListModelsRequest], model_service.ListModelsResponse]:
378
+ r"""Return a callable for the list models method over gRPC.
379
+
380
+ Lists the
381
+ ```Model``\ s <https://ai.google.dev/gemini-api/docs/models/gemini>`__
382
+ available through the Gemini API.
383
+
384
+ Returns:
385
+ Callable[[~.ListModelsRequest],
386
+ ~.ListModelsResponse]:
387
+ A function that, when called, will call the underlying RPC
388
+ on the server.
389
+ """
390
+ # Generate a "stub function" on-the-fly which will actually make
391
+ # the request.
392
+ # gRPC handles serialization and deserialization, so we just need
393
+ # to pass in the functions for each.
394
+ if "list_models" not in self._stubs:
395
+ self._stubs["list_models"] = self._logged_channel.unary_unary(
396
+ "/google.ai.generativelanguage.v1beta.ModelService/ListModels",
397
+ request_serializer=model_service.ListModelsRequest.serialize,
398
+ response_deserializer=model_service.ListModelsResponse.deserialize,
399
+ )
400
+ return self._stubs["list_models"]
401
+
402
+ @property
403
+ def get_tuned_model(
404
+ self,
405
+ ) -> Callable[[model_service.GetTunedModelRequest], tuned_model.TunedModel]:
406
+ r"""Return a callable for the get tuned model method over gRPC.
407
+
408
+ Gets information about a specific TunedModel.
409
+
410
+ Returns:
411
+ Callable[[~.GetTunedModelRequest],
412
+ ~.TunedModel]:
413
+ A function that, when called, will call the underlying RPC
414
+ on the server.
415
+ """
416
+ # Generate a "stub function" on-the-fly which will actually make
417
+ # the request.
418
+ # gRPC handles serialization and deserialization, so we just need
419
+ # to pass in the functions for each.
420
+ if "get_tuned_model" not in self._stubs:
421
+ self._stubs["get_tuned_model"] = self._logged_channel.unary_unary(
422
+ "/google.ai.generativelanguage.v1beta.ModelService/GetTunedModel",
423
+ request_serializer=model_service.GetTunedModelRequest.serialize,
424
+ response_deserializer=tuned_model.TunedModel.deserialize,
425
+ )
426
+ return self._stubs["get_tuned_model"]
427
+
428
+ @property
429
+ def list_tuned_models(
430
+ self,
431
+ ) -> Callable[
432
+ [model_service.ListTunedModelsRequest], model_service.ListTunedModelsResponse
433
+ ]:
434
+ r"""Return a callable for the list tuned models method over gRPC.
435
+
436
+ Lists created tuned models.
437
+
438
+ Returns:
439
+ Callable[[~.ListTunedModelsRequest],
440
+ ~.ListTunedModelsResponse]:
441
+ A function that, when called, will call the underlying RPC
442
+ on the server.
443
+ """
444
+ # Generate a "stub function" on-the-fly which will actually make
445
+ # the request.
446
+ # gRPC handles serialization and deserialization, so we just need
447
+ # to pass in the functions for each.
448
+ if "list_tuned_models" not in self._stubs:
449
+ self._stubs["list_tuned_models"] = self._logged_channel.unary_unary(
450
+ "/google.ai.generativelanguage.v1beta.ModelService/ListTunedModels",
451
+ request_serializer=model_service.ListTunedModelsRequest.serialize,
452
+ response_deserializer=model_service.ListTunedModelsResponse.deserialize,
453
+ )
454
+ return self._stubs["list_tuned_models"]
455
+
456
+ @property
457
+ def create_tuned_model(
458
+ self,
459
+ ) -> Callable[[model_service.CreateTunedModelRequest], operations_pb2.Operation]:
460
+ r"""Return a callable for the create tuned model method over gRPC.
461
+
462
+ Creates a tuned model. Check intermediate tuning progress (if
463
+ any) through the [google.longrunning.Operations] service.
464
+
465
+ Access status and results through the Operations service.
466
+ Example: GET /v1/tunedModels/az2mb0bpw6i/operations/000-111-222
467
+
468
+ Returns:
469
+ Callable[[~.CreateTunedModelRequest],
470
+ ~.Operation]:
471
+ A function that, when called, will call the underlying RPC
472
+ on the server.
473
+ """
474
+ # Generate a "stub function" on-the-fly which will actually make
475
+ # the request.
476
+ # gRPC handles serialization and deserialization, so we just need
477
+ # to pass in the functions for each.
478
+ if "create_tuned_model" not in self._stubs:
479
+ self._stubs["create_tuned_model"] = self._logged_channel.unary_unary(
480
+ "/google.ai.generativelanguage.v1beta.ModelService/CreateTunedModel",
481
+ request_serializer=model_service.CreateTunedModelRequest.serialize,
482
+ response_deserializer=operations_pb2.Operation.FromString,
483
+ )
484
+ return self._stubs["create_tuned_model"]
485
+
486
+ @property
487
+ def update_tuned_model(
488
+ self,
489
+ ) -> Callable[[model_service.UpdateTunedModelRequest], gag_tuned_model.TunedModel]:
490
+ r"""Return a callable for the update tuned model method over gRPC.
491
+
492
+ Updates a tuned model.
493
+
494
+ Returns:
495
+ Callable[[~.UpdateTunedModelRequest],
496
+ ~.TunedModel]:
497
+ A function that, when called, will call the underlying RPC
498
+ on the server.
499
+ """
500
+ # Generate a "stub function" on-the-fly which will actually make
501
+ # the request.
502
+ # gRPC handles serialization and deserialization, so we just need
503
+ # to pass in the functions for each.
504
+ if "update_tuned_model" not in self._stubs:
505
+ self._stubs["update_tuned_model"] = self._logged_channel.unary_unary(
506
+ "/google.ai.generativelanguage.v1beta.ModelService/UpdateTunedModel",
507
+ request_serializer=model_service.UpdateTunedModelRequest.serialize,
508
+ response_deserializer=gag_tuned_model.TunedModel.deserialize,
509
+ )
510
+ return self._stubs["update_tuned_model"]
511
+
512
+ @property
513
+ def delete_tuned_model(
514
+ self,
515
+ ) -> Callable[[model_service.DeleteTunedModelRequest], empty_pb2.Empty]:
516
+ r"""Return a callable for the delete tuned model method over gRPC.
517
+
518
+ Deletes a tuned model.
519
+
520
+ Returns:
521
+ Callable[[~.DeleteTunedModelRequest],
522
+ ~.Empty]:
523
+ A function that, when called, will call the underlying RPC
524
+ on the server.
525
+ """
526
+ # Generate a "stub function" on-the-fly which will actually make
527
+ # the request.
528
+ # gRPC handles serialization and deserialization, so we just need
529
+ # to pass in the functions for each.
530
+ if "delete_tuned_model" not in self._stubs:
531
+ self._stubs["delete_tuned_model"] = self._logged_channel.unary_unary(
532
+ "/google.ai.generativelanguage.v1beta.ModelService/DeleteTunedModel",
533
+ request_serializer=model_service.DeleteTunedModelRequest.serialize,
534
+ response_deserializer=empty_pb2.Empty.FromString,
535
+ )
536
+ return self._stubs["delete_tuned_model"]
537
+
538
+ def close(self):
539
+ self._logged_channel.close()
540
+
541
+ @property
542
+ def get_operation(
543
+ self,
544
+ ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]:
545
+ r"""Return a callable for the get_operation method over gRPC."""
546
+ # Generate a "stub function" on-the-fly which will actually make
547
+ # the request.
548
+ # gRPC handles serialization and deserialization, so we just need
549
+ # to pass in the functions for each.
550
+ if "get_operation" not in self._stubs:
551
+ self._stubs["get_operation"] = self._logged_channel.unary_unary(
552
+ "/google.longrunning.Operations/GetOperation",
553
+ request_serializer=operations_pb2.GetOperationRequest.SerializeToString,
554
+ response_deserializer=operations_pb2.Operation.FromString,
555
+ )
556
+ return self._stubs["get_operation"]
557
+
558
+ @property
559
+ def list_operations(
560
+ self,
561
+ ) -> Callable[
562
+ [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse
563
+ ]:
564
+ r"""Return a callable for the list_operations method over gRPC."""
565
+ # Generate a "stub function" on-the-fly which will actually make
566
+ # the request.
567
+ # gRPC handles serialization and deserialization, so we just need
568
+ # to pass in the functions for each.
569
+ if "list_operations" not in self._stubs:
570
+ self._stubs["list_operations"] = self._logged_channel.unary_unary(
571
+ "/google.longrunning.Operations/ListOperations",
572
+ request_serializer=operations_pb2.ListOperationsRequest.SerializeToString,
573
+ response_deserializer=operations_pb2.ListOperationsResponse.FromString,
574
+ )
575
+ return self._stubs["list_operations"]
576
+
577
+ @property
578
+ def kind(self) -> str:
579
+ return "grpc"
580
+
581
+
582
+ __all__ = ("ModelServiceGrpcTransport",)
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/transports/grpc_asyncio.py ADDED
@@ -0,0 +1,718 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ import inspect
17
+ import json
18
+ import logging as std_logging
19
+ import pickle
20
+ from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union
21
+ import warnings
22
+
23
+ from google.api_core import exceptions as core_exceptions
24
+ from google.api_core import gapic_v1, grpc_helpers_async, operations_v1
25
+ from google.api_core import retry_async as retries
26
+ from google.auth import credentials as ga_credentials # type: ignore
27
+ from google.auth.transport.grpc import SslCredentials # type: ignore
28
+ from google.longrunning import operations_pb2 # type: ignore
29
+ from google.protobuf import empty_pb2 # type: ignore
30
+ from google.protobuf.json_format import MessageToJson
31
+ import google.protobuf.message
32
+ import grpc # type: ignore
33
+ from grpc.experimental import aio # type: ignore
34
+ import proto # type: ignore
35
+
36
+ from google.ai.generativelanguage_v1beta.types import tuned_model as gag_tuned_model
37
+ from google.ai.generativelanguage_v1beta.types import model, model_service
38
+ from google.ai.generativelanguage_v1beta.types import tuned_model
39
+
40
+ from .base import DEFAULT_CLIENT_INFO, ModelServiceTransport
41
+ from .grpc import ModelServiceGrpcTransport
42
+
43
+ try:
44
+ from google.api_core import client_logging # type: ignore
45
+
46
+ CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
47
+ except ImportError: # pragma: NO COVER
48
+ CLIENT_LOGGING_SUPPORTED = False
49
+
50
+ _LOGGER = std_logging.getLogger(__name__)
51
+
52
+
53
+ class _LoggingClientAIOInterceptor(
54
+ grpc.aio.UnaryUnaryClientInterceptor
55
+ ): # pragma: NO COVER
56
+ async def intercept_unary_unary(self, continuation, client_call_details, request):
57
+ logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
58
+ std_logging.DEBUG
59
+ )
60
+ if logging_enabled: # pragma: NO COVER
61
+ request_metadata = client_call_details.metadata
62
+ if isinstance(request, proto.Message):
63
+ request_payload = type(request).to_json(request)
64
+ elif isinstance(request, google.protobuf.message.Message):
65
+ request_payload = MessageToJson(request)
66
+ else:
67
+ request_payload = f"{type(request).__name__}: {pickle.dumps(request)}"
68
+
69
+ request_metadata = {
70
+ key: value.decode("utf-8") if isinstance(value, bytes) else value
71
+ for key, value in request_metadata
72
+ }
73
+ grpc_request = {
74
+ "payload": request_payload,
75
+ "requestMethod": "grpc",
76
+ "metadata": dict(request_metadata),
77
+ }
78
+ _LOGGER.debug(
79
+ f"Sending request for {client_call_details.method}",
80
+ extra={
81
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
82
+ "rpcName": str(client_call_details.method),
83
+ "request": grpc_request,
84
+ "metadata": grpc_request["metadata"],
85
+ },
86
+ )
87
+ response = await continuation(client_call_details, request)
88
+ if logging_enabled: # pragma: NO COVER
89
+ response_metadata = await response.trailing_metadata()
90
+ # Convert gRPC metadata `<class 'grpc.aio._metadata.Metadata'>` to list of tuples
91
+ metadata = (
92
+ dict([(k, str(v)) for k, v in response_metadata])
93
+ if response_metadata
94
+ else None
95
+ )
96
+ result = await response
97
+ if isinstance(result, proto.Message):
98
+ response_payload = type(result).to_json(result)
99
+ elif isinstance(result, google.protobuf.message.Message):
100
+ response_payload = MessageToJson(result)
101
+ else:
102
+ response_payload = f"{type(result).__name__}: {pickle.dumps(result)}"
103
+ grpc_response = {
104
+ "payload": response_payload,
105
+ "metadata": metadata,
106
+ "status": "OK",
107
+ }
108
+ _LOGGER.debug(
109
+ f"Received response to rpc {client_call_details.method}.",
110
+ extra={
111
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
112
+ "rpcName": str(client_call_details.method),
113
+ "response": grpc_response,
114
+ "metadata": grpc_response["metadata"],
115
+ },
116
+ )
117
+ return response
118
+
119
+
120
+ class ModelServiceGrpcAsyncIOTransport(ModelServiceTransport):
121
+ """gRPC AsyncIO backend transport for ModelService.
122
+
123
+ Provides methods for getting metadata information about
124
+ Generative Models.
125
+
126
+ This class defines the same methods as the primary client, so the
127
+ primary client can load the underlying transport implementation
128
+ and call it.
129
+
130
+ It sends protocol buffers over the wire using gRPC (which is built on
131
+ top of HTTP/2); the ``grpcio`` package must be installed.
132
+ """
133
+
134
+ _grpc_channel: aio.Channel
135
+ _stubs: Dict[str, Callable] = {}
136
+
137
+ @classmethod
138
+ def create_channel(
139
+ cls,
140
+ host: str = "generativelanguage.googleapis.com",
141
+ credentials: Optional[ga_credentials.Credentials] = None,
142
+ credentials_file: Optional[str] = None,
143
+ scopes: Optional[Sequence[str]] = None,
144
+ quota_project_id: Optional[str] = None,
145
+ **kwargs,
146
+ ) -> aio.Channel:
147
+ """Create and return a gRPC AsyncIO channel object.
148
+ Args:
149
+ host (Optional[str]): The host for the channel to use.
150
+ credentials (Optional[~.Credentials]): The
151
+ authorization credentials to attach to requests. These
152
+ credentials identify this application to the service. If
153
+ none are specified, the client will attempt to ascertain
154
+ the credentials from the environment.
155
+ credentials_file (Optional[str]): A file with credentials that can
156
+ be loaded with :func:`google.auth.load_credentials_from_file`.
157
+ scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
158
+ service. These are only used when credentials are not specified and
159
+ are passed to :func:`google.auth.default`.
160
+ quota_project_id (Optional[str]): An optional project to use for billing
161
+ and quota.
162
+ kwargs (Optional[dict]): Keyword arguments, which are passed to the
163
+ channel creation.
164
+ Returns:
165
+ aio.Channel: A gRPC AsyncIO channel object.
166
+ """
167
+
168
+ return grpc_helpers_async.create_channel(
169
+ host,
170
+ credentials=credentials,
171
+ credentials_file=credentials_file,
172
+ quota_project_id=quota_project_id,
173
+ default_scopes=cls.AUTH_SCOPES,
174
+ scopes=scopes,
175
+ default_host=cls.DEFAULT_HOST,
176
+ **kwargs,
177
+ )
178
+
179
+ def __init__(
180
+ self,
181
+ *,
182
+ host: str = "generativelanguage.googleapis.com",
183
+ credentials: Optional[ga_credentials.Credentials] = None,
184
+ credentials_file: Optional[str] = None,
185
+ scopes: Optional[Sequence[str]] = None,
186
+ channel: Optional[Union[aio.Channel, Callable[..., aio.Channel]]] = None,
187
+ api_mtls_endpoint: Optional[str] = None,
188
+ client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
189
+ ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None,
190
+ client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
191
+ quota_project_id: Optional[str] = None,
192
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
193
+ always_use_jwt_access: Optional[bool] = False,
194
+ api_audience: Optional[str] = None,
195
+ ) -> None:
196
+ """Instantiate the transport.
197
+
198
+ Args:
199
+ host (Optional[str]):
200
+ The hostname to connect to (default: 'generativelanguage.googleapis.com').
201
+ credentials (Optional[google.auth.credentials.Credentials]): The
202
+ authorization credentials to attach to requests. These
203
+ credentials identify the application to the service; if none
204
+ are specified, the client will attempt to ascertain the
205
+ credentials from the environment.
206
+ This argument is ignored if a ``channel`` instance is provided.
207
+ credentials_file (Optional[str]): A file with credentials that can
208
+ be loaded with :func:`google.auth.load_credentials_from_file`.
209
+ This argument is ignored if a ``channel`` instance is provided.
210
+ scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
211
+ service. These are only used when credentials are not specified and
212
+ are passed to :func:`google.auth.default`.
213
+ channel (Optional[Union[aio.Channel, Callable[..., aio.Channel]]]):
214
+ A ``Channel`` instance through which to make calls, or a Callable
215
+ that constructs and returns one. If set to None, ``self.create_channel``
216
+ is used to create the channel. If a Callable is given, it will be called
217
+ with the same arguments as used in ``self.create_channel``.
218
+ api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint.
219
+ If provided, it overrides the ``host`` argument and tries to create
220
+ a mutual TLS channel with client SSL credentials from
221
+ ``client_cert_source`` or application default SSL credentials.
222
+ client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]):
223
+ Deprecated. A callback to provide client SSL certificate bytes and
224
+ private key bytes, both in PEM format. It is ignored if
225
+ ``api_mtls_endpoint`` is None.
226
+ ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials
227
+ for the grpc channel. It is ignored if a ``channel`` instance is provided.
228
+ client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]):
229
+ A callback to provide client certificate bytes and private key bytes,
230
+ both in PEM format. It is used to configure a mutual TLS channel. It is
231
+ ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided.
232
+ quota_project_id (Optional[str]): An optional project to use for billing
233
+ and quota.
234
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
235
+ The client info used to send a user-agent string along with
236
+ API requests. If ``None``, then default info will be used.
237
+ Generally, you only need to set this if you're developing
238
+ your own client library.
239
+ always_use_jwt_access (Optional[bool]): Whether self signed JWT should
240
+ be used for service account credentials.
241
+
242
+ Raises:
243
+ google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
244
+ creation failed for any reason.
245
+ google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
246
+ and ``credentials_file`` are passed.
247
+ """
248
+ self._grpc_channel = None
249
+ self._ssl_channel_credentials = ssl_channel_credentials
250
+ self._stubs: Dict[str, Callable] = {}
251
+ self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None
252
+
253
+ if api_mtls_endpoint:
254
+ warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
255
+ if client_cert_source:
256
+ warnings.warn("client_cert_source is deprecated", DeprecationWarning)
257
+
258
+ if isinstance(channel, aio.Channel):
259
+ # Ignore credentials if a channel was passed.
260
+ credentials = None
261
+ self._ignore_credentials = True
262
+ # If a channel was explicitly provided, set it.
263
+ self._grpc_channel = channel
264
+ self._ssl_channel_credentials = None
265
+ else:
266
+ if api_mtls_endpoint:
267
+ host = api_mtls_endpoint
268
+
269
+ # Create SSL credentials with client_cert_source or application
270
+ # default SSL credentials.
271
+ if client_cert_source:
272
+ cert, key = client_cert_source()
273
+ self._ssl_channel_credentials = grpc.ssl_channel_credentials(
274
+ certificate_chain=cert, private_key=key
275
+ )
276
+ else:
277
+ self._ssl_channel_credentials = SslCredentials().ssl_credentials
278
+
279
+ else:
280
+ if client_cert_source_for_mtls and not ssl_channel_credentials:
281
+ cert, key = client_cert_source_for_mtls()
282
+ self._ssl_channel_credentials = grpc.ssl_channel_credentials(
283
+ certificate_chain=cert, private_key=key
284
+ )
285
+
286
+ # The base transport sets the host, credentials and scopes
287
+ super().__init__(
288
+ host=host,
289
+ credentials=credentials,
290
+ credentials_file=credentials_file,
291
+ scopes=scopes,
292
+ quota_project_id=quota_project_id,
293
+ client_info=client_info,
294
+ always_use_jwt_access=always_use_jwt_access,
295
+ api_audience=api_audience,
296
+ )
297
+
298
+ if not self._grpc_channel:
299
+ # initialize with the provided callable or the default channel
300
+ channel_init = channel or type(self).create_channel
301
+ self._grpc_channel = channel_init(
302
+ self._host,
303
+ # use the credentials which are saved
304
+ credentials=self._credentials,
305
+ # Set ``credentials_file`` to ``None`` here as
306
+ # the credentials that we saved earlier should be used.
307
+ credentials_file=None,
308
+ scopes=self._scopes,
309
+ ssl_credentials=self._ssl_channel_credentials,
310
+ quota_project_id=quota_project_id,
311
+ options=[
312
+ ("grpc.max_send_message_length", -1),
313
+ ("grpc.max_receive_message_length", -1),
314
+ ],
315
+ )
316
+
317
+ self._interceptor = _LoggingClientAIOInterceptor()
318
+ self._grpc_channel._unary_unary_interceptors.append(self._interceptor)
319
+ self._logged_channel = self._grpc_channel
320
+ self._wrap_with_kind = (
321
+ "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters
322
+ )
323
+ # Wrap messages. This must be done after self._logged_channel exists
324
+ self._prep_wrapped_messages(client_info)
325
+
326
+ @property
327
+ def grpc_channel(self) -> aio.Channel:
328
+ """Create the channel designed to connect to this service.
329
+
330
+ This property caches on the instance; repeated calls return
331
+ the same channel.
332
+ """
333
+ # Return the channel from cache.
334
+ return self._grpc_channel
335
+
336
+ @property
337
+ def operations_client(self) -> operations_v1.OperationsAsyncClient:
338
+ """Create the client designed to process long-running operations.
339
+
340
+ This property caches on the instance; repeated calls return the same
341
+ client.
342
+ """
343
+ # Quick check: Only create a new client if we do not already have one.
344
+ if self._operations_client is None:
345
+ self._operations_client = operations_v1.OperationsAsyncClient(
346
+ self._logged_channel
347
+ )
348
+
349
+ # Return the client from cache.
350
+ return self._operations_client
351
+
352
+ @property
353
+ def get_model(
354
+ self,
355
+ ) -> Callable[[model_service.GetModelRequest], Awaitable[model.Model]]:
356
+ r"""Return a callable for the get model method over gRPC.
357
+
358
+ Gets information about a specific ``Model`` such as its version
359
+ number, token limits,
360
+ `parameters <https://ai.google.dev/gemini-api/docs/models/generative-models#model-parameters>`__
361
+ and other metadata. Refer to the `Gemini models
362
+ guide <https://ai.google.dev/gemini-api/docs/models/gemini>`__
363
+ for detailed model information.
364
+
365
+ Returns:
366
+ Callable[[~.GetModelRequest],
367
+ Awaitable[~.Model]]:
368
+ A function that, when called, will call the underlying RPC
369
+ on the server.
370
+ """
371
+ # Generate a "stub function" on-the-fly which will actually make
372
+ # the request.
373
+ # gRPC handles serialization and deserialization, so we just need
374
+ # to pass in the functions for each.
375
+ if "get_model" not in self._stubs:
376
+ self._stubs["get_model"] = self._logged_channel.unary_unary(
377
+ "/google.ai.generativelanguage.v1beta.ModelService/GetModel",
378
+ request_serializer=model_service.GetModelRequest.serialize,
379
+ response_deserializer=model.Model.deserialize,
380
+ )
381
+ return self._stubs["get_model"]
382
+
383
+ @property
384
+ def list_models(
385
+ self,
386
+ ) -> Callable[
387
+ [model_service.ListModelsRequest], Awaitable[model_service.ListModelsResponse]
388
+ ]:
389
+ r"""Return a callable for the list models method over gRPC.
390
+
391
+ Lists the
392
+ ```Model``\ s <https://ai.google.dev/gemini-api/docs/models/gemini>`__
393
+ available through the Gemini API.
394
+
395
+ Returns:
396
+ Callable[[~.ListModelsRequest],
397
+ Awaitable[~.ListModelsResponse]]:
398
+ A function that, when called, will call the underlying RPC
399
+ on the server.
400
+ """
401
+ # Generate a "stub function" on-the-fly which will actually make
402
+ # the request.
403
+ # gRPC handles serialization and deserialization, so we just need
404
+ # to pass in the functions for each.
405
+ if "list_models" not in self._stubs:
406
+ self._stubs["list_models"] = self._logged_channel.unary_unary(
407
+ "/google.ai.generativelanguage.v1beta.ModelService/ListModels",
408
+ request_serializer=model_service.ListModelsRequest.serialize,
409
+ response_deserializer=model_service.ListModelsResponse.deserialize,
410
+ )
411
+ return self._stubs["list_models"]
412
+
413
+ @property
414
+ def get_tuned_model(
415
+ self,
416
+ ) -> Callable[
417
+ [model_service.GetTunedModelRequest], Awaitable[tuned_model.TunedModel]
418
+ ]:
419
+ r"""Return a callable for the get tuned model method over gRPC.
420
+
421
+ Gets information about a specific TunedModel.
422
+
423
+ Returns:
424
+ Callable[[~.GetTunedModelRequest],
425
+ Awaitable[~.TunedModel]]:
426
+ A function that, when called, will call the underlying RPC
427
+ on the server.
428
+ """
429
+ # Generate a "stub function" on-the-fly which will actually make
430
+ # the request.
431
+ # gRPC handles serialization and deserialization, so we just need
432
+ # to pass in the functions for each.
433
+ if "get_tuned_model" not in self._stubs:
434
+ self._stubs["get_tuned_model"] = self._logged_channel.unary_unary(
435
+ "/google.ai.generativelanguage.v1beta.ModelService/GetTunedModel",
436
+ request_serializer=model_service.GetTunedModelRequest.serialize,
437
+ response_deserializer=tuned_model.TunedModel.deserialize,
438
+ )
439
+ return self._stubs["get_tuned_model"]
440
+
441
+ @property
442
+ def list_tuned_models(
443
+ self,
444
+ ) -> Callable[
445
+ [model_service.ListTunedModelsRequest],
446
+ Awaitable[model_service.ListTunedModelsResponse],
447
+ ]:
448
+ r"""Return a callable for the list tuned models method over gRPC.
449
+
450
+ Lists created tuned models.
451
+
452
+ Returns:
453
+ Callable[[~.ListTunedModelsRequest],
454
+ Awaitable[~.ListTunedModelsResponse]]:
455
+ A function that, when called, will call the underlying RPC
456
+ on the server.
457
+ """
458
+ # Generate a "stub function" on-the-fly which will actually make
459
+ # the request.
460
+ # gRPC handles serialization and deserialization, so we just need
461
+ # to pass in the functions for each.
462
+ if "list_tuned_models" not in self._stubs:
463
+ self._stubs["list_tuned_models"] = self._logged_channel.unary_unary(
464
+ "/google.ai.generativelanguage.v1beta.ModelService/ListTunedModels",
465
+ request_serializer=model_service.ListTunedModelsRequest.serialize,
466
+ response_deserializer=model_service.ListTunedModelsResponse.deserialize,
467
+ )
468
+ return self._stubs["list_tuned_models"]
469
+
470
+ @property
471
+ def create_tuned_model(
472
+ self,
473
+ ) -> Callable[
474
+ [model_service.CreateTunedModelRequest], Awaitable[operations_pb2.Operation]
475
+ ]:
476
+ r"""Return a callable for the create tuned model method over gRPC.
477
+
478
+ Creates a tuned model. Check intermediate tuning progress (if
479
+ any) through the [google.longrunning.Operations] service.
480
+
481
+ Access status and results through the Operations service.
482
+ Example: GET /v1/tunedModels/az2mb0bpw6i/operations/000-111-222
483
+
484
+ Returns:
485
+ Callable[[~.CreateTunedModelRequest],
486
+ Awaitable[~.Operation]]:
487
+ A function that, when called, will call the underlying RPC
488
+ on the server.
489
+ """
490
+ # Generate a "stub function" on-the-fly which will actually make
491
+ # the request.
492
+ # gRPC handles serialization and deserialization, so we just need
493
+ # to pass in the functions for each.
494
+ if "create_tuned_model" not in self._stubs:
495
+ self._stubs["create_tuned_model"] = self._logged_channel.unary_unary(
496
+ "/google.ai.generativelanguage.v1beta.ModelService/CreateTunedModel",
497
+ request_serializer=model_service.CreateTunedModelRequest.serialize,
498
+ response_deserializer=operations_pb2.Operation.FromString,
499
+ )
500
+ return self._stubs["create_tuned_model"]
501
+
502
+ @property
503
+ def update_tuned_model(
504
+ self,
505
+ ) -> Callable[
506
+ [model_service.UpdateTunedModelRequest], Awaitable[gag_tuned_model.TunedModel]
507
+ ]:
508
+ r"""Return a callable for the update tuned model method over gRPC.
509
+
510
+ Updates a tuned model.
511
+
512
+ Returns:
513
+ Callable[[~.UpdateTunedModelRequest],
514
+ Awaitable[~.TunedModel]]:
515
+ A function that, when called, will call the underlying RPC
516
+ on the server.
517
+ """
518
+ # Generate a "stub function" on-the-fly which will actually make
519
+ # the request.
520
+ # gRPC handles serialization and deserialization, so we just need
521
+ # to pass in the functions for each.
522
+ if "update_tuned_model" not in self._stubs:
523
+ self._stubs["update_tuned_model"] = self._logged_channel.unary_unary(
524
+ "/google.ai.generativelanguage.v1beta.ModelService/UpdateTunedModel",
525
+ request_serializer=model_service.UpdateTunedModelRequest.serialize,
526
+ response_deserializer=gag_tuned_model.TunedModel.deserialize,
527
+ )
528
+ return self._stubs["update_tuned_model"]
529
+
530
+ @property
531
+ def delete_tuned_model(
532
+ self,
533
+ ) -> Callable[[model_service.DeleteTunedModelRequest], Awaitable[empty_pb2.Empty]]:
534
+ r"""Return a callable for the delete tuned model method over gRPC.
535
+
536
+ Deletes a tuned model.
537
+
538
+ Returns:
539
+ Callable[[~.DeleteTunedModelRequest],
540
+ Awaitable[~.Empty]]:
541
+ A function that, when called, will call the underlying RPC
542
+ on the server.
543
+ """
544
+ # Generate a "stub function" on-the-fly which will actually make
545
+ # the request.
546
+ # gRPC handles serialization and deserialization, so we just need
547
+ # to pass in the functions for each.
548
+ if "delete_tuned_model" not in self._stubs:
549
+ self._stubs["delete_tuned_model"] = self._logged_channel.unary_unary(
550
+ "/google.ai.generativelanguage.v1beta.ModelService/DeleteTunedModel",
551
+ request_serializer=model_service.DeleteTunedModelRequest.serialize,
552
+ response_deserializer=empty_pb2.Empty.FromString,
553
+ )
554
+ return self._stubs["delete_tuned_model"]
555
+
556
+ def _prep_wrapped_messages(self, client_info):
557
+ """Precompute the wrapped methods, overriding the base class method to use async wrappers."""
558
+ self._wrapped_methods = {
559
+ self.get_model: self._wrap_method(
560
+ self.get_model,
561
+ default_retry=retries.AsyncRetry(
562
+ initial=1.0,
563
+ maximum=10.0,
564
+ multiplier=1.3,
565
+ predicate=retries.if_exception_type(
566
+ core_exceptions.ServiceUnavailable,
567
+ ),
568
+ deadline=60.0,
569
+ ),
570
+ default_timeout=60.0,
571
+ client_info=client_info,
572
+ ),
573
+ self.list_models: self._wrap_method(
574
+ self.list_models,
575
+ default_retry=retries.AsyncRetry(
576
+ initial=1.0,
577
+ maximum=10.0,
578
+ multiplier=1.3,
579
+ predicate=retries.if_exception_type(
580
+ core_exceptions.ServiceUnavailable,
581
+ ),
582
+ deadline=60.0,
583
+ ),
584
+ default_timeout=60.0,
585
+ client_info=client_info,
586
+ ),
587
+ self.get_tuned_model: self._wrap_method(
588
+ self.get_tuned_model,
589
+ default_retry=retries.AsyncRetry(
590
+ initial=1.0,
591
+ maximum=10.0,
592
+ multiplier=1.3,
593
+ predicate=retries.if_exception_type(
594
+ core_exceptions.ServiceUnavailable,
595
+ ),
596
+ deadline=60.0,
597
+ ),
598
+ default_timeout=60.0,
599
+ client_info=client_info,
600
+ ),
601
+ self.list_tuned_models: self._wrap_method(
602
+ self.list_tuned_models,
603
+ default_retry=retries.AsyncRetry(
604
+ initial=1.0,
605
+ maximum=10.0,
606
+ multiplier=1.3,
607
+ predicate=retries.if_exception_type(
608
+ core_exceptions.ServiceUnavailable,
609
+ ),
610
+ deadline=60.0,
611
+ ),
612
+ default_timeout=60.0,
613
+ client_info=client_info,
614
+ ),
615
+ self.create_tuned_model: self._wrap_method(
616
+ self.create_tuned_model,
617
+ default_retry=retries.AsyncRetry(
618
+ initial=1.0,
619
+ maximum=10.0,
620
+ multiplier=1.3,
621
+ predicate=retries.if_exception_type(
622
+ core_exceptions.ServiceUnavailable,
623
+ ),
624
+ deadline=60.0,
625
+ ),
626
+ default_timeout=60.0,
627
+ client_info=client_info,
628
+ ),
629
+ self.update_tuned_model: self._wrap_method(
630
+ self.update_tuned_model,
631
+ default_retry=retries.AsyncRetry(
632
+ initial=1.0,
633
+ maximum=10.0,
634
+ multiplier=1.3,
635
+ predicate=retries.if_exception_type(
636
+ core_exceptions.ServiceUnavailable,
637
+ ),
638
+ deadline=60.0,
639
+ ),
640
+ default_timeout=60.0,
641
+ client_info=client_info,
642
+ ),
643
+ self.delete_tuned_model: self._wrap_method(
644
+ self.delete_tuned_model,
645
+ default_retry=retries.AsyncRetry(
646
+ initial=1.0,
647
+ maximum=10.0,
648
+ multiplier=1.3,
649
+ predicate=retries.if_exception_type(
650
+ core_exceptions.ServiceUnavailable,
651
+ ),
652
+ deadline=60.0,
653
+ ),
654
+ default_timeout=60.0,
655
+ client_info=client_info,
656
+ ),
657
+ self.get_operation: self._wrap_method(
658
+ self.get_operation,
659
+ default_timeout=None,
660
+ client_info=client_info,
661
+ ),
662
+ self.list_operations: self._wrap_method(
663
+ self.list_operations,
664
+ default_timeout=None,
665
+ client_info=client_info,
666
+ ),
667
+ }
668
+
669
+ def _wrap_method(self, func, *args, **kwargs):
670
+ if self._wrap_with_kind: # pragma: NO COVER
671
+ kwargs["kind"] = self.kind
672
+ return gapic_v1.method_async.wrap_method(func, *args, **kwargs)
673
+
674
+ def close(self):
675
+ return self._logged_channel.close()
676
+
677
+ @property
678
+ def kind(self) -> str:
679
+ return "grpc_asyncio"
680
+
681
+ @property
682
+ def get_operation(
683
+ self,
684
+ ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]:
685
+ r"""Return a callable for the get_operation method over gRPC."""
686
+ # Generate a "stub function" on-the-fly which will actually make
687
+ # the request.
688
+ # gRPC handles serialization and deserialization, so we just need
689
+ # to pass in the functions for each.
690
+ if "get_operation" not in self._stubs:
691
+ self._stubs["get_operation"] = self._logged_channel.unary_unary(
692
+ "/google.longrunning.Operations/GetOperation",
693
+ request_serializer=operations_pb2.GetOperationRequest.SerializeToString,
694
+ response_deserializer=operations_pb2.Operation.FromString,
695
+ )
696
+ return self._stubs["get_operation"]
697
+
698
+ @property
699
+ def list_operations(
700
+ self,
701
+ ) -> Callable[
702
+ [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse
703
+ ]:
704
+ r"""Return a callable for the list_operations method over gRPC."""
705
+ # Generate a "stub function" on-the-fly which will actually make
706
+ # the request.
707
+ # gRPC handles serialization and deserialization, so we just need
708
+ # to pass in the functions for each.
709
+ if "list_operations" not in self._stubs:
710
+ self._stubs["list_operations"] = self._logged_channel.unary_unary(
711
+ "/google.longrunning.Operations/ListOperations",
712
+ request_serializer=operations_pb2.ListOperationsRequest.SerializeToString,
713
+ response_deserializer=operations_pb2.ListOperationsResponse.FromString,
714
+ )
715
+ return self._stubs["list_operations"]
716
+
717
+
718
+ __all__ = ("ModelServiceGrpcAsyncIOTransport",)
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/transports/rest.py ADDED
@@ -0,0 +1,1819 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ import dataclasses
17
+ import json # type: ignore
18
+ import logging
19
+ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
20
+ import warnings
21
+
22
+ from google.api_core import gapic_v1, operations_v1, rest_helpers, rest_streaming
23
+ from google.api_core import exceptions as core_exceptions
24
+ from google.api_core import retry as retries
25
+ from google.auth import credentials as ga_credentials # type: ignore
26
+ from google.auth.transport.requests import AuthorizedSession # type: ignore
27
+ from google.longrunning import operations_pb2 # type: ignore
28
+ from google.protobuf import empty_pb2 # type: ignore
29
+ from google.protobuf import json_format
30
+ from requests import __version__ as requests_version
31
+
32
+ from google.ai.generativelanguage_v1beta.types import tuned_model as gag_tuned_model
33
+ from google.ai.generativelanguage_v1beta.types import model, model_service
34
+ from google.ai.generativelanguage_v1beta.types import tuned_model
35
+
36
+ from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO
37
+ from .rest_base import _BaseModelServiceRestTransport
38
+
39
+ try:
40
+ OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
41
+ except AttributeError: # pragma: NO COVER
42
+ OptionalRetry = Union[retries.Retry, object, None] # type: ignore
43
+
44
+ try:
45
+ from google.api_core import client_logging # type: ignore
46
+
47
+ CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
48
+ except ImportError: # pragma: NO COVER
49
+ CLIENT_LOGGING_SUPPORTED = False
50
+
51
+ _LOGGER = logging.getLogger(__name__)
52
+
53
+ DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
54
+ gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version,
55
+ grpc_version=None,
56
+ rest_version=f"requests@{requests_version}",
57
+ )
58
+
59
+
60
+ class ModelServiceRestInterceptor:
61
+ """Interceptor for ModelService.
62
+
63
+ Interceptors are used to manipulate requests, request metadata, and responses
64
+ in arbitrary ways.
65
+ Example use cases include:
66
+ * Logging
67
+ * Verifying requests according to service or custom semantics
68
+ * Stripping extraneous information from responses
69
+
70
+ These use cases and more can be enabled by injecting an
71
+ instance of a custom subclass when constructing the ModelServiceRestTransport.
72
+
73
+ .. code-block:: python
74
+ class MyCustomModelServiceInterceptor(ModelServiceRestInterceptor):
75
+ def pre_create_tuned_model(self, request, metadata):
76
+ logging.log(f"Received request: {request}")
77
+ return request, metadata
78
+
79
+ def post_create_tuned_model(self, response):
80
+ logging.log(f"Received response: {response}")
81
+ return response
82
+
83
+ def pre_delete_tuned_model(self, request, metadata):
84
+ logging.log(f"Received request: {request}")
85
+ return request, metadata
86
+
87
+ def pre_get_model(self, request, metadata):
88
+ logging.log(f"Received request: {request}")
89
+ return request, metadata
90
+
91
+ def post_get_model(self, response):
92
+ logging.log(f"Received response: {response}")
93
+ return response
94
+
95
+ def pre_get_tuned_model(self, request, metadata):
96
+ logging.log(f"Received request: {request}")
97
+ return request, metadata
98
+
99
+ def post_get_tuned_model(self, response):
100
+ logging.log(f"Received response: {response}")
101
+ return response
102
+
103
+ def pre_list_models(self, request, metadata):
104
+ logging.log(f"Received request: {request}")
105
+ return request, metadata
106
+
107
+ def post_list_models(self, response):
108
+ logging.log(f"Received response: {response}")
109
+ return response
110
+
111
+ def pre_list_tuned_models(self, request, metadata):
112
+ logging.log(f"Received request: {request}")
113
+ return request, metadata
114
+
115
+ def post_list_tuned_models(self, response):
116
+ logging.log(f"Received response: {response}")
117
+ return response
118
+
119
+ def pre_update_tuned_model(self, request, metadata):
120
+ logging.log(f"Received request: {request}")
121
+ return request, metadata
122
+
123
+ def post_update_tuned_model(self, response):
124
+ logging.log(f"Received response: {response}")
125
+ return response
126
+
127
+ transport = ModelServiceRestTransport(interceptor=MyCustomModelServiceInterceptor())
128
+ client = ModelServiceClient(transport=transport)
129
+
130
+
131
+ """
132
+
133
+ def pre_create_tuned_model(
134
+ self,
135
+ request: model_service.CreateTunedModelRequest,
136
+ metadata: Sequence[Tuple[str, Union[str, bytes]]],
137
+ ) -> Tuple[
138
+ model_service.CreateTunedModelRequest, Sequence[Tuple[str, Union[str, bytes]]]
139
+ ]:
140
+ """Pre-rpc interceptor for create_tuned_model
141
+
142
+ Override in a subclass to manipulate the request or metadata
143
+ before they are sent to the ModelService server.
144
+ """
145
+ return request, metadata
146
+
147
+ def post_create_tuned_model(
148
+ self, response: operations_pb2.Operation
149
+ ) -> operations_pb2.Operation:
150
+ """Post-rpc interceptor for create_tuned_model
151
+
152
+ Override in a subclass to manipulate the response
153
+ after it is returned by the ModelService server but before
154
+ it is returned to user code.
155
+ """
156
+ return response
157
+
158
+ def pre_delete_tuned_model(
159
+ self,
160
+ request: model_service.DeleteTunedModelRequest,
161
+ metadata: Sequence[Tuple[str, Union[str, bytes]]],
162
+ ) -> Tuple[
163
+ model_service.DeleteTunedModelRequest, Sequence[Tuple[str, Union[str, bytes]]]
164
+ ]:
165
+ """Pre-rpc interceptor for delete_tuned_model
166
+
167
+ Override in a subclass to manipulate the request or metadata
168
+ before they are sent to the ModelService server.
169
+ """
170
+ return request, metadata
171
+
172
+ def pre_get_model(
173
+ self,
174
+ request: model_service.GetModelRequest,
175
+ metadata: Sequence[Tuple[str, Union[str, bytes]]],
176
+ ) -> Tuple[model_service.GetModelRequest, Sequence[Tuple[str, Union[str, bytes]]]]:
177
+ """Pre-rpc interceptor for get_model
178
+
179
+ Override in a subclass to manipulate the request or metadata
180
+ before they are sent to the ModelService server.
181
+ """
182
+ return request, metadata
183
+
184
+ def post_get_model(self, response: model.Model) -> model.Model:
185
+ """Post-rpc interceptor for get_model
186
+
187
+ Override in a subclass to manipulate the response
188
+ after it is returned by the ModelService server but before
189
+ it is returned to user code.
190
+ """
191
+ return response
192
+
193
+ def pre_get_tuned_model(
194
+ self,
195
+ request: model_service.GetTunedModelRequest,
196
+ metadata: Sequence[Tuple[str, Union[str, bytes]]],
197
+ ) -> Tuple[
198
+ model_service.GetTunedModelRequest, Sequence[Tuple[str, Union[str, bytes]]]
199
+ ]:
200
+ """Pre-rpc interceptor for get_tuned_model
201
+
202
+ Override in a subclass to manipulate the request or metadata
203
+ before they are sent to the ModelService server.
204
+ """
205
+ return request, metadata
206
+
207
+ def post_get_tuned_model(
208
+ self, response: tuned_model.TunedModel
209
+ ) -> tuned_model.TunedModel:
210
+ """Post-rpc interceptor for get_tuned_model
211
+
212
+ Override in a subclass to manipulate the response
213
+ after it is returned by the ModelService server but before
214
+ it is returned to user code.
215
+ """
216
+ return response
217
+
218
+ def pre_list_models(
219
+ self,
220
+ request: model_service.ListModelsRequest,
221
+ metadata: Sequence[Tuple[str, Union[str, bytes]]],
222
+ ) -> Tuple[
223
+ model_service.ListModelsRequest, Sequence[Tuple[str, Union[str, bytes]]]
224
+ ]:
225
+ """Pre-rpc interceptor for list_models
226
+
227
+ Override in a subclass to manipulate the request or metadata
228
+ before they are sent to the ModelService server.
229
+ """
230
+ return request, metadata
231
+
232
+ def post_list_models(
233
+ self, response: model_service.ListModelsResponse
234
+ ) -> model_service.ListModelsResponse:
235
+ """Post-rpc interceptor for list_models
236
+
237
+ Override in a subclass to manipulate the response
238
+ after it is returned by the ModelService server but before
239
+ it is returned to user code.
240
+ """
241
+ return response
242
+
243
+ def pre_list_tuned_models(
244
+ self,
245
+ request: model_service.ListTunedModelsRequest,
246
+ metadata: Sequence[Tuple[str, Union[str, bytes]]],
247
+ ) -> Tuple[
248
+ model_service.ListTunedModelsRequest, Sequence[Tuple[str, Union[str, bytes]]]
249
+ ]:
250
+ """Pre-rpc interceptor for list_tuned_models
251
+
252
+ Override in a subclass to manipulate the request or metadata
253
+ before they are sent to the ModelService server.
254
+ """
255
+ return request, metadata
256
+
257
+ def post_list_tuned_models(
258
+ self, response: model_service.ListTunedModelsResponse
259
+ ) -> model_service.ListTunedModelsResponse:
260
+ """Post-rpc interceptor for list_tuned_models
261
+
262
+ Override in a subclass to manipulate the response
263
+ after it is returned by the ModelService server but before
264
+ it is returned to user code.
265
+ """
266
+ return response
267
+
268
+ def pre_update_tuned_model(
269
+ self,
270
+ request: model_service.UpdateTunedModelRequest,
271
+ metadata: Sequence[Tuple[str, Union[str, bytes]]],
272
+ ) -> Tuple[
273
+ model_service.UpdateTunedModelRequest, Sequence[Tuple[str, Union[str, bytes]]]
274
+ ]:
275
+ """Pre-rpc interceptor for update_tuned_model
276
+
277
+ Override in a subclass to manipulate the request or metadata
278
+ before they are sent to the ModelService server.
279
+ """
280
+ return request, metadata
281
+
282
+ def post_update_tuned_model(
283
+ self, response: gag_tuned_model.TunedModel
284
+ ) -> gag_tuned_model.TunedModel:
285
+ """Post-rpc interceptor for update_tuned_model
286
+
287
+ Override in a subclass to manipulate the response
288
+ after it is returned by the ModelService server but before
289
+ it is returned to user code.
290
+ """
291
+ return response
292
+
293
+ def pre_get_operation(
294
+ self,
295
+ request: operations_pb2.GetOperationRequest,
296
+ metadata: Sequence[Tuple[str, Union[str, bytes]]],
297
+ ) -> Tuple[
298
+ operations_pb2.GetOperationRequest, Sequence[Tuple[str, Union[str, bytes]]]
299
+ ]:
300
+ """Pre-rpc interceptor for get_operation
301
+
302
+ Override in a subclass to manipulate the request or metadata
303
+ before they are sent to the ModelService server.
304
+ """
305
+ return request, metadata
306
+
307
+ def post_get_operation(
308
+ self, response: operations_pb2.Operation
309
+ ) -> operations_pb2.Operation:
310
+ """Post-rpc interceptor for get_operation
311
+
312
+ Override in a subclass to manipulate the response
313
+ after it is returned by the ModelService server but before
314
+ it is returned to user code.
315
+ """
316
+ return response
317
+
318
+ def pre_list_operations(
319
+ self,
320
+ request: operations_pb2.ListOperationsRequest,
321
+ metadata: Sequence[Tuple[str, Union[str, bytes]]],
322
+ ) -> Tuple[
323
+ operations_pb2.ListOperationsRequest, Sequence[Tuple[str, Union[str, bytes]]]
324
+ ]:
325
+ """Pre-rpc interceptor for list_operations
326
+
327
+ Override in a subclass to manipulate the request or metadata
328
+ before they are sent to the ModelService server.
329
+ """
330
+ return request, metadata
331
+
332
+ def post_list_operations(
333
+ self, response: operations_pb2.ListOperationsResponse
334
+ ) -> operations_pb2.ListOperationsResponse:
335
+ """Post-rpc interceptor for list_operations
336
+
337
+ Override in a subclass to manipulate the response
338
+ after it is returned by the ModelService server but before
339
+ it is returned to user code.
340
+ """
341
+ return response
342
+
343
+
344
+ @dataclasses.dataclass
345
+ class ModelServiceRestStub:
346
+ _session: AuthorizedSession
347
+ _host: str
348
+ _interceptor: ModelServiceRestInterceptor
349
+
350
+
351
+ class ModelServiceRestTransport(_BaseModelServiceRestTransport):
352
+ """REST backend synchronous transport for ModelService.
353
+
354
+ Provides methods for getting metadata information about
355
+ Generative Models.
356
+
357
+ This class defines the same methods as the primary client, so the
358
+ primary client can load the underlying transport implementation
359
+ and call it.
360
+
361
+ It sends JSON representations of protocol buffers over HTTP/1.1
362
+ """
363
+
364
+ def __init__(
365
+ self,
366
+ *,
367
+ host: str = "generativelanguage.googleapis.com",
368
+ credentials: Optional[ga_credentials.Credentials] = None,
369
+ credentials_file: Optional[str] = None,
370
+ scopes: Optional[Sequence[str]] = None,
371
+ client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
372
+ quota_project_id: Optional[str] = None,
373
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
374
+ always_use_jwt_access: Optional[bool] = False,
375
+ url_scheme: str = "https",
376
+ interceptor: Optional[ModelServiceRestInterceptor] = None,
377
+ api_audience: Optional[str] = None,
378
+ ) -> None:
379
+ """Instantiate the transport.
380
+
381
+ Args:
382
+ host (Optional[str]):
383
+ The hostname to connect to (default: 'generativelanguage.googleapis.com').
384
+ credentials (Optional[google.auth.credentials.Credentials]): The
385
+ authorization credentials to attach to requests. These
386
+ credentials identify the application to the service; if none
387
+ are specified, the client will attempt to ascertain the
388
+ credentials from the environment.
389
+
390
+ credentials_file (Optional[str]): A file with credentials that can
391
+ be loaded with :func:`google.auth.load_credentials_from_file`.
392
+ This argument is ignored if ``channel`` is provided.
393
+ scopes (Optional(Sequence[str])): A list of scopes. This argument is
394
+ ignored if ``channel`` is provided.
395
+ client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client
396
+ certificate to configure mutual TLS HTTP channel. It is ignored
397
+ if ``channel`` is provided.
398
+ quota_project_id (Optional[str]): An optional project to use for billing
399
+ and quota.
400
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
401
+ The client info used to send a user-agent string along with
402
+ API requests. If ``None``, then default info will be used.
403
+ Generally, you only need to set this if you are developing
404
+ your own client library.
405
+ always_use_jwt_access (Optional[bool]): Whether self signed JWT should
406
+ be used for service account credentials.
407
+ url_scheme: the protocol scheme for the API endpoint. Normally
408
+ "https", but for testing or local servers,
409
+ "http" can be specified.
410
+ """
411
+ # Run the base constructor
412
+ # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc.
413
+ # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the
414
+ # credentials object
415
+ super().__init__(
416
+ host=host,
417
+ credentials=credentials,
418
+ client_info=client_info,
419
+ always_use_jwt_access=always_use_jwt_access,
420
+ url_scheme=url_scheme,
421
+ api_audience=api_audience,
422
+ )
423
+ self._session = AuthorizedSession(
424
+ self._credentials, default_host=self.DEFAULT_HOST
425
+ )
426
+ self._operations_client: Optional[operations_v1.AbstractOperationsClient] = None
427
+ if client_cert_source_for_mtls:
428
+ self._session.configure_mtls_channel(client_cert_source_for_mtls)
429
+ self._interceptor = interceptor or ModelServiceRestInterceptor()
430
+ self._prep_wrapped_messages(client_info)
431
+
432
+ @property
433
+ def operations_client(self) -> operations_v1.AbstractOperationsClient:
434
+ """Create the client designed to process long-running operations.
435
+
436
+ This property caches on the instance; repeated calls return the same
437
+ client.
438
+ """
439
+ # Only create a new client if we do not already have one.
440
+ if self._operations_client is None:
441
+ http_options: Dict[str, List[Dict[str, str]]] = {
442
+ "google.longrunning.Operations.GetOperation": [
443
+ {
444
+ "method": "get",
445
+ "uri": "/v1beta/{name=tunedModels/*/operations/*}",
446
+ },
447
+ {
448
+ "method": "get",
449
+ "uri": "/v1beta/{name=generatedFiles/*/operations/*}",
450
+ },
451
+ {
452
+ "method": "get",
453
+ "uri": "/v1beta/{name=models/*/operations/*}",
454
+ },
455
+ ],
456
+ "google.longrunning.Operations.ListOperations": [
457
+ {
458
+ "method": "get",
459
+ "uri": "/v1beta/{name=tunedModels/*}/operations",
460
+ },
461
+ {
462
+ "method": "get",
463
+ "uri": "/v1beta/{name=models/*}/operations",
464
+ },
465
+ ],
466
+ }
467
+
468
+ rest_transport = operations_v1.OperationsRestTransport(
469
+ host=self._host,
470
+ # use the credentials which are saved
471
+ credentials=self._credentials,
472
+ scopes=self._scopes,
473
+ http_options=http_options,
474
+ path_prefix="v1beta",
475
+ )
476
+
477
+ self._operations_client = operations_v1.AbstractOperationsClient(
478
+ transport=rest_transport
479
+ )
480
+
481
+ # Return the client from cache.
482
+ return self._operations_client
483
+
484
+ class _CreateTunedModel(
485
+ _BaseModelServiceRestTransport._BaseCreateTunedModel, ModelServiceRestStub
486
+ ):
487
+ def __hash__(self):
488
+ return hash("ModelServiceRestTransport.CreateTunedModel")
489
+
490
+ @staticmethod
491
+ def _get_response(
492
+ host,
493
+ metadata,
494
+ query_params,
495
+ session,
496
+ timeout,
497
+ transcoded_request,
498
+ body=None,
499
+ ):
500
+ uri = transcoded_request["uri"]
501
+ method = transcoded_request["method"]
502
+ headers = dict(metadata)
503
+ headers["Content-Type"] = "application/json"
504
+ response = getattr(session, method)(
505
+ "{host}{uri}".format(host=host, uri=uri),
506
+ timeout=timeout,
507
+ headers=headers,
508
+ params=rest_helpers.flatten_query_params(query_params, strict=True),
509
+ data=body,
510
+ )
511
+ return response
512
+
513
+ def __call__(
514
+ self,
515
+ request: model_service.CreateTunedModelRequest,
516
+ *,
517
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
518
+ timeout: Optional[float] = None,
519
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
520
+ ) -> operations_pb2.Operation:
521
+ r"""Call the create tuned model method over HTTP.
522
+
523
+ Args:
524
+ request (~.model_service.CreateTunedModelRequest):
525
+ The request object. Request to create a TunedModel.
526
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
527
+ should be retried.
528
+ timeout (float): The timeout for this request.
529
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
530
+ sent along with the request as metadata. Normally, each value must be of type `str`,
531
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
532
+ be of type `bytes`.
533
+
534
+ Returns:
535
+ ~.operations_pb2.Operation:
536
+ This resource represents a
537
+ long-running operation that is the
538
+ result of a network API call.
539
+
540
+ """
541
+
542
+ http_options = (
543
+ _BaseModelServiceRestTransport._BaseCreateTunedModel._get_http_options()
544
+ )
545
+
546
+ request, metadata = self._interceptor.pre_create_tuned_model(
547
+ request, metadata
548
+ )
549
+ transcoded_request = _BaseModelServiceRestTransport._BaseCreateTunedModel._get_transcoded_request(
550
+ http_options, request
551
+ )
552
+
553
+ body = _BaseModelServiceRestTransport._BaseCreateTunedModel._get_request_body_json(
554
+ transcoded_request
555
+ )
556
+
557
+ # Jsonify the query params
558
+ query_params = _BaseModelServiceRestTransport._BaseCreateTunedModel._get_query_params_json(
559
+ transcoded_request
560
+ )
561
+
562
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
563
+ logging.DEBUG
564
+ ): # pragma: NO COVER
565
+ request_url = "{host}{uri}".format(
566
+ host=self._host, uri=transcoded_request["uri"]
567
+ )
568
+ method = transcoded_request["method"]
569
+ try:
570
+ request_payload = json_format.MessageToJson(request)
571
+ except:
572
+ request_payload = None
573
+ http_request = {
574
+ "payload": request_payload,
575
+ "requestMethod": method,
576
+ "requestUrl": request_url,
577
+ "headers": dict(metadata),
578
+ }
579
+ _LOGGER.debug(
580
+ f"Sending request for google.ai.generativelanguage_v1beta.ModelServiceClient.CreateTunedModel",
581
+ extra={
582
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
583
+ "rpcName": "CreateTunedModel",
584
+ "httpRequest": http_request,
585
+ "metadata": http_request["headers"],
586
+ },
587
+ )
588
+
589
+ # Send the request
590
+ response = ModelServiceRestTransport._CreateTunedModel._get_response(
591
+ self._host,
592
+ metadata,
593
+ query_params,
594
+ self._session,
595
+ timeout,
596
+ transcoded_request,
597
+ body,
598
+ )
599
+
600
+ # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
601
+ # subclass.
602
+ if response.status_code >= 400:
603
+ raise core_exceptions.from_http_response(response)
604
+
605
+ # Return the response
606
+ resp = operations_pb2.Operation()
607
+ json_format.Parse(response.content, resp, ignore_unknown_fields=True)
608
+
609
+ resp = self._interceptor.post_create_tuned_model(resp)
610
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
611
+ logging.DEBUG
612
+ ): # pragma: NO COVER
613
+ try:
614
+ response_payload = json_format.MessageToJson(resp)
615
+ except:
616
+ response_payload = None
617
+ http_response = {
618
+ "payload": response_payload,
619
+ "headers": dict(response.headers),
620
+ "status": response.status_code,
621
+ }
622
+ _LOGGER.debug(
623
+ "Received response for google.ai.generativelanguage_v1beta.ModelServiceClient.create_tuned_model",
624
+ extra={
625
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
626
+ "rpcName": "CreateTunedModel",
627
+ "metadata": http_response["headers"],
628
+ "httpResponse": http_response,
629
+ },
630
+ )
631
+ return resp
632
+
633
+ class _DeleteTunedModel(
634
+ _BaseModelServiceRestTransport._BaseDeleteTunedModel, ModelServiceRestStub
635
+ ):
636
+ def __hash__(self):
637
+ return hash("ModelServiceRestTransport.DeleteTunedModel")
638
+
639
+ @staticmethod
640
+ def _get_response(
641
+ host,
642
+ metadata,
643
+ query_params,
644
+ session,
645
+ timeout,
646
+ transcoded_request,
647
+ body=None,
648
+ ):
649
+ uri = transcoded_request["uri"]
650
+ method = transcoded_request["method"]
651
+ headers = dict(metadata)
652
+ headers["Content-Type"] = "application/json"
653
+ response = getattr(session, method)(
654
+ "{host}{uri}".format(host=host, uri=uri),
655
+ timeout=timeout,
656
+ headers=headers,
657
+ params=rest_helpers.flatten_query_params(query_params, strict=True),
658
+ )
659
+ return response
660
+
661
+ def __call__(
662
+ self,
663
+ request: model_service.DeleteTunedModelRequest,
664
+ *,
665
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
666
+ timeout: Optional[float] = None,
667
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
668
+ ):
669
+ r"""Call the delete tuned model method over HTTP.
670
+
671
+ Args:
672
+ request (~.model_service.DeleteTunedModelRequest):
673
+ The request object. Request to delete a TunedModel.
674
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
675
+ should be retried.
676
+ timeout (float): The timeout for this request.
677
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
678
+ sent along with the request as metadata. Normally, each value must be of type `str`,
679
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
680
+ be of type `bytes`.
681
+ """
682
+
683
+ http_options = (
684
+ _BaseModelServiceRestTransport._BaseDeleteTunedModel._get_http_options()
685
+ )
686
+
687
+ request, metadata = self._interceptor.pre_delete_tuned_model(
688
+ request, metadata
689
+ )
690
+ transcoded_request = _BaseModelServiceRestTransport._BaseDeleteTunedModel._get_transcoded_request(
691
+ http_options, request
692
+ )
693
+
694
+ # Jsonify the query params
695
+ query_params = _BaseModelServiceRestTransport._BaseDeleteTunedModel._get_query_params_json(
696
+ transcoded_request
697
+ )
698
+
699
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
700
+ logging.DEBUG
701
+ ): # pragma: NO COVER
702
+ request_url = "{host}{uri}".format(
703
+ host=self._host, uri=transcoded_request["uri"]
704
+ )
705
+ method = transcoded_request["method"]
706
+ try:
707
+ request_payload = json_format.MessageToJson(request)
708
+ except:
709
+ request_payload = None
710
+ http_request = {
711
+ "payload": request_payload,
712
+ "requestMethod": method,
713
+ "requestUrl": request_url,
714
+ "headers": dict(metadata),
715
+ }
716
+ _LOGGER.debug(
717
+ f"Sending request for google.ai.generativelanguage_v1beta.ModelServiceClient.DeleteTunedModel",
718
+ extra={
719
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
720
+ "rpcName": "DeleteTunedModel",
721
+ "httpRequest": http_request,
722
+ "metadata": http_request["headers"],
723
+ },
724
+ )
725
+
726
+ # Send the request
727
+ response = ModelServiceRestTransport._DeleteTunedModel._get_response(
728
+ self._host,
729
+ metadata,
730
+ query_params,
731
+ self._session,
732
+ timeout,
733
+ transcoded_request,
734
+ )
735
+
736
+ # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
737
+ # subclass.
738
+ if response.status_code >= 400:
739
+ raise core_exceptions.from_http_response(response)
740
+
741
+ class _GetModel(_BaseModelServiceRestTransport._BaseGetModel, ModelServiceRestStub):
742
+ def __hash__(self):
743
+ return hash("ModelServiceRestTransport.GetModel")
744
+
745
+ @staticmethod
746
+ def _get_response(
747
+ host,
748
+ metadata,
749
+ query_params,
750
+ session,
751
+ timeout,
752
+ transcoded_request,
753
+ body=None,
754
+ ):
755
+ uri = transcoded_request["uri"]
756
+ method = transcoded_request["method"]
757
+ headers = dict(metadata)
758
+ headers["Content-Type"] = "application/json"
759
+ response = getattr(session, method)(
760
+ "{host}{uri}".format(host=host, uri=uri),
761
+ timeout=timeout,
762
+ headers=headers,
763
+ params=rest_helpers.flatten_query_params(query_params, strict=True),
764
+ )
765
+ return response
766
+
767
+ def __call__(
768
+ self,
769
+ request: model_service.GetModelRequest,
770
+ *,
771
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
772
+ timeout: Optional[float] = None,
773
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
774
+ ) -> model.Model:
775
+ r"""Call the get model method over HTTP.
776
+
777
+ Args:
778
+ request (~.model_service.GetModelRequest):
779
+ The request object. Request for getting information about
780
+ a specific Model.
781
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
782
+ should be retried.
783
+ timeout (float): The timeout for this request.
784
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
785
+ sent along with the request as metadata. Normally, each value must be of type `str`,
786
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
787
+ be of type `bytes`.
788
+
789
+ Returns:
790
+ ~.model.Model:
791
+ Information about a Generative
792
+ Language Model.
793
+
794
+ """
795
+
796
+ http_options = (
797
+ _BaseModelServiceRestTransport._BaseGetModel._get_http_options()
798
+ )
799
+
800
+ request, metadata = self._interceptor.pre_get_model(request, metadata)
801
+ transcoded_request = (
802
+ _BaseModelServiceRestTransport._BaseGetModel._get_transcoded_request(
803
+ http_options, request
804
+ )
805
+ )
806
+
807
+ # Jsonify the query params
808
+ query_params = (
809
+ _BaseModelServiceRestTransport._BaseGetModel._get_query_params_json(
810
+ transcoded_request
811
+ )
812
+ )
813
+
814
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
815
+ logging.DEBUG
816
+ ): # pragma: NO COVER
817
+ request_url = "{host}{uri}".format(
818
+ host=self._host, uri=transcoded_request["uri"]
819
+ )
820
+ method = transcoded_request["method"]
821
+ try:
822
+ request_payload = type(request).to_json(request)
823
+ except:
824
+ request_payload = None
825
+ http_request = {
826
+ "payload": request_payload,
827
+ "requestMethod": method,
828
+ "requestUrl": request_url,
829
+ "headers": dict(metadata),
830
+ }
831
+ _LOGGER.debug(
832
+ f"Sending request for google.ai.generativelanguage_v1beta.ModelServiceClient.GetModel",
833
+ extra={
834
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
835
+ "rpcName": "GetModel",
836
+ "httpRequest": http_request,
837
+ "metadata": http_request["headers"],
838
+ },
839
+ )
840
+
841
+ # Send the request
842
+ response = ModelServiceRestTransport._GetModel._get_response(
843
+ self._host,
844
+ metadata,
845
+ query_params,
846
+ self._session,
847
+ timeout,
848
+ transcoded_request,
849
+ )
850
+
851
+ # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
852
+ # subclass.
853
+ if response.status_code >= 400:
854
+ raise core_exceptions.from_http_response(response)
855
+
856
+ # Return the response
857
+ resp = model.Model()
858
+ pb_resp = model.Model.pb(resp)
859
+
860
+ json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
861
+
862
+ resp = self._interceptor.post_get_model(resp)
863
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
864
+ logging.DEBUG
865
+ ): # pragma: NO COVER
866
+ try:
867
+ response_payload = model.Model.to_json(response)
868
+ except:
869
+ response_payload = None
870
+ http_response = {
871
+ "payload": response_payload,
872
+ "headers": dict(response.headers),
873
+ "status": response.status_code,
874
+ }
875
+ _LOGGER.debug(
876
+ "Received response for google.ai.generativelanguage_v1beta.ModelServiceClient.get_model",
877
+ extra={
878
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
879
+ "rpcName": "GetModel",
880
+ "metadata": http_response["headers"],
881
+ "httpResponse": http_response,
882
+ },
883
+ )
884
+ return resp
885
+
886
+ class _GetTunedModel(
887
+ _BaseModelServiceRestTransport._BaseGetTunedModel, ModelServiceRestStub
888
+ ):
889
+ def __hash__(self):
890
+ return hash("ModelServiceRestTransport.GetTunedModel")
891
+
892
+ @staticmethod
893
+ def _get_response(
894
+ host,
895
+ metadata,
896
+ query_params,
897
+ session,
898
+ timeout,
899
+ transcoded_request,
900
+ body=None,
901
+ ):
902
+ uri = transcoded_request["uri"]
903
+ method = transcoded_request["method"]
904
+ headers = dict(metadata)
905
+ headers["Content-Type"] = "application/json"
906
+ response = getattr(session, method)(
907
+ "{host}{uri}".format(host=host, uri=uri),
908
+ timeout=timeout,
909
+ headers=headers,
910
+ params=rest_helpers.flatten_query_params(query_params, strict=True),
911
+ )
912
+ return response
913
+
914
+ def __call__(
915
+ self,
916
+ request: model_service.GetTunedModelRequest,
917
+ *,
918
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
919
+ timeout: Optional[float] = None,
920
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
921
+ ) -> tuned_model.TunedModel:
922
+ r"""Call the get tuned model method over HTTP.
923
+
924
+ Args:
925
+ request (~.model_service.GetTunedModelRequest):
926
+ The request object. Request for getting information about
927
+ a specific Model.
928
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
929
+ should be retried.
930
+ timeout (float): The timeout for this request.
931
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
932
+ sent along with the request as metadata. Normally, each value must be of type `str`,
933
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
934
+ be of type `bytes`.
935
+
936
+ Returns:
937
+ ~.tuned_model.TunedModel:
938
+ A fine-tuned model created using
939
+ ModelService.CreateTunedModel.
940
+
941
+ """
942
+
943
+ http_options = (
944
+ _BaseModelServiceRestTransport._BaseGetTunedModel._get_http_options()
945
+ )
946
+
947
+ request, metadata = self._interceptor.pre_get_tuned_model(request, metadata)
948
+ transcoded_request = _BaseModelServiceRestTransport._BaseGetTunedModel._get_transcoded_request(
949
+ http_options, request
950
+ )
951
+
952
+ # Jsonify the query params
953
+ query_params = _BaseModelServiceRestTransport._BaseGetTunedModel._get_query_params_json(
954
+ transcoded_request
955
+ )
956
+
957
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
958
+ logging.DEBUG
959
+ ): # pragma: NO COVER
960
+ request_url = "{host}{uri}".format(
961
+ host=self._host, uri=transcoded_request["uri"]
962
+ )
963
+ method = transcoded_request["method"]
964
+ try:
965
+ request_payload = type(request).to_json(request)
966
+ except:
967
+ request_payload = None
968
+ http_request = {
969
+ "payload": request_payload,
970
+ "requestMethod": method,
971
+ "requestUrl": request_url,
972
+ "headers": dict(metadata),
973
+ }
974
+ _LOGGER.debug(
975
+ f"Sending request for google.ai.generativelanguage_v1beta.ModelServiceClient.GetTunedModel",
976
+ extra={
977
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
978
+ "rpcName": "GetTunedModel",
979
+ "httpRequest": http_request,
980
+ "metadata": http_request["headers"],
981
+ },
982
+ )
983
+
984
+ # Send the request
985
+ response = ModelServiceRestTransport._GetTunedModel._get_response(
986
+ self._host,
987
+ metadata,
988
+ query_params,
989
+ self._session,
990
+ timeout,
991
+ transcoded_request,
992
+ )
993
+
994
+ # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
995
+ # subclass.
996
+ if response.status_code >= 400:
997
+ raise core_exceptions.from_http_response(response)
998
+
999
+ # Return the response
1000
+ resp = tuned_model.TunedModel()
1001
+ pb_resp = tuned_model.TunedModel.pb(resp)
1002
+
1003
+ json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
1004
+
1005
+ resp = self._interceptor.post_get_tuned_model(resp)
1006
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1007
+ logging.DEBUG
1008
+ ): # pragma: NO COVER
1009
+ try:
1010
+ response_payload = tuned_model.TunedModel.to_json(response)
1011
+ except:
1012
+ response_payload = None
1013
+ http_response = {
1014
+ "payload": response_payload,
1015
+ "headers": dict(response.headers),
1016
+ "status": response.status_code,
1017
+ }
1018
+ _LOGGER.debug(
1019
+ "Received response for google.ai.generativelanguage_v1beta.ModelServiceClient.get_tuned_model",
1020
+ extra={
1021
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
1022
+ "rpcName": "GetTunedModel",
1023
+ "metadata": http_response["headers"],
1024
+ "httpResponse": http_response,
1025
+ },
1026
+ )
1027
+ return resp
1028
+
1029
+ class _ListModels(
1030
+ _BaseModelServiceRestTransport._BaseListModels, ModelServiceRestStub
1031
+ ):
1032
+ def __hash__(self):
1033
+ return hash("ModelServiceRestTransport.ListModels")
1034
+
1035
+ @staticmethod
1036
+ def _get_response(
1037
+ host,
1038
+ metadata,
1039
+ query_params,
1040
+ session,
1041
+ timeout,
1042
+ transcoded_request,
1043
+ body=None,
1044
+ ):
1045
+ uri = transcoded_request["uri"]
1046
+ method = transcoded_request["method"]
1047
+ headers = dict(metadata)
1048
+ headers["Content-Type"] = "application/json"
1049
+ response = getattr(session, method)(
1050
+ "{host}{uri}".format(host=host, uri=uri),
1051
+ timeout=timeout,
1052
+ headers=headers,
1053
+ params=rest_helpers.flatten_query_params(query_params, strict=True),
1054
+ )
1055
+ return response
1056
+
1057
+ def __call__(
1058
+ self,
1059
+ request: model_service.ListModelsRequest,
1060
+ *,
1061
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1062
+ timeout: Optional[float] = None,
1063
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1064
+ ) -> model_service.ListModelsResponse:
1065
+ r"""Call the list models method over HTTP.
1066
+
1067
+ Args:
1068
+ request (~.model_service.ListModelsRequest):
1069
+ The request object. Request for listing all Models.
1070
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1071
+ should be retried.
1072
+ timeout (float): The timeout for this request.
1073
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1074
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1075
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1076
+ be of type `bytes`.
1077
+
1078
+ Returns:
1079
+ ~.model_service.ListModelsResponse:
1080
+ Response from ``ListModel`` containing a paginated list
1081
+ of Models.
1082
+
1083
+ """
1084
+
1085
+ http_options = (
1086
+ _BaseModelServiceRestTransport._BaseListModels._get_http_options()
1087
+ )
1088
+
1089
+ request, metadata = self._interceptor.pre_list_models(request, metadata)
1090
+ transcoded_request = (
1091
+ _BaseModelServiceRestTransport._BaseListModels._get_transcoded_request(
1092
+ http_options, request
1093
+ )
1094
+ )
1095
+
1096
+ # Jsonify the query params
1097
+ query_params = (
1098
+ _BaseModelServiceRestTransport._BaseListModels._get_query_params_json(
1099
+ transcoded_request
1100
+ )
1101
+ )
1102
+
1103
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1104
+ logging.DEBUG
1105
+ ): # pragma: NO COVER
1106
+ request_url = "{host}{uri}".format(
1107
+ host=self._host, uri=transcoded_request["uri"]
1108
+ )
1109
+ method = transcoded_request["method"]
1110
+ try:
1111
+ request_payload = type(request).to_json(request)
1112
+ except:
1113
+ request_payload = None
1114
+ http_request = {
1115
+ "payload": request_payload,
1116
+ "requestMethod": method,
1117
+ "requestUrl": request_url,
1118
+ "headers": dict(metadata),
1119
+ }
1120
+ _LOGGER.debug(
1121
+ f"Sending request for google.ai.generativelanguage_v1beta.ModelServiceClient.ListModels",
1122
+ extra={
1123
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
1124
+ "rpcName": "ListModels",
1125
+ "httpRequest": http_request,
1126
+ "metadata": http_request["headers"],
1127
+ },
1128
+ )
1129
+
1130
+ # Send the request
1131
+ response = ModelServiceRestTransport._ListModels._get_response(
1132
+ self._host,
1133
+ metadata,
1134
+ query_params,
1135
+ self._session,
1136
+ timeout,
1137
+ transcoded_request,
1138
+ )
1139
+
1140
+ # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1141
+ # subclass.
1142
+ if response.status_code >= 400:
1143
+ raise core_exceptions.from_http_response(response)
1144
+
1145
+ # Return the response
1146
+ resp = model_service.ListModelsResponse()
1147
+ pb_resp = model_service.ListModelsResponse.pb(resp)
1148
+
1149
+ json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
1150
+
1151
+ resp = self._interceptor.post_list_models(resp)
1152
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1153
+ logging.DEBUG
1154
+ ): # pragma: NO COVER
1155
+ try:
1156
+ response_payload = model_service.ListModelsResponse.to_json(
1157
+ response
1158
+ )
1159
+ except:
1160
+ response_payload = None
1161
+ http_response = {
1162
+ "payload": response_payload,
1163
+ "headers": dict(response.headers),
1164
+ "status": response.status_code,
1165
+ }
1166
+ _LOGGER.debug(
1167
+ "Received response for google.ai.generativelanguage_v1beta.ModelServiceClient.list_models",
1168
+ extra={
1169
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
1170
+ "rpcName": "ListModels",
1171
+ "metadata": http_response["headers"],
1172
+ "httpResponse": http_response,
1173
+ },
1174
+ )
1175
+ return resp
1176
+
1177
+ class _ListTunedModels(
1178
+ _BaseModelServiceRestTransport._BaseListTunedModels, ModelServiceRestStub
1179
+ ):
1180
+ def __hash__(self):
1181
+ return hash("ModelServiceRestTransport.ListTunedModels")
1182
+
1183
+ @staticmethod
1184
+ def _get_response(
1185
+ host,
1186
+ metadata,
1187
+ query_params,
1188
+ session,
1189
+ timeout,
1190
+ transcoded_request,
1191
+ body=None,
1192
+ ):
1193
+ uri = transcoded_request["uri"]
1194
+ method = transcoded_request["method"]
1195
+ headers = dict(metadata)
1196
+ headers["Content-Type"] = "application/json"
1197
+ response = getattr(session, method)(
1198
+ "{host}{uri}".format(host=host, uri=uri),
1199
+ timeout=timeout,
1200
+ headers=headers,
1201
+ params=rest_helpers.flatten_query_params(query_params, strict=True),
1202
+ )
1203
+ return response
1204
+
1205
+ def __call__(
1206
+ self,
1207
+ request: model_service.ListTunedModelsRequest,
1208
+ *,
1209
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1210
+ timeout: Optional[float] = None,
1211
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1212
+ ) -> model_service.ListTunedModelsResponse:
1213
+ r"""Call the list tuned models method over HTTP.
1214
+
1215
+ Args:
1216
+ request (~.model_service.ListTunedModelsRequest):
1217
+ The request object. Request for listing TunedModels.
1218
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1219
+ should be retried.
1220
+ timeout (float): The timeout for this request.
1221
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1222
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1223
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1224
+ be of type `bytes`.
1225
+
1226
+ Returns:
1227
+ ~.model_service.ListTunedModelsResponse:
1228
+ Response from ``ListTunedModels`` containing a paginated
1229
+ list of Models.
1230
+
1231
+ """
1232
+
1233
+ http_options = (
1234
+ _BaseModelServiceRestTransport._BaseListTunedModels._get_http_options()
1235
+ )
1236
+
1237
+ request, metadata = self._interceptor.pre_list_tuned_models(
1238
+ request, metadata
1239
+ )
1240
+ transcoded_request = _BaseModelServiceRestTransport._BaseListTunedModels._get_transcoded_request(
1241
+ http_options, request
1242
+ )
1243
+
1244
+ # Jsonify the query params
1245
+ query_params = _BaseModelServiceRestTransport._BaseListTunedModels._get_query_params_json(
1246
+ transcoded_request
1247
+ )
1248
+
1249
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1250
+ logging.DEBUG
1251
+ ): # pragma: NO COVER
1252
+ request_url = "{host}{uri}".format(
1253
+ host=self._host, uri=transcoded_request["uri"]
1254
+ )
1255
+ method = transcoded_request["method"]
1256
+ try:
1257
+ request_payload = type(request).to_json(request)
1258
+ except:
1259
+ request_payload = None
1260
+ http_request = {
1261
+ "payload": request_payload,
1262
+ "requestMethod": method,
1263
+ "requestUrl": request_url,
1264
+ "headers": dict(metadata),
1265
+ }
1266
+ _LOGGER.debug(
1267
+ f"Sending request for google.ai.generativelanguage_v1beta.ModelServiceClient.ListTunedModels",
1268
+ extra={
1269
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
1270
+ "rpcName": "ListTunedModels",
1271
+ "httpRequest": http_request,
1272
+ "metadata": http_request["headers"],
1273
+ },
1274
+ )
1275
+
1276
+ # Send the request
1277
+ response = ModelServiceRestTransport._ListTunedModels._get_response(
1278
+ self._host,
1279
+ metadata,
1280
+ query_params,
1281
+ self._session,
1282
+ timeout,
1283
+ transcoded_request,
1284
+ )
1285
+
1286
+ # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1287
+ # subclass.
1288
+ if response.status_code >= 400:
1289
+ raise core_exceptions.from_http_response(response)
1290
+
1291
+ # Return the response
1292
+ resp = model_service.ListTunedModelsResponse()
1293
+ pb_resp = model_service.ListTunedModelsResponse.pb(resp)
1294
+
1295
+ json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
1296
+
1297
+ resp = self._interceptor.post_list_tuned_models(resp)
1298
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1299
+ logging.DEBUG
1300
+ ): # pragma: NO COVER
1301
+ try:
1302
+ response_payload = model_service.ListTunedModelsResponse.to_json(
1303
+ response
1304
+ )
1305
+ except:
1306
+ response_payload = None
1307
+ http_response = {
1308
+ "payload": response_payload,
1309
+ "headers": dict(response.headers),
1310
+ "status": response.status_code,
1311
+ }
1312
+ _LOGGER.debug(
1313
+ "Received response for google.ai.generativelanguage_v1beta.ModelServiceClient.list_tuned_models",
1314
+ extra={
1315
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
1316
+ "rpcName": "ListTunedModels",
1317
+ "metadata": http_response["headers"],
1318
+ "httpResponse": http_response,
1319
+ },
1320
+ )
1321
+ return resp
1322
+
1323
+ class _UpdateTunedModel(
1324
+ _BaseModelServiceRestTransport._BaseUpdateTunedModel, ModelServiceRestStub
1325
+ ):
1326
+ def __hash__(self):
1327
+ return hash("ModelServiceRestTransport.UpdateTunedModel")
1328
+
1329
+ @staticmethod
1330
+ def _get_response(
1331
+ host,
1332
+ metadata,
1333
+ query_params,
1334
+ session,
1335
+ timeout,
1336
+ transcoded_request,
1337
+ body=None,
1338
+ ):
1339
+ uri = transcoded_request["uri"]
1340
+ method = transcoded_request["method"]
1341
+ headers = dict(metadata)
1342
+ headers["Content-Type"] = "application/json"
1343
+ response = getattr(session, method)(
1344
+ "{host}{uri}".format(host=host, uri=uri),
1345
+ timeout=timeout,
1346
+ headers=headers,
1347
+ params=rest_helpers.flatten_query_params(query_params, strict=True),
1348
+ data=body,
1349
+ )
1350
+ return response
1351
+
1352
+ def __call__(
1353
+ self,
1354
+ request: model_service.UpdateTunedModelRequest,
1355
+ *,
1356
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1357
+ timeout: Optional[float] = None,
1358
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1359
+ ) -> gag_tuned_model.TunedModel:
1360
+ r"""Call the update tuned model method over HTTP.
1361
+
1362
+ Args:
1363
+ request (~.model_service.UpdateTunedModelRequest):
1364
+ The request object. Request to update a TunedModel.
1365
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1366
+ should be retried.
1367
+ timeout (float): The timeout for this request.
1368
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1369
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1370
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1371
+ be of type `bytes`.
1372
+
1373
+ Returns:
1374
+ ~.gag_tuned_model.TunedModel:
1375
+ A fine-tuned model created using
1376
+ ModelService.CreateTunedModel.
1377
+
1378
+ """
1379
+
1380
+ http_options = (
1381
+ _BaseModelServiceRestTransport._BaseUpdateTunedModel._get_http_options()
1382
+ )
1383
+
1384
+ request, metadata = self._interceptor.pre_update_tuned_model(
1385
+ request, metadata
1386
+ )
1387
+ transcoded_request = _BaseModelServiceRestTransport._BaseUpdateTunedModel._get_transcoded_request(
1388
+ http_options, request
1389
+ )
1390
+
1391
+ body = _BaseModelServiceRestTransport._BaseUpdateTunedModel._get_request_body_json(
1392
+ transcoded_request
1393
+ )
1394
+
1395
+ # Jsonify the query params
1396
+ query_params = _BaseModelServiceRestTransport._BaseUpdateTunedModel._get_query_params_json(
1397
+ transcoded_request
1398
+ )
1399
+
1400
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1401
+ logging.DEBUG
1402
+ ): # pragma: NO COVER
1403
+ request_url = "{host}{uri}".format(
1404
+ host=self._host, uri=transcoded_request["uri"]
1405
+ )
1406
+ method = transcoded_request["method"]
1407
+ try:
1408
+ request_payload = type(request).to_json(request)
1409
+ except:
1410
+ request_payload = None
1411
+ http_request = {
1412
+ "payload": request_payload,
1413
+ "requestMethod": method,
1414
+ "requestUrl": request_url,
1415
+ "headers": dict(metadata),
1416
+ }
1417
+ _LOGGER.debug(
1418
+ f"Sending request for google.ai.generativelanguage_v1beta.ModelServiceClient.UpdateTunedModel",
1419
+ extra={
1420
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
1421
+ "rpcName": "UpdateTunedModel",
1422
+ "httpRequest": http_request,
1423
+ "metadata": http_request["headers"],
1424
+ },
1425
+ )
1426
+
1427
+ # Send the request
1428
+ response = ModelServiceRestTransport._UpdateTunedModel._get_response(
1429
+ self._host,
1430
+ metadata,
1431
+ query_params,
1432
+ self._session,
1433
+ timeout,
1434
+ transcoded_request,
1435
+ body,
1436
+ )
1437
+
1438
+ # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1439
+ # subclass.
1440
+ if response.status_code >= 400:
1441
+ raise core_exceptions.from_http_response(response)
1442
+
1443
+ # Return the response
1444
+ resp = gag_tuned_model.TunedModel()
1445
+ pb_resp = gag_tuned_model.TunedModel.pb(resp)
1446
+
1447
+ json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
1448
+
1449
+ resp = self._interceptor.post_update_tuned_model(resp)
1450
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1451
+ logging.DEBUG
1452
+ ): # pragma: NO COVER
1453
+ try:
1454
+ response_payload = gag_tuned_model.TunedModel.to_json(response)
1455
+ except:
1456
+ response_payload = None
1457
+ http_response = {
1458
+ "payload": response_payload,
1459
+ "headers": dict(response.headers),
1460
+ "status": response.status_code,
1461
+ }
1462
+ _LOGGER.debug(
1463
+ "Received response for google.ai.generativelanguage_v1beta.ModelServiceClient.update_tuned_model",
1464
+ extra={
1465
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
1466
+ "rpcName": "UpdateTunedModel",
1467
+ "metadata": http_response["headers"],
1468
+ "httpResponse": http_response,
1469
+ },
1470
+ )
1471
+ return resp
1472
+
1473
+ @property
1474
+ def create_tuned_model(
1475
+ self,
1476
+ ) -> Callable[[model_service.CreateTunedModelRequest], operations_pb2.Operation]:
1477
+ # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
1478
+ # In C++ this would require a dynamic_cast
1479
+ return self._CreateTunedModel(self._session, self._host, self._interceptor) # type: ignore
1480
+
1481
+ @property
1482
+ def delete_tuned_model(
1483
+ self,
1484
+ ) -> Callable[[model_service.DeleteTunedModelRequest], empty_pb2.Empty]:
1485
+ # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
1486
+ # In C++ this would require a dynamic_cast
1487
+ return self._DeleteTunedModel(self._session, self._host, self._interceptor) # type: ignore
1488
+
1489
+ @property
1490
+ def get_model(self) -> Callable[[model_service.GetModelRequest], model.Model]:
1491
+ # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
1492
+ # In C++ this would require a dynamic_cast
1493
+ return self._GetModel(self._session, self._host, self._interceptor) # type: ignore
1494
+
1495
+ @property
1496
+ def get_tuned_model(
1497
+ self,
1498
+ ) -> Callable[[model_service.GetTunedModelRequest], tuned_model.TunedModel]:
1499
+ # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
1500
+ # In C++ this would require a dynamic_cast
1501
+ return self._GetTunedModel(self._session, self._host, self._interceptor) # type: ignore
1502
+
1503
+ @property
1504
+ def list_models(
1505
+ self,
1506
+ ) -> Callable[[model_service.ListModelsRequest], model_service.ListModelsResponse]:
1507
+ # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
1508
+ # In C++ this would require a dynamic_cast
1509
+ return self._ListModels(self._session, self._host, self._interceptor) # type: ignore
1510
+
1511
+ @property
1512
+ def list_tuned_models(
1513
+ self,
1514
+ ) -> Callable[
1515
+ [model_service.ListTunedModelsRequest], model_service.ListTunedModelsResponse
1516
+ ]:
1517
+ # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
1518
+ # In C++ this would require a dynamic_cast
1519
+ return self._ListTunedModels(self._session, self._host, self._interceptor) # type: ignore
1520
+
1521
+ @property
1522
+ def update_tuned_model(
1523
+ self,
1524
+ ) -> Callable[[model_service.UpdateTunedModelRequest], gag_tuned_model.TunedModel]:
1525
+ # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
1526
+ # In C++ this would require a dynamic_cast
1527
+ return self._UpdateTunedModel(self._session, self._host, self._interceptor) # type: ignore
1528
+
1529
+ @property
1530
+ def get_operation(self):
1531
+ return self._GetOperation(self._session, self._host, self._interceptor) # type: ignore
1532
+
1533
+ class _GetOperation(
1534
+ _BaseModelServiceRestTransport._BaseGetOperation, ModelServiceRestStub
1535
+ ):
1536
+ def __hash__(self):
1537
+ return hash("ModelServiceRestTransport.GetOperation")
1538
+
1539
+ @staticmethod
1540
+ def _get_response(
1541
+ host,
1542
+ metadata,
1543
+ query_params,
1544
+ session,
1545
+ timeout,
1546
+ transcoded_request,
1547
+ body=None,
1548
+ ):
1549
+ uri = transcoded_request["uri"]
1550
+ method = transcoded_request["method"]
1551
+ headers = dict(metadata)
1552
+ headers["Content-Type"] = "application/json"
1553
+ response = getattr(session, method)(
1554
+ "{host}{uri}".format(host=host, uri=uri),
1555
+ timeout=timeout,
1556
+ headers=headers,
1557
+ params=rest_helpers.flatten_query_params(query_params, strict=True),
1558
+ )
1559
+ return response
1560
+
1561
+ def __call__(
1562
+ self,
1563
+ request: operations_pb2.GetOperationRequest,
1564
+ *,
1565
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1566
+ timeout: Optional[float] = None,
1567
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1568
+ ) -> operations_pb2.Operation:
1569
+ r"""Call the get operation method over HTTP.
1570
+
1571
+ Args:
1572
+ request (operations_pb2.GetOperationRequest):
1573
+ The request object for GetOperation method.
1574
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1575
+ should be retried.
1576
+ timeout (float): The timeout for this request.
1577
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1578
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1579
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1580
+ be of type `bytes`.
1581
+
1582
+ Returns:
1583
+ operations_pb2.Operation: Response from GetOperation method.
1584
+ """
1585
+
1586
+ http_options = (
1587
+ _BaseModelServiceRestTransport._BaseGetOperation._get_http_options()
1588
+ )
1589
+
1590
+ request, metadata = self._interceptor.pre_get_operation(request, metadata)
1591
+ transcoded_request = _BaseModelServiceRestTransport._BaseGetOperation._get_transcoded_request(
1592
+ http_options, request
1593
+ )
1594
+
1595
+ # Jsonify the query params
1596
+ query_params = (
1597
+ _BaseModelServiceRestTransport._BaseGetOperation._get_query_params_json(
1598
+ transcoded_request
1599
+ )
1600
+ )
1601
+
1602
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1603
+ logging.DEBUG
1604
+ ): # pragma: NO COVER
1605
+ request_url = "{host}{uri}".format(
1606
+ host=self._host, uri=transcoded_request["uri"]
1607
+ )
1608
+ method = transcoded_request["method"]
1609
+ try:
1610
+ request_payload = json_format.MessageToJson(request)
1611
+ except:
1612
+ request_payload = None
1613
+ http_request = {
1614
+ "payload": request_payload,
1615
+ "requestMethod": method,
1616
+ "requestUrl": request_url,
1617
+ "headers": dict(metadata),
1618
+ }
1619
+ _LOGGER.debug(
1620
+ f"Sending request for google.ai.generativelanguage_v1beta.ModelServiceClient.GetOperation",
1621
+ extra={
1622
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
1623
+ "rpcName": "GetOperation",
1624
+ "httpRequest": http_request,
1625
+ "metadata": http_request["headers"],
1626
+ },
1627
+ )
1628
+
1629
+ # Send the request
1630
+ response = ModelServiceRestTransport._GetOperation._get_response(
1631
+ self._host,
1632
+ metadata,
1633
+ query_params,
1634
+ self._session,
1635
+ timeout,
1636
+ transcoded_request,
1637
+ )
1638
+
1639
+ # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1640
+ # subclass.
1641
+ if response.status_code >= 400:
1642
+ raise core_exceptions.from_http_response(response)
1643
+
1644
+ content = response.content.decode("utf-8")
1645
+ resp = operations_pb2.Operation()
1646
+ resp = json_format.Parse(content, resp)
1647
+ resp = self._interceptor.post_get_operation(resp)
1648
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1649
+ logging.DEBUG
1650
+ ): # pragma: NO COVER
1651
+ try:
1652
+ response_payload = json_format.MessageToJson(resp)
1653
+ except:
1654
+ response_payload = None
1655
+ http_response = {
1656
+ "payload": response_payload,
1657
+ "headers": dict(response.headers),
1658
+ "status": response.status_code,
1659
+ }
1660
+ _LOGGER.debug(
1661
+ "Received response for google.ai.generativelanguage_v1beta.ModelServiceAsyncClient.GetOperation",
1662
+ extra={
1663
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
1664
+ "rpcName": "GetOperation",
1665
+ "httpResponse": http_response,
1666
+ "metadata": http_response["headers"],
1667
+ },
1668
+ )
1669
+ return resp
1670
+
1671
+ @property
1672
+ def list_operations(self):
1673
+ return self._ListOperations(self._session, self._host, self._interceptor) # type: ignore
1674
+
1675
+ class _ListOperations(
1676
+ _BaseModelServiceRestTransport._BaseListOperations, ModelServiceRestStub
1677
+ ):
1678
+ def __hash__(self):
1679
+ return hash("ModelServiceRestTransport.ListOperations")
1680
+
1681
+ @staticmethod
1682
+ def _get_response(
1683
+ host,
1684
+ metadata,
1685
+ query_params,
1686
+ session,
1687
+ timeout,
1688
+ transcoded_request,
1689
+ body=None,
1690
+ ):
1691
+ uri = transcoded_request["uri"]
1692
+ method = transcoded_request["method"]
1693
+ headers = dict(metadata)
1694
+ headers["Content-Type"] = "application/json"
1695
+ response = getattr(session, method)(
1696
+ "{host}{uri}".format(host=host, uri=uri),
1697
+ timeout=timeout,
1698
+ headers=headers,
1699
+ params=rest_helpers.flatten_query_params(query_params, strict=True),
1700
+ )
1701
+ return response
1702
+
1703
+ def __call__(
1704
+ self,
1705
+ request: operations_pb2.ListOperationsRequest,
1706
+ *,
1707
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1708
+ timeout: Optional[float] = None,
1709
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1710
+ ) -> operations_pb2.ListOperationsResponse:
1711
+ r"""Call the list operations method over HTTP.
1712
+
1713
+ Args:
1714
+ request (operations_pb2.ListOperationsRequest):
1715
+ The request object for ListOperations method.
1716
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1717
+ should be retried.
1718
+ timeout (float): The timeout for this request.
1719
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1720
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1721
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1722
+ be of type `bytes`.
1723
+
1724
+ Returns:
1725
+ operations_pb2.ListOperationsResponse: Response from ListOperations method.
1726
+ """
1727
+
1728
+ http_options = (
1729
+ _BaseModelServiceRestTransport._BaseListOperations._get_http_options()
1730
+ )
1731
+
1732
+ request, metadata = self._interceptor.pre_list_operations(request, metadata)
1733
+ transcoded_request = _BaseModelServiceRestTransport._BaseListOperations._get_transcoded_request(
1734
+ http_options, request
1735
+ )
1736
+
1737
+ # Jsonify the query params
1738
+ query_params = _BaseModelServiceRestTransport._BaseListOperations._get_query_params_json(
1739
+ transcoded_request
1740
+ )
1741
+
1742
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1743
+ logging.DEBUG
1744
+ ): # pragma: NO COVER
1745
+ request_url = "{host}{uri}".format(
1746
+ host=self._host, uri=transcoded_request["uri"]
1747
+ )
1748
+ method = transcoded_request["method"]
1749
+ try:
1750
+ request_payload = json_format.MessageToJson(request)
1751
+ except:
1752
+ request_payload = None
1753
+ http_request = {
1754
+ "payload": request_payload,
1755
+ "requestMethod": method,
1756
+ "requestUrl": request_url,
1757
+ "headers": dict(metadata),
1758
+ }
1759
+ _LOGGER.debug(
1760
+ f"Sending request for google.ai.generativelanguage_v1beta.ModelServiceClient.ListOperations",
1761
+ extra={
1762
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
1763
+ "rpcName": "ListOperations",
1764
+ "httpRequest": http_request,
1765
+ "metadata": http_request["headers"],
1766
+ },
1767
+ )
1768
+
1769
+ # Send the request
1770
+ response = ModelServiceRestTransport._ListOperations._get_response(
1771
+ self._host,
1772
+ metadata,
1773
+ query_params,
1774
+ self._session,
1775
+ timeout,
1776
+ transcoded_request,
1777
+ )
1778
+
1779
+ # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1780
+ # subclass.
1781
+ if response.status_code >= 400:
1782
+ raise core_exceptions.from_http_response(response)
1783
+
1784
+ content = response.content.decode("utf-8")
1785
+ resp = operations_pb2.ListOperationsResponse()
1786
+ resp = json_format.Parse(content, resp)
1787
+ resp = self._interceptor.post_list_operations(resp)
1788
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1789
+ logging.DEBUG
1790
+ ): # pragma: NO COVER
1791
+ try:
1792
+ response_payload = json_format.MessageToJson(resp)
1793
+ except:
1794
+ response_payload = None
1795
+ http_response = {
1796
+ "payload": response_payload,
1797
+ "headers": dict(response.headers),
1798
+ "status": response.status_code,
1799
+ }
1800
+ _LOGGER.debug(
1801
+ "Received response for google.ai.generativelanguage_v1beta.ModelServiceAsyncClient.ListOperations",
1802
+ extra={
1803
+ "serviceName": "google.ai.generativelanguage.v1beta.ModelService",
1804
+ "rpcName": "ListOperations",
1805
+ "httpResponse": http_response,
1806
+ "metadata": http_response["headers"],
1807
+ },
1808
+ )
1809
+ return resp
1810
+
1811
+ @property
1812
+ def kind(self) -> str:
1813
+ return "rest"
1814
+
1815
+ def close(self):
1816
+ self._session.close()
1817
+
1818
+
1819
+ __all__ = ("ModelServiceRestTransport",)
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/model_service/transports/rest_base.py ADDED
@@ -0,0 +1,476 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ import json # type: ignore
17
+ import re
18
+ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
19
+
20
+ from google.api_core import gapic_v1, path_template
21
+ from google.longrunning import operations_pb2 # type: ignore
22
+ from google.protobuf import empty_pb2 # type: ignore
23
+ from google.protobuf import json_format
24
+
25
+ from google.ai.generativelanguage_v1beta.types import tuned_model as gag_tuned_model
26
+ from google.ai.generativelanguage_v1beta.types import model, model_service
27
+ from google.ai.generativelanguage_v1beta.types import tuned_model
28
+
29
+ from .base import DEFAULT_CLIENT_INFO, ModelServiceTransport
30
+
31
+
32
+ class _BaseModelServiceRestTransport(ModelServiceTransport):
33
+ """Base REST backend transport for ModelService.
34
+
35
+ Note: This class is not meant to be used directly. Use its sync and
36
+ async sub-classes instead.
37
+
38
+ This class defines the same methods as the primary client, so the
39
+ primary client can load the underlying transport implementation
40
+ and call it.
41
+
42
+ It sends JSON representations of protocol buffers over HTTP/1.1
43
+ """
44
+
45
+ def __init__(
46
+ self,
47
+ *,
48
+ host: str = "generativelanguage.googleapis.com",
49
+ credentials: Optional[Any] = None,
50
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
51
+ always_use_jwt_access: Optional[bool] = False,
52
+ url_scheme: str = "https",
53
+ api_audience: Optional[str] = None,
54
+ ) -> None:
55
+ """Instantiate the transport.
56
+ Args:
57
+ host (Optional[str]):
58
+ The hostname to connect to (default: 'generativelanguage.googleapis.com').
59
+ credentials (Optional[Any]): The
60
+ authorization credentials to attach to requests. These
61
+ credentials identify the application to the service; if none
62
+ are specified, the client will attempt to ascertain the
63
+ credentials from the environment.
64
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
65
+ The client info used to send a user-agent string along with
66
+ API requests. If ``None``, then default info will be used.
67
+ Generally, you only need to set this if you are developing
68
+ your own client library.
69
+ always_use_jwt_access (Optional[bool]): Whether self signed JWT should
70
+ be used for service account credentials.
71
+ url_scheme: the protocol scheme for the API endpoint. Normally
72
+ "https", but for testing or local servers,
73
+ "http" can be specified.
74
+ """
75
+ # Run the base constructor
76
+ maybe_url_match = re.match("^(?P<scheme>http(?:s)?://)?(?P<host>.*)$", host)
77
+ if maybe_url_match is None:
78
+ raise ValueError(
79
+ f"Unexpected hostname structure: {host}"
80
+ ) # pragma: NO COVER
81
+
82
+ url_match_items = maybe_url_match.groupdict()
83
+
84
+ host = f"{url_scheme}://{host}" if not url_match_items["scheme"] else host
85
+
86
+ super().__init__(
87
+ host=host,
88
+ credentials=credentials,
89
+ client_info=client_info,
90
+ always_use_jwt_access=always_use_jwt_access,
91
+ api_audience=api_audience,
92
+ )
93
+
94
+ class _BaseCreateTunedModel:
95
+ def __hash__(self): # pragma: NO COVER
96
+ return NotImplementedError("__hash__ must be implemented.")
97
+
98
+ __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
99
+
100
+ @classmethod
101
+ def _get_unset_required_fields(cls, message_dict):
102
+ return {
103
+ k: v
104
+ for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
105
+ if k not in message_dict
106
+ }
107
+
108
+ @staticmethod
109
+ def _get_http_options():
110
+ http_options: List[Dict[str, str]] = [
111
+ {
112
+ "method": "post",
113
+ "uri": "/v1beta/tunedModels",
114
+ "body": "tuned_model",
115
+ },
116
+ ]
117
+ return http_options
118
+
119
+ @staticmethod
120
+ def _get_transcoded_request(http_options, request):
121
+ pb_request = model_service.CreateTunedModelRequest.pb(request)
122
+ transcoded_request = path_template.transcode(http_options, pb_request)
123
+ return transcoded_request
124
+
125
+ @staticmethod
126
+ def _get_request_body_json(transcoded_request):
127
+ # Jsonify the request body
128
+
129
+ body = json_format.MessageToJson(
130
+ transcoded_request["body"], use_integers_for_enums=True
131
+ )
132
+ return body
133
+
134
+ @staticmethod
135
+ def _get_query_params_json(transcoded_request):
136
+ query_params = json.loads(
137
+ json_format.MessageToJson(
138
+ transcoded_request["query_params"],
139
+ use_integers_for_enums=True,
140
+ )
141
+ )
142
+ query_params.update(
143
+ _BaseModelServiceRestTransport._BaseCreateTunedModel._get_unset_required_fields(
144
+ query_params
145
+ )
146
+ )
147
+
148
+ query_params["$alt"] = "json;enum-encoding=int"
149
+ return query_params
150
+
151
+ class _BaseDeleteTunedModel:
152
+ def __hash__(self): # pragma: NO COVER
153
+ return NotImplementedError("__hash__ must be implemented.")
154
+
155
+ __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
156
+
157
+ @classmethod
158
+ def _get_unset_required_fields(cls, message_dict):
159
+ return {
160
+ k: v
161
+ for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
162
+ if k not in message_dict
163
+ }
164
+
165
+ @staticmethod
166
+ def _get_http_options():
167
+ http_options: List[Dict[str, str]] = [
168
+ {
169
+ "method": "delete",
170
+ "uri": "/v1beta/{name=tunedModels/*}",
171
+ },
172
+ ]
173
+ return http_options
174
+
175
+ @staticmethod
176
+ def _get_transcoded_request(http_options, request):
177
+ pb_request = model_service.DeleteTunedModelRequest.pb(request)
178
+ transcoded_request = path_template.transcode(http_options, pb_request)
179
+ return transcoded_request
180
+
181
+ @staticmethod
182
+ def _get_query_params_json(transcoded_request):
183
+ query_params = json.loads(
184
+ json_format.MessageToJson(
185
+ transcoded_request["query_params"],
186
+ use_integers_for_enums=True,
187
+ )
188
+ )
189
+ query_params.update(
190
+ _BaseModelServiceRestTransport._BaseDeleteTunedModel._get_unset_required_fields(
191
+ query_params
192
+ )
193
+ )
194
+
195
+ query_params["$alt"] = "json;enum-encoding=int"
196
+ return query_params
197
+
198
+ class _BaseGetModel:
199
+ def __hash__(self): # pragma: NO COVER
200
+ return NotImplementedError("__hash__ must be implemented.")
201
+
202
+ __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
203
+
204
+ @classmethod
205
+ def _get_unset_required_fields(cls, message_dict):
206
+ return {
207
+ k: v
208
+ for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
209
+ if k not in message_dict
210
+ }
211
+
212
+ @staticmethod
213
+ def _get_http_options():
214
+ http_options: List[Dict[str, str]] = [
215
+ {
216
+ "method": "get",
217
+ "uri": "/v1beta/{name=models/*}",
218
+ },
219
+ ]
220
+ return http_options
221
+
222
+ @staticmethod
223
+ def _get_transcoded_request(http_options, request):
224
+ pb_request = model_service.GetModelRequest.pb(request)
225
+ transcoded_request = path_template.transcode(http_options, pb_request)
226
+ return transcoded_request
227
+
228
+ @staticmethod
229
+ def _get_query_params_json(transcoded_request):
230
+ query_params = json.loads(
231
+ json_format.MessageToJson(
232
+ transcoded_request["query_params"],
233
+ use_integers_for_enums=True,
234
+ )
235
+ )
236
+ query_params.update(
237
+ _BaseModelServiceRestTransport._BaseGetModel._get_unset_required_fields(
238
+ query_params
239
+ )
240
+ )
241
+
242
+ query_params["$alt"] = "json;enum-encoding=int"
243
+ return query_params
244
+
245
+ class _BaseGetTunedModel:
246
+ def __hash__(self): # pragma: NO COVER
247
+ return NotImplementedError("__hash__ must be implemented.")
248
+
249
+ __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
250
+
251
+ @classmethod
252
+ def _get_unset_required_fields(cls, message_dict):
253
+ return {
254
+ k: v
255
+ for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
256
+ if k not in message_dict
257
+ }
258
+
259
+ @staticmethod
260
+ def _get_http_options():
261
+ http_options: List[Dict[str, str]] = [
262
+ {
263
+ "method": "get",
264
+ "uri": "/v1beta/{name=tunedModels/*}",
265
+ },
266
+ ]
267
+ return http_options
268
+
269
+ @staticmethod
270
+ def _get_transcoded_request(http_options, request):
271
+ pb_request = model_service.GetTunedModelRequest.pb(request)
272
+ transcoded_request = path_template.transcode(http_options, pb_request)
273
+ return transcoded_request
274
+
275
+ @staticmethod
276
+ def _get_query_params_json(transcoded_request):
277
+ query_params = json.loads(
278
+ json_format.MessageToJson(
279
+ transcoded_request["query_params"],
280
+ use_integers_for_enums=True,
281
+ )
282
+ )
283
+ query_params.update(
284
+ _BaseModelServiceRestTransport._BaseGetTunedModel._get_unset_required_fields(
285
+ query_params
286
+ )
287
+ )
288
+
289
+ query_params["$alt"] = "json;enum-encoding=int"
290
+ return query_params
291
+
292
+ class _BaseListModels:
293
+ def __hash__(self): # pragma: NO COVER
294
+ return NotImplementedError("__hash__ must be implemented.")
295
+
296
+ @staticmethod
297
+ def _get_http_options():
298
+ http_options: List[Dict[str, str]] = [
299
+ {
300
+ "method": "get",
301
+ "uri": "/v1beta/models",
302
+ },
303
+ ]
304
+ return http_options
305
+
306
+ @staticmethod
307
+ def _get_transcoded_request(http_options, request):
308
+ pb_request = model_service.ListModelsRequest.pb(request)
309
+ transcoded_request = path_template.transcode(http_options, pb_request)
310
+ return transcoded_request
311
+
312
+ @staticmethod
313
+ def _get_query_params_json(transcoded_request):
314
+ query_params = json.loads(
315
+ json_format.MessageToJson(
316
+ transcoded_request["query_params"],
317
+ use_integers_for_enums=True,
318
+ )
319
+ )
320
+
321
+ query_params["$alt"] = "json;enum-encoding=int"
322
+ return query_params
323
+
324
+ class _BaseListTunedModels:
325
+ def __hash__(self): # pragma: NO COVER
326
+ return NotImplementedError("__hash__ must be implemented.")
327
+
328
+ @staticmethod
329
+ def _get_http_options():
330
+ http_options: List[Dict[str, str]] = [
331
+ {
332
+ "method": "get",
333
+ "uri": "/v1beta/tunedModels",
334
+ },
335
+ ]
336
+ return http_options
337
+
338
+ @staticmethod
339
+ def _get_transcoded_request(http_options, request):
340
+ pb_request = model_service.ListTunedModelsRequest.pb(request)
341
+ transcoded_request = path_template.transcode(http_options, pb_request)
342
+ return transcoded_request
343
+
344
+ @staticmethod
345
+ def _get_query_params_json(transcoded_request):
346
+ query_params = json.loads(
347
+ json_format.MessageToJson(
348
+ transcoded_request["query_params"],
349
+ use_integers_for_enums=True,
350
+ )
351
+ )
352
+
353
+ query_params["$alt"] = "json;enum-encoding=int"
354
+ return query_params
355
+
356
+ class _BaseUpdateTunedModel:
357
+ def __hash__(self): # pragma: NO COVER
358
+ return NotImplementedError("__hash__ must be implemented.")
359
+
360
+ __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
361
+
362
+ @classmethod
363
+ def _get_unset_required_fields(cls, message_dict):
364
+ return {
365
+ k: v
366
+ for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
367
+ if k not in message_dict
368
+ }
369
+
370
+ @staticmethod
371
+ def _get_http_options():
372
+ http_options: List[Dict[str, str]] = [
373
+ {
374
+ "method": "patch",
375
+ "uri": "/v1beta/{tuned_model.name=tunedModels/*}",
376
+ "body": "tuned_model",
377
+ },
378
+ ]
379
+ return http_options
380
+
381
+ @staticmethod
382
+ def _get_transcoded_request(http_options, request):
383
+ pb_request = model_service.UpdateTunedModelRequest.pb(request)
384
+ transcoded_request = path_template.transcode(http_options, pb_request)
385
+ return transcoded_request
386
+
387
+ @staticmethod
388
+ def _get_request_body_json(transcoded_request):
389
+ # Jsonify the request body
390
+
391
+ body = json_format.MessageToJson(
392
+ transcoded_request["body"], use_integers_for_enums=True
393
+ )
394
+ return body
395
+
396
+ @staticmethod
397
+ def _get_query_params_json(transcoded_request):
398
+ query_params = json.loads(
399
+ json_format.MessageToJson(
400
+ transcoded_request["query_params"],
401
+ use_integers_for_enums=True,
402
+ )
403
+ )
404
+ query_params.update(
405
+ _BaseModelServiceRestTransport._BaseUpdateTunedModel._get_unset_required_fields(
406
+ query_params
407
+ )
408
+ )
409
+
410
+ query_params["$alt"] = "json;enum-encoding=int"
411
+ return query_params
412
+
413
+ class _BaseGetOperation:
414
+ def __hash__(self): # pragma: NO COVER
415
+ return NotImplementedError("__hash__ must be implemented.")
416
+
417
+ @staticmethod
418
+ def _get_http_options():
419
+ http_options: List[Dict[str, str]] = [
420
+ {
421
+ "method": "get",
422
+ "uri": "/v1beta/{name=tunedModels/*/operations/*}",
423
+ },
424
+ {
425
+ "method": "get",
426
+ "uri": "/v1beta/{name=generatedFiles/*/operations/*}",
427
+ },
428
+ {
429
+ "method": "get",
430
+ "uri": "/v1beta/{name=models/*/operations/*}",
431
+ },
432
+ ]
433
+ return http_options
434
+
435
+ @staticmethod
436
+ def _get_transcoded_request(http_options, request):
437
+ request_kwargs = json_format.MessageToDict(request)
438
+ transcoded_request = path_template.transcode(http_options, **request_kwargs)
439
+ return transcoded_request
440
+
441
+ @staticmethod
442
+ def _get_query_params_json(transcoded_request):
443
+ query_params = json.loads(json.dumps(transcoded_request["query_params"]))
444
+ return query_params
445
+
446
+ class _BaseListOperations:
447
+ def __hash__(self): # pragma: NO COVER
448
+ return NotImplementedError("__hash__ must be implemented.")
449
+
450
+ @staticmethod
451
+ def _get_http_options():
452
+ http_options: List[Dict[str, str]] = [
453
+ {
454
+ "method": "get",
455
+ "uri": "/v1beta/{name=tunedModels/*}/operations",
456
+ },
457
+ {
458
+ "method": "get",
459
+ "uri": "/v1beta/{name=models/*}/operations",
460
+ },
461
+ ]
462
+ return http_options
463
+
464
+ @staticmethod
465
+ def _get_transcoded_request(http_options, request):
466
+ request_kwargs = json_format.MessageToDict(request)
467
+ transcoded_request = path_template.transcode(http_options, **request_kwargs)
468
+ return transcoded_request
469
+
470
+ @staticmethod
471
+ def _get_query_params_json(transcoded_request):
472
+ query_params = json.loads(json.dumps(transcoded_request["query_params"]))
473
+ return query_params
474
+
475
+
476
+ __all__ = ("_BaseModelServiceRestTransport",)
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/__init__.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ from .async_client import PermissionServiceAsyncClient
17
+ from .client import PermissionServiceClient
18
+
19
+ __all__ = (
20
+ "PermissionServiceClient",
21
+ "PermissionServiceAsyncClient",
22
+ )
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (417 Bytes). View file
 
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/__pycache__/async_client.cpython-311.pyc ADDED
Binary file (46.1 kB). View file
 
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/__pycache__/client.cpython-311.pyc ADDED
Binary file (62.1 kB). View file
 
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/__pycache__/pagers.cpython-311.pyc ADDED
Binary file (10.2 kB). View file
 
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/async_client.py ADDED
@@ -0,0 +1,1150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ from collections import OrderedDict
17
+ import logging as std_logging
18
+ import re
19
+ from typing import (
20
+ Callable,
21
+ Dict,
22
+ Mapping,
23
+ MutableMapping,
24
+ MutableSequence,
25
+ Optional,
26
+ Sequence,
27
+ Tuple,
28
+ Type,
29
+ Union,
30
+ )
31
+
32
+ from google.api_core import exceptions as core_exceptions
33
+ from google.api_core import gapic_v1
34
+ from google.api_core import retry_async as retries
35
+ from google.api_core.client_options import ClientOptions
36
+ from google.auth import credentials as ga_credentials # type: ignore
37
+ from google.oauth2 import service_account # type: ignore
38
+
39
+ from google.ai.generativelanguage_v1beta import gapic_version as package_version
40
+
41
+ try:
42
+ OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None]
43
+ except AttributeError: # pragma: NO COVER
44
+ OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore
45
+
46
+ from google.longrunning import operations_pb2 # type: ignore
47
+ from google.protobuf import field_mask_pb2 # type: ignore
48
+
49
+ from google.ai.generativelanguage_v1beta.services.permission_service import pagers
50
+ from google.ai.generativelanguage_v1beta.types import permission as gag_permission
51
+ from google.ai.generativelanguage_v1beta.types import permission
52
+ from google.ai.generativelanguage_v1beta.types import permission_service
53
+
54
+ from .client import PermissionServiceClient
55
+ from .transports.base import DEFAULT_CLIENT_INFO, PermissionServiceTransport
56
+ from .transports.grpc_asyncio import PermissionServiceGrpcAsyncIOTransport
57
+
58
+ try:
59
+ from google.api_core import client_logging # type: ignore
60
+
61
+ CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
62
+ except ImportError: # pragma: NO COVER
63
+ CLIENT_LOGGING_SUPPORTED = False
64
+
65
+ _LOGGER = std_logging.getLogger(__name__)
66
+
67
+
68
+ class PermissionServiceAsyncClient:
69
+ """Provides methods for managing permissions to PaLM API
70
+ resources.
71
+ """
72
+
73
+ _client: PermissionServiceClient
74
+
75
+ # Copy defaults from the synchronous client for use here.
76
+ # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead.
77
+ DEFAULT_ENDPOINT = PermissionServiceClient.DEFAULT_ENDPOINT
78
+ DEFAULT_MTLS_ENDPOINT = PermissionServiceClient.DEFAULT_MTLS_ENDPOINT
79
+ _DEFAULT_ENDPOINT_TEMPLATE = PermissionServiceClient._DEFAULT_ENDPOINT_TEMPLATE
80
+ _DEFAULT_UNIVERSE = PermissionServiceClient._DEFAULT_UNIVERSE
81
+
82
+ permission_path = staticmethod(PermissionServiceClient.permission_path)
83
+ parse_permission_path = staticmethod(PermissionServiceClient.parse_permission_path)
84
+ common_billing_account_path = staticmethod(
85
+ PermissionServiceClient.common_billing_account_path
86
+ )
87
+ parse_common_billing_account_path = staticmethod(
88
+ PermissionServiceClient.parse_common_billing_account_path
89
+ )
90
+ common_folder_path = staticmethod(PermissionServiceClient.common_folder_path)
91
+ parse_common_folder_path = staticmethod(
92
+ PermissionServiceClient.parse_common_folder_path
93
+ )
94
+ common_organization_path = staticmethod(
95
+ PermissionServiceClient.common_organization_path
96
+ )
97
+ parse_common_organization_path = staticmethod(
98
+ PermissionServiceClient.parse_common_organization_path
99
+ )
100
+ common_project_path = staticmethod(PermissionServiceClient.common_project_path)
101
+ parse_common_project_path = staticmethod(
102
+ PermissionServiceClient.parse_common_project_path
103
+ )
104
+ common_location_path = staticmethod(PermissionServiceClient.common_location_path)
105
+ parse_common_location_path = staticmethod(
106
+ PermissionServiceClient.parse_common_location_path
107
+ )
108
+
109
+ @classmethod
110
+ def from_service_account_info(cls, info: dict, *args, **kwargs):
111
+ """Creates an instance of this client using the provided credentials
112
+ info.
113
+
114
+ Args:
115
+ info (dict): The service account private key info.
116
+ args: Additional arguments to pass to the constructor.
117
+ kwargs: Additional arguments to pass to the constructor.
118
+
119
+ Returns:
120
+ PermissionServiceAsyncClient: The constructed client.
121
+ """
122
+ return PermissionServiceClient.from_service_account_info.__func__(PermissionServiceAsyncClient, info, *args, **kwargs) # type: ignore
123
+
124
+ @classmethod
125
+ def from_service_account_file(cls, filename: str, *args, **kwargs):
126
+ """Creates an instance of this client using the provided credentials
127
+ file.
128
+
129
+ Args:
130
+ filename (str): The path to the service account private key json
131
+ file.
132
+ args: Additional arguments to pass to the constructor.
133
+ kwargs: Additional arguments to pass to the constructor.
134
+
135
+ Returns:
136
+ PermissionServiceAsyncClient: The constructed client.
137
+ """
138
+ return PermissionServiceClient.from_service_account_file.__func__(PermissionServiceAsyncClient, filename, *args, **kwargs) # type: ignore
139
+
140
+ from_service_account_json = from_service_account_file
141
+
142
+ @classmethod
143
+ def get_mtls_endpoint_and_cert_source(
144
+ cls, client_options: Optional[ClientOptions] = None
145
+ ):
146
+ """Return the API endpoint and client cert source for mutual TLS.
147
+
148
+ The client cert source is determined in the following order:
149
+ (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
150
+ client cert source is None.
151
+ (2) if `client_options.client_cert_source` is provided, use the provided one; if the
152
+ default client cert source exists, use the default one; otherwise the client cert
153
+ source is None.
154
+
155
+ The API endpoint is determined in the following order:
156
+ (1) if `client_options.api_endpoint` if provided, use the provided one.
157
+ (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
158
+ default mTLS endpoint; if the environment variable is "never", use the default API
159
+ endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
160
+ use the default API endpoint.
161
+
162
+ More details can be found at https://google.aip.dev/auth/4114.
163
+
164
+ Args:
165
+ client_options (google.api_core.client_options.ClientOptions): Custom options for the
166
+ client. Only the `api_endpoint` and `client_cert_source` properties may be used
167
+ in this method.
168
+
169
+ Returns:
170
+ Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
171
+ client cert source to use.
172
+
173
+ Raises:
174
+ google.auth.exceptions.MutualTLSChannelError: If any errors happen.
175
+ """
176
+ return PermissionServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore
177
+
178
+ @property
179
+ def transport(self) -> PermissionServiceTransport:
180
+ """Returns the transport used by the client instance.
181
+
182
+ Returns:
183
+ PermissionServiceTransport: The transport used by the client instance.
184
+ """
185
+ return self._client.transport
186
+
187
+ @property
188
+ def api_endpoint(self):
189
+ """Return the API endpoint used by the client instance.
190
+
191
+ Returns:
192
+ str: The API endpoint used by the client instance.
193
+ """
194
+ return self._client._api_endpoint
195
+
196
+ @property
197
+ def universe_domain(self) -> str:
198
+ """Return the universe domain used by the client instance.
199
+
200
+ Returns:
201
+ str: The universe domain used
202
+ by the client instance.
203
+ """
204
+ return self._client._universe_domain
205
+
206
+ get_transport_class = PermissionServiceClient.get_transport_class
207
+
208
+ def __init__(
209
+ self,
210
+ *,
211
+ credentials: Optional[ga_credentials.Credentials] = None,
212
+ transport: Optional[
213
+ Union[
214
+ str,
215
+ PermissionServiceTransport,
216
+ Callable[..., PermissionServiceTransport],
217
+ ]
218
+ ] = "grpc_asyncio",
219
+ client_options: Optional[ClientOptions] = None,
220
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
221
+ ) -> None:
222
+ """Instantiates the permission service async client.
223
+
224
+ Args:
225
+ credentials (Optional[google.auth.credentials.Credentials]): The
226
+ authorization credentials to attach to requests. These
227
+ credentials identify the application to the service; if none
228
+ are specified, the client will attempt to ascertain the
229
+ credentials from the environment.
230
+ transport (Optional[Union[str,PermissionServiceTransport,Callable[..., PermissionServiceTransport]]]):
231
+ The transport to use, or a Callable that constructs and returns a new transport to use.
232
+ If a Callable is given, it will be called with the same set of initialization
233
+ arguments as used in the PermissionServiceTransport constructor.
234
+ If set to None, a transport is chosen automatically.
235
+ client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]):
236
+ Custom options for the client.
237
+
238
+ 1. The ``api_endpoint`` property can be used to override the
239
+ default endpoint provided by the client when ``transport`` is
240
+ not explicitly provided. Only if this property is not set and
241
+ ``transport`` was not explicitly provided, the endpoint is
242
+ determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment
243
+ variable, which have one of the following values:
244
+ "always" (always use the default mTLS endpoint), "never" (always
245
+ use the default regular endpoint) and "auto" (auto-switch to the
246
+ default mTLS endpoint if client certificate is present; this is
247
+ the default value).
248
+
249
+ 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
250
+ is "true", then the ``client_cert_source`` property can be used
251
+ to provide a client certificate for mTLS transport. If
252
+ not provided, the default SSL client certificate will be used if
253
+ present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
254
+ set, no client certificate will be used.
255
+
256
+ 3. The ``universe_domain`` property can be used to override the
257
+ default "googleapis.com" universe. Note that ``api_endpoint``
258
+ property still takes precedence; and ``universe_domain`` is
259
+ currently not supported for mTLS.
260
+
261
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
262
+ The client info used to send a user-agent string along with
263
+ API requests. If ``None``, then default info will be used.
264
+ Generally, you only need to set this if you're developing
265
+ your own client library.
266
+
267
+ Raises:
268
+ google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
269
+ creation failed for any reason.
270
+ """
271
+ self._client = PermissionServiceClient(
272
+ credentials=credentials,
273
+ transport=transport,
274
+ client_options=client_options,
275
+ client_info=client_info,
276
+ )
277
+
278
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
279
+ std_logging.DEBUG
280
+ ): # pragma: NO COVER
281
+ _LOGGER.debug(
282
+ "Created client `google.ai.generativelanguage_v1beta.PermissionServiceAsyncClient`.",
283
+ extra={
284
+ "serviceName": "google.ai.generativelanguage.v1beta.PermissionService",
285
+ "universeDomain": getattr(
286
+ self._client._transport._credentials, "universe_domain", ""
287
+ ),
288
+ "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}",
289
+ "credentialsInfo": getattr(
290
+ self.transport._credentials, "get_cred_info", lambda: None
291
+ )(),
292
+ }
293
+ if hasattr(self._client._transport, "_credentials")
294
+ else {
295
+ "serviceName": "google.ai.generativelanguage.v1beta.PermissionService",
296
+ "credentialsType": None,
297
+ },
298
+ )
299
+
300
+ async def create_permission(
301
+ self,
302
+ request: Optional[
303
+ Union[permission_service.CreatePermissionRequest, dict]
304
+ ] = None,
305
+ *,
306
+ parent: Optional[str] = None,
307
+ permission: Optional[gag_permission.Permission] = None,
308
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
309
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
310
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
311
+ ) -> gag_permission.Permission:
312
+ r"""Create a permission to a specific resource.
313
+
314
+ .. code-block:: python
315
+
316
+ # This snippet has been automatically generated and should be regarded as a
317
+ # code template only.
318
+ # It will require modifications to work:
319
+ # - It may require correct/in-range values for request initialization.
320
+ # - It may require specifying regional endpoints when creating the service
321
+ # client as shown in:
322
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
323
+ from google.ai import generativelanguage_v1beta
324
+
325
+ async def sample_create_permission():
326
+ # Create a client
327
+ client = generativelanguage_v1beta.PermissionServiceAsyncClient()
328
+
329
+ # Initialize request argument(s)
330
+ request = generativelanguage_v1beta.CreatePermissionRequest(
331
+ parent="parent_value",
332
+ )
333
+
334
+ # Make the request
335
+ response = await client.create_permission(request=request)
336
+
337
+ # Handle the response
338
+ print(response)
339
+
340
+ Args:
341
+ request (Optional[Union[google.ai.generativelanguage_v1beta.types.CreatePermissionRequest, dict]]):
342
+ The request object. Request to create a ``Permission``.
343
+ parent (:class:`str`):
344
+ Required. The parent resource of the ``Permission``.
345
+ Formats: ``tunedModels/{tuned_model}``
346
+ ``corpora/{corpus}``
347
+
348
+ This corresponds to the ``parent`` field
349
+ on the ``request`` instance; if ``request`` is provided, this
350
+ should not be set.
351
+ permission (:class:`google.ai.generativelanguage_v1beta.types.Permission`):
352
+ Required. The permission to create.
353
+ This corresponds to the ``permission`` field
354
+ on the ``request`` instance; if ``request`` is provided, this
355
+ should not be set.
356
+ retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
357
+ should be retried.
358
+ timeout (float): The timeout for this request.
359
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
360
+ sent along with the request as metadata. Normally, each value must be of type `str`,
361
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
362
+ be of type `bytes`.
363
+
364
+ Returns:
365
+ google.ai.generativelanguage_v1beta.types.Permission:
366
+ Permission resource grants user,
367
+ group or the rest of the world access to
368
+ the PaLM API resource (e.g. a tuned
369
+ model, corpus).
370
+
371
+ A role is a collection of permitted
372
+ operations that allows users to perform
373
+ specific actions on PaLM API resources.
374
+ To make them available to users, groups,
375
+ or service accounts, you assign roles.
376
+ When you assign a role, you grant
377
+ permissions that the role contains.
378
+
379
+ There are three concentric roles. Each
380
+ role is a superset of the previous
381
+ role's permitted operations:
382
+
383
+ - reader can use the resource (e.g.
384
+ tuned model, corpus) for inference
385
+ - writer has reader's permissions and
386
+ additionally can edit and share
387
+ - owner has writer's permissions and
388
+ additionally can delete
389
+
390
+ """
391
+ # Create or coerce a protobuf request object.
392
+ # - Quick check: If we got a request object, we should *not* have
393
+ # gotten any keyword arguments that map to the request.
394
+ has_flattened_params = any([parent, permission])
395
+ if request is not None and has_flattened_params:
396
+ raise ValueError(
397
+ "If the `request` argument is set, then none of "
398
+ "the individual field arguments should be set."
399
+ )
400
+
401
+ # - Use the request object if provided (there's no risk of modifying the input as
402
+ # there are no flattened fields), or create one.
403
+ if not isinstance(request, permission_service.CreatePermissionRequest):
404
+ request = permission_service.CreatePermissionRequest(request)
405
+
406
+ # If we have keyword arguments corresponding to fields on the
407
+ # request, apply these.
408
+ if parent is not None:
409
+ request.parent = parent
410
+ if permission is not None:
411
+ request.permission = permission
412
+
413
+ # Wrap the RPC method; this adds retry and timeout information,
414
+ # and friendly error handling.
415
+ rpc = self._client._transport._wrapped_methods[
416
+ self._client._transport.create_permission
417
+ ]
418
+
419
+ # Certain fields should be provided within the metadata header;
420
+ # add these here.
421
+ metadata = tuple(metadata) + (
422
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
423
+ )
424
+
425
+ # Validate the universe domain.
426
+ self._client._validate_universe_domain()
427
+
428
+ # Send the request.
429
+ response = await rpc(
430
+ request,
431
+ retry=retry,
432
+ timeout=timeout,
433
+ metadata=metadata,
434
+ )
435
+
436
+ # Done; return the response.
437
+ return response
438
+
439
+ async def get_permission(
440
+ self,
441
+ request: Optional[Union[permission_service.GetPermissionRequest, dict]] = None,
442
+ *,
443
+ name: Optional[str] = None,
444
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
445
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
446
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
447
+ ) -> permission.Permission:
448
+ r"""Gets information about a specific Permission.
449
+
450
+ .. code-block:: python
451
+
452
+ # This snippet has been automatically generated and should be regarded as a
453
+ # code template only.
454
+ # It will require modifications to work:
455
+ # - It may require correct/in-range values for request initialization.
456
+ # - It may require specifying regional endpoints when creating the service
457
+ # client as shown in:
458
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
459
+ from google.ai import generativelanguage_v1beta
460
+
461
+ async def sample_get_permission():
462
+ # Create a client
463
+ client = generativelanguage_v1beta.PermissionServiceAsyncClient()
464
+
465
+ # Initialize request argument(s)
466
+ request = generativelanguage_v1beta.GetPermissionRequest(
467
+ name="name_value",
468
+ )
469
+
470
+ # Make the request
471
+ response = await client.get_permission(request=request)
472
+
473
+ # Handle the response
474
+ print(response)
475
+
476
+ Args:
477
+ request (Optional[Union[google.ai.generativelanguage_v1beta.types.GetPermissionRequest, dict]]):
478
+ The request object. Request for getting information about a specific
479
+ ``Permission``.
480
+ name (:class:`str`):
481
+ Required. The resource name of the permission.
482
+
483
+ Formats:
484
+ ``tunedModels/{tuned_model}/permissions/{permission}``
485
+ ``corpora/{corpus}/permissions/{permission}``
486
+
487
+ This corresponds to the ``name`` field
488
+ on the ``request`` instance; if ``request`` is provided, this
489
+ should not be set.
490
+ retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
491
+ should be retried.
492
+ timeout (float): The timeout for this request.
493
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
494
+ sent along with the request as metadata. Normally, each value must be of type `str`,
495
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
496
+ be of type `bytes`.
497
+
498
+ Returns:
499
+ google.ai.generativelanguage_v1beta.types.Permission:
500
+ Permission resource grants user,
501
+ group or the rest of the world access to
502
+ the PaLM API resource (e.g. a tuned
503
+ model, corpus).
504
+
505
+ A role is a collection of permitted
506
+ operations that allows users to perform
507
+ specific actions on PaLM API resources.
508
+ To make them available to users, groups,
509
+ or service accounts, you assign roles.
510
+ When you assign a role, you grant
511
+ permissions that the role contains.
512
+
513
+ There are three concentric roles. Each
514
+ role is a superset of the previous
515
+ role's permitted operations:
516
+
517
+ - reader can use the resource (e.g.
518
+ tuned model, corpus) for inference
519
+ - writer has reader's permissions and
520
+ additionally can edit and share
521
+ - owner has writer's permissions and
522
+ additionally can delete
523
+
524
+ """
525
+ # Create or coerce a protobuf request object.
526
+ # - Quick check: If we got a request object, we should *not* have
527
+ # gotten any keyword arguments that map to the request.
528
+ has_flattened_params = any([name])
529
+ if request is not None and has_flattened_params:
530
+ raise ValueError(
531
+ "If the `request` argument is set, then none of "
532
+ "the individual field arguments should be set."
533
+ )
534
+
535
+ # - Use the request object if provided (there's no risk of modifying the input as
536
+ # there are no flattened fields), or create one.
537
+ if not isinstance(request, permission_service.GetPermissionRequest):
538
+ request = permission_service.GetPermissionRequest(request)
539
+
540
+ # If we have keyword arguments corresponding to fields on the
541
+ # request, apply these.
542
+ if name is not None:
543
+ request.name = name
544
+
545
+ # Wrap the RPC method; this adds retry and timeout information,
546
+ # and friendly error handling.
547
+ rpc = self._client._transport._wrapped_methods[
548
+ self._client._transport.get_permission
549
+ ]
550
+
551
+ # Certain fields should be provided within the metadata header;
552
+ # add these here.
553
+ metadata = tuple(metadata) + (
554
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
555
+ )
556
+
557
+ # Validate the universe domain.
558
+ self._client._validate_universe_domain()
559
+
560
+ # Send the request.
561
+ response = await rpc(
562
+ request,
563
+ retry=retry,
564
+ timeout=timeout,
565
+ metadata=metadata,
566
+ )
567
+
568
+ # Done; return the response.
569
+ return response
570
+
571
+ async def list_permissions(
572
+ self,
573
+ request: Optional[
574
+ Union[permission_service.ListPermissionsRequest, dict]
575
+ ] = None,
576
+ *,
577
+ parent: Optional[str] = None,
578
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
579
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
580
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
581
+ ) -> pagers.ListPermissionsAsyncPager:
582
+ r"""Lists permissions for the specific resource.
583
+
584
+ .. code-block:: python
585
+
586
+ # This snippet has been automatically generated and should be regarded as a
587
+ # code template only.
588
+ # It will require modifications to work:
589
+ # - It may require correct/in-range values for request initialization.
590
+ # - It may require specifying regional endpoints when creating the service
591
+ # client as shown in:
592
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
593
+ from google.ai import generativelanguage_v1beta
594
+
595
+ async def sample_list_permissions():
596
+ # Create a client
597
+ client = generativelanguage_v1beta.PermissionServiceAsyncClient()
598
+
599
+ # Initialize request argument(s)
600
+ request = generativelanguage_v1beta.ListPermissionsRequest(
601
+ parent="parent_value",
602
+ )
603
+
604
+ # Make the request
605
+ page_result = client.list_permissions(request=request)
606
+
607
+ # Handle the response
608
+ async for response in page_result:
609
+ print(response)
610
+
611
+ Args:
612
+ request (Optional[Union[google.ai.generativelanguage_v1beta.types.ListPermissionsRequest, dict]]):
613
+ The request object. Request for listing permissions.
614
+ parent (:class:`str`):
615
+ Required. The parent resource of the permissions.
616
+ Formats: ``tunedModels/{tuned_model}``
617
+ ``corpora/{corpus}``
618
+
619
+ This corresponds to the ``parent`` field
620
+ on the ``request`` instance; if ``request`` is provided, this
621
+ should not be set.
622
+ retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
623
+ should be retried.
624
+ timeout (float): The timeout for this request.
625
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
626
+ sent along with the request as metadata. Normally, each value must be of type `str`,
627
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
628
+ be of type `bytes`.
629
+
630
+ Returns:
631
+ google.ai.generativelanguage_v1beta.services.permission_service.pagers.ListPermissionsAsyncPager:
632
+ Response from ListPermissions containing a paginated list of
633
+ permissions.
634
+
635
+ Iterating over this object will yield results and
636
+ resolve additional pages automatically.
637
+
638
+ """
639
+ # Create or coerce a protobuf request object.
640
+ # - Quick check: If we got a request object, we should *not* have
641
+ # gotten any keyword arguments that map to the request.
642
+ has_flattened_params = any([parent])
643
+ if request is not None and has_flattened_params:
644
+ raise ValueError(
645
+ "If the `request` argument is set, then none of "
646
+ "the individual field arguments should be set."
647
+ )
648
+
649
+ # - Use the request object if provided (there's no risk of modifying the input as
650
+ # there are no flattened fields), or create one.
651
+ if not isinstance(request, permission_service.ListPermissionsRequest):
652
+ request = permission_service.ListPermissionsRequest(request)
653
+
654
+ # If we have keyword arguments corresponding to fields on the
655
+ # request, apply these.
656
+ if parent is not None:
657
+ request.parent = parent
658
+
659
+ # Wrap the RPC method; this adds retry and timeout information,
660
+ # and friendly error handling.
661
+ rpc = self._client._transport._wrapped_methods[
662
+ self._client._transport.list_permissions
663
+ ]
664
+
665
+ # Certain fields should be provided within the metadata header;
666
+ # add these here.
667
+ metadata = tuple(metadata) + (
668
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
669
+ )
670
+
671
+ # Validate the universe domain.
672
+ self._client._validate_universe_domain()
673
+
674
+ # Send the request.
675
+ response = await rpc(
676
+ request,
677
+ retry=retry,
678
+ timeout=timeout,
679
+ metadata=metadata,
680
+ )
681
+
682
+ # This method is paged; wrap the response in a pager, which provides
683
+ # an `__aiter__` convenience method.
684
+ response = pagers.ListPermissionsAsyncPager(
685
+ method=rpc,
686
+ request=request,
687
+ response=response,
688
+ retry=retry,
689
+ timeout=timeout,
690
+ metadata=metadata,
691
+ )
692
+
693
+ # Done; return the response.
694
+ return response
695
+
696
+ async def update_permission(
697
+ self,
698
+ request: Optional[
699
+ Union[permission_service.UpdatePermissionRequest, dict]
700
+ ] = None,
701
+ *,
702
+ permission: Optional[gag_permission.Permission] = None,
703
+ update_mask: Optional[field_mask_pb2.FieldMask] = None,
704
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
705
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
706
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
707
+ ) -> gag_permission.Permission:
708
+ r"""Updates the permission.
709
+
710
+ .. code-block:: python
711
+
712
+ # This snippet has been automatically generated and should be regarded as a
713
+ # code template only.
714
+ # It will require modifications to work:
715
+ # - It may require correct/in-range values for request initialization.
716
+ # - It may require specifying regional endpoints when creating the service
717
+ # client as shown in:
718
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
719
+ from google.ai import generativelanguage_v1beta
720
+
721
+ async def sample_update_permission():
722
+ # Create a client
723
+ client = generativelanguage_v1beta.PermissionServiceAsyncClient()
724
+
725
+ # Initialize request argument(s)
726
+ request = generativelanguage_v1beta.UpdatePermissionRequest(
727
+ )
728
+
729
+ # Make the request
730
+ response = await client.update_permission(request=request)
731
+
732
+ # Handle the response
733
+ print(response)
734
+
735
+ Args:
736
+ request (Optional[Union[google.ai.generativelanguage_v1beta.types.UpdatePermissionRequest, dict]]):
737
+ The request object. Request to update the ``Permission``.
738
+ permission (:class:`google.ai.generativelanguage_v1beta.types.Permission`):
739
+ Required. The permission to update.
740
+
741
+ The permission's ``name`` field is used to identify the
742
+ permission to update.
743
+
744
+ This corresponds to the ``permission`` field
745
+ on the ``request`` instance; if ``request`` is provided, this
746
+ should not be set.
747
+ update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`):
748
+ Required. The list of fields to update. Accepted ones:
749
+
750
+ - role (``Permission.role`` field)
751
+
752
+ This corresponds to the ``update_mask`` field
753
+ on the ``request`` instance; if ``request`` is provided, this
754
+ should not be set.
755
+ retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
756
+ should be retried.
757
+ timeout (float): The timeout for this request.
758
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
759
+ sent along with the request as metadata. Normally, each value must be of type `str`,
760
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
761
+ be of type `bytes`.
762
+
763
+ Returns:
764
+ google.ai.generativelanguage_v1beta.types.Permission:
765
+ Permission resource grants user,
766
+ group or the rest of the world access to
767
+ the PaLM API resource (e.g. a tuned
768
+ model, corpus).
769
+
770
+ A role is a collection of permitted
771
+ operations that allows users to perform
772
+ specific actions on PaLM API resources.
773
+ To make them available to users, groups,
774
+ or service accounts, you assign roles.
775
+ When you assign a role, you grant
776
+ permissions that the role contains.
777
+
778
+ There are three concentric roles. Each
779
+ role is a superset of the previous
780
+ role's permitted operations:
781
+
782
+ - reader can use the resource (e.g.
783
+ tuned model, corpus) for inference
784
+ - writer has reader's permissions and
785
+ additionally can edit and share
786
+ - owner has writer's permissions and
787
+ additionally can delete
788
+
789
+ """
790
+ # Create or coerce a protobuf request object.
791
+ # - Quick check: If we got a request object, we should *not* have
792
+ # gotten any keyword arguments that map to the request.
793
+ has_flattened_params = any([permission, update_mask])
794
+ if request is not None and has_flattened_params:
795
+ raise ValueError(
796
+ "If the `request` argument is set, then none of "
797
+ "the individual field arguments should be set."
798
+ )
799
+
800
+ # - Use the request object if provided (there's no risk of modifying the input as
801
+ # there are no flattened fields), or create one.
802
+ if not isinstance(request, permission_service.UpdatePermissionRequest):
803
+ request = permission_service.UpdatePermissionRequest(request)
804
+
805
+ # If we have keyword arguments corresponding to fields on the
806
+ # request, apply these.
807
+ if permission is not None:
808
+ request.permission = permission
809
+ if update_mask is not None:
810
+ request.update_mask = update_mask
811
+
812
+ # Wrap the RPC method; this adds retry and timeout information,
813
+ # and friendly error handling.
814
+ rpc = self._client._transport._wrapped_methods[
815
+ self._client._transport.update_permission
816
+ ]
817
+
818
+ # Certain fields should be provided within the metadata header;
819
+ # add these here.
820
+ metadata = tuple(metadata) + (
821
+ gapic_v1.routing_header.to_grpc_metadata(
822
+ (("permission.name", request.permission.name),)
823
+ ),
824
+ )
825
+
826
+ # Validate the universe domain.
827
+ self._client._validate_universe_domain()
828
+
829
+ # Send the request.
830
+ response = await rpc(
831
+ request,
832
+ retry=retry,
833
+ timeout=timeout,
834
+ metadata=metadata,
835
+ )
836
+
837
+ # Done; return the response.
838
+ return response
839
+
840
+ async def delete_permission(
841
+ self,
842
+ request: Optional[
843
+ Union[permission_service.DeletePermissionRequest, dict]
844
+ ] = None,
845
+ *,
846
+ name: Optional[str] = None,
847
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
848
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
849
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
850
+ ) -> None:
851
+ r"""Deletes the permission.
852
+
853
+ .. code-block:: python
854
+
855
+ # This snippet has been automatically generated and should be regarded as a
856
+ # code template only.
857
+ # It will require modifications to work:
858
+ # - It may require correct/in-range values for request initialization.
859
+ # - It may require specifying regional endpoints when creating the service
860
+ # client as shown in:
861
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
862
+ from google.ai import generativelanguage_v1beta
863
+
864
+ async def sample_delete_permission():
865
+ # Create a client
866
+ client = generativelanguage_v1beta.PermissionServiceAsyncClient()
867
+
868
+ # Initialize request argument(s)
869
+ request = generativelanguage_v1beta.DeletePermissionRequest(
870
+ name="name_value",
871
+ )
872
+
873
+ # Make the request
874
+ await client.delete_permission(request=request)
875
+
876
+ Args:
877
+ request (Optional[Union[google.ai.generativelanguage_v1beta.types.DeletePermissionRequest, dict]]):
878
+ The request object. Request to delete the ``Permission``.
879
+ name (:class:`str`):
880
+ Required. The resource name of the permission. Formats:
881
+ ``tunedModels/{tuned_model}/permissions/{permission}``
882
+ ``corpora/{corpus}/permissions/{permission}``
883
+
884
+ This corresponds to the ``name`` field
885
+ on the ``request`` instance; if ``request`` is provided, this
886
+ should not be set.
887
+ retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
888
+ should be retried.
889
+ timeout (float): The timeout for this request.
890
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
891
+ sent along with the request as metadata. Normally, each value must be of type `str`,
892
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
893
+ be of type `bytes`.
894
+ """
895
+ # Create or coerce a protobuf request object.
896
+ # - Quick check: If we got a request object, we should *not* have
897
+ # gotten any keyword arguments that map to the request.
898
+ has_flattened_params = any([name])
899
+ if request is not None and has_flattened_params:
900
+ raise ValueError(
901
+ "If the `request` argument is set, then none of "
902
+ "the individual field arguments should be set."
903
+ )
904
+
905
+ # - Use the request object if provided (there's no risk of modifying the input as
906
+ # there are no flattened fields), or create one.
907
+ if not isinstance(request, permission_service.DeletePermissionRequest):
908
+ request = permission_service.DeletePermissionRequest(request)
909
+
910
+ # If we have keyword arguments corresponding to fields on the
911
+ # request, apply these.
912
+ if name is not None:
913
+ request.name = name
914
+
915
+ # Wrap the RPC method; this adds retry and timeout information,
916
+ # and friendly error handling.
917
+ rpc = self._client._transport._wrapped_methods[
918
+ self._client._transport.delete_permission
919
+ ]
920
+
921
+ # Certain fields should be provided within the metadata header;
922
+ # add these here.
923
+ metadata = tuple(metadata) + (
924
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
925
+ )
926
+
927
+ # Validate the universe domain.
928
+ self._client._validate_universe_domain()
929
+
930
+ # Send the request.
931
+ await rpc(
932
+ request,
933
+ retry=retry,
934
+ timeout=timeout,
935
+ metadata=metadata,
936
+ )
937
+
938
+ async def transfer_ownership(
939
+ self,
940
+ request: Optional[
941
+ Union[permission_service.TransferOwnershipRequest, dict]
942
+ ] = None,
943
+ *,
944
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
945
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
946
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
947
+ ) -> permission_service.TransferOwnershipResponse:
948
+ r"""Transfers ownership of the tuned model.
949
+ This is the only way to change ownership of the tuned
950
+ model. The current owner will be downgraded to writer
951
+ role.
952
+
953
+ .. code-block:: python
954
+
955
+ # This snippet has been automatically generated and should be regarded as a
956
+ # code template only.
957
+ # It will require modifications to work:
958
+ # - It may require correct/in-range values for request initialization.
959
+ # - It may require specifying regional endpoints when creating the service
960
+ # client as shown in:
961
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
962
+ from google.ai import generativelanguage_v1beta
963
+
964
+ async def sample_transfer_ownership():
965
+ # Create a client
966
+ client = generativelanguage_v1beta.PermissionServiceAsyncClient()
967
+
968
+ # Initialize request argument(s)
969
+ request = generativelanguage_v1beta.TransferOwnershipRequest(
970
+ name="name_value",
971
+ email_address="email_address_value",
972
+ )
973
+
974
+ # Make the request
975
+ response = await client.transfer_ownership(request=request)
976
+
977
+ # Handle the response
978
+ print(response)
979
+
980
+ Args:
981
+ request (Optional[Union[google.ai.generativelanguage_v1beta.types.TransferOwnershipRequest, dict]]):
982
+ The request object. Request to transfer the ownership of
983
+ the tuned model.
984
+ retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
985
+ should be retried.
986
+ timeout (float): The timeout for this request.
987
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
988
+ sent along with the request as metadata. Normally, each value must be of type `str`,
989
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
990
+ be of type `bytes`.
991
+
992
+ Returns:
993
+ google.ai.generativelanguage_v1beta.types.TransferOwnershipResponse:
994
+ Response from TransferOwnership.
995
+ """
996
+ # Create or coerce a protobuf request object.
997
+ # - Use the request object if provided (there's no risk of modifying the input as
998
+ # there are no flattened fields), or create one.
999
+ if not isinstance(request, permission_service.TransferOwnershipRequest):
1000
+ request = permission_service.TransferOwnershipRequest(request)
1001
+
1002
+ # Wrap the RPC method; this adds retry and timeout information,
1003
+ # and friendly error handling.
1004
+ rpc = self._client._transport._wrapped_methods[
1005
+ self._client._transport.transfer_ownership
1006
+ ]
1007
+
1008
+ # Certain fields should be provided within the metadata header;
1009
+ # add these here.
1010
+ metadata = tuple(metadata) + (
1011
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1012
+ )
1013
+
1014
+ # Validate the universe domain.
1015
+ self._client._validate_universe_domain()
1016
+
1017
+ # Send the request.
1018
+ response = await rpc(
1019
+ request,
1020
+ retry=retry,
1021
+ timeout=timeout,
1022
+ metadata=metadata,
1023
+ )
1024
+
1025
+ # Done; return the response.
1026
+ return response
1027
+
1028
+ async def list_operations(
1029
+ self,
1030
+ request: Optional[operations_pb2.ListOperationsRequest] = None,
1031
+ *,
1032
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1033
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1034
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1035
+ ) -> operations_pb2.ListOperationsResponse:
1036
+ r"""Lists operations that match the specified filter in the request.
1037
+
1038
+ Args:
1039
+ request (:class:`~.operations_pb2.ListOperationsRequest`):
1040
+ The request object. Request message for
1041
+ `ListOperations` method.
1042
+ retry (google.api_core.retry_async.AsyncRetry): Designation of what errors,
1043
+ if any, should be retried.
1044
+ timeout (float): The timeout for this request.
1045
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1046
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1047
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1048
+ be of type `bytes`.
1049
+ Returns:
1050
+ ~.operations_pb2.ListOperationsResponse:
1051
+ Response message for ``ListOperations`` method.
1052
+ """
1053
+ # Create or coerce a protobuf request object.
1054
+ # The request isn't a proto-plus wrapped type,
1055
+ # so it must be constructed via keyword expansion.
1056
+ if isinstance(request, dict):
1057
+ request = operations_pb2.ListOperationsRequest(**request)
1058
+
1059
+ # Wrap the RPC method; this adds retry and timeout information,
1060
+ # and friendly error handling.
1061
+ rpc = self.transport._wrapped_methods[self._client._transport.list_operations]
1062
+
1063
+ # Certain fields should be provided within the metadata header;
1064
+ # add these here.
1065
+ metadata = tuple(metadata) + (
1066
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1067
+ )
1068
+
1069
+ # Validate the universe domain.
1070
+ self._client._validate_universe_domain()
1071
+
1072
+ # Send the request.
1073
+ response = await rpc(
1074
+ request,
1075
+ retry=retry,
1076
+ timeout=timeout,
1077
+ metadata=metadata,
1078
+ )
1079
+
1080
+ # Done; return the response.
1081
+ return response
1082
+
1083
+ async def get_operation(
1084
+ self,
1085
+ request: Optional[operations_pb2.GetOperationRequest] = None,
1086
+ *,
1087
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1088
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1089
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1090
+ ) -> operations_pb2.Operation:
1091
+ r"""Gets the latest state of a long-running operation.
1092
+
1093
+ Args:
1094
+ request (:class:`~.operations_pb2.GetOperationRequest`):
1095
+ The request object. Request message for
1096
+ `GetOperation` method.
1097
+ retry (google.api_core.retry_async.AsyncRetry): Designation of what errors,
1098
+ if any, should be retried.
1099
+ timeout (float): The timeout for this request.
1100
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1101
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1102
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1103
+ be of type `bytes`.
1104
+ Returns:
1105
+ ~.operations_pb2.Operation:
1106
+ An ``Operation`` object.
1107
+ """
1108
+ # Create or coerce a protobuf request object.
1109
+ # The request isn't a proto-plus wrapped type,
1110
+ # so it must be constructed via keyword expansion.
1111
+ if isinstance(request, dict):
1112
+ request = operations_pb2.GetOperationRequest(**request)
1113
+
1114
+ # Wrap the RPC method; this adds retry and timeout information,
1115
+ # and friendly error handling.
1116
+ rpc = self.transport._wrapped_methods[self._client._transport.get_operation]
1117
+
1118
+ # Certain fields should be provided within the metadata header;
1119
+ # add these here.
1120
+ metadata = tuple(metadata) + (
1121
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1122
+ )
1123
+
1124
+ # Validate the universe domain.
1125
+ self._client._validate_universe_domain()
1126
+
1127
+ # Send the request.
1128
+ response = await rpc(
1129
+ request,
1130
+ retry=retry,
1131
+ timeout=timeout,
1132
+ metadata=metadata,
1133
+ )
1134
+
1135
+ # Done; return the response.
1136
+ return response
1137
+
1138
+ async def __aenter__(self) -> "PermissionServiceAsyncClient":
1139
+ return self
1140
+
1141
+ async def __aexit__(self, exc_type, exc, tb):
1142
+ await self.transport.close()
1143
+
1144
+
1145
+ DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
1146
+ gapic_version=package_version.__version__
1147
+ )
1148
+
1149
+
1150
+ __all__ = ("PermissionServiceAsyncClient",)
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/client.py ADDED
@@ -0,0 +1,1532 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ from collections import OrderedDict
17
+ import logging as std_logging
18
+ import os
19
+ import re
20
+ from typing import (
21
+ Callable,
22
+ Dict,
23
+ Mapping,
24
+ MutableMapping,
25
+ MutableSequence,
26
+ Optional,
27
+ Sequence,
28
+ Tuple,
29
+ Type,
30
+ Union,
31
+ cast,
32
+ )
33
+ import warnings
34
+
35
+ from google.api_core import client_options as client_options_lib
36
+ from google.api_core import exceptions as core_exceptions
37
+ from google.api_core import gapic_v1
38
+ from google.api_core import retry as retries
39
+ from google.auth import credentials as ga_credentials # type: ignore
40
+ from google.auth.exceptions import MutualTLSChannelError # type: ignore
41
+ from google.auth.transport import mtls # type: ignore
42
+ from google.auth.transport.grpc import SslCredentials # type: ignore
43
+ from google.oauth2 import service_account # type: ignore
44
+
45
+ from google.ai.generativelanguage_v1beta import gapic_version as package_version
46
+
47
+ try:
48
+ OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
49
+ except AttributeError: # pragma: NO COVER
50
+ OptionalRetry = Union[retries.Retry, object, None] # type: ignore
51
+
52
+ try:
53
+ from google.api_core import client_logging # type: ignore
54
+
55
+ CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
56
+ except ImportError: # pragma: NO COVER
57
+ CLIENT_LOGGING_SUPPORTED = False
58
+
59
+ _LOGGER = std_logging.getLogger(__name__)
60
+
61
+ from google.longrunning import operations_pb2 # type: ignore
62
+ from google.protobuf import field_mask_pb2 # type: ignore
63
+
64
+ from google.ai.generativelanguage_v1beta.services.permission_service import pagers
65
+ from google.ai.generativelanguage_v1beta.types import permission as gag_permission
66
+ from google.ai.generativelanguage_v1beta.types import permission
67
+ from google.ai.generativelanguage_v1beta.types import permission_service
68
+
69
+ from .transports.base import DEFAULT_CLIENT_INFO, PermissionServiceTransport
70
+ from .transports.grpc import PermissionServiceGrpcTransport
71
+ from .transports.grpc_asyncio import PermissionServiceGrpcAsyncIOTransport
72
+ from .transports.rest import PermissionServiceRestTransport
73
+
74
+
75
+ class PermissionServiceClientMeta(type):
76
+ """Metaclass for the PermissionService client.
77
+
78
+ This provides class-level methods for building and retrieving
79
+ support objects (e.g. transport) without polluting the client instance
80
+ objects.
81
+ """
82
+
83
+ _transport_registry = (
84
+ OrderedDict()
85
+ ) # type: Dict[str, Type[PermissionServiceTransport]]
86
+ _transport_registry["grpc"] = PermissionServiceGrpcTransport
87
+ _transport_registry["grpc_asyncio"] = PermissionServiceGrpcAsyncIOTransport
88
+ _transport_registry["rest"] = PermissionServiceRestTransport
89
+
90
+ def get_transport_class(
91
+ cls,
92
+ label: Optional[str] = None,
93
+ ) -> Type[PermissionServiceTransport]:
94
+ """Returns an appropriate transport class.
95
+
96
+ Args:
97
+ label: The name of the desired transport. If none is
98
+ provided, then the first transport in the registry is used.
99
+
100
+ Returns:
101
+ The transport class to use.
102
+ """
103
+ # If a specific transport is requested, return that one.
104
+ if label:
105
+ return cls._transport_registry[label]
106
+
107
+ # No transport is requested; return the default (that is, the first one
108
+ # in the dictionary).
109
+ return next(iter(cls._transport_registry.values()))
110
+
111
+
112
+ class PermissionServiceClient(metaclass=PermissionServiceClientMeta):
113
+ """Provides methods for managing permissions to PaLM API
114
+ resources.
115
+ """
116
+
117
+ @staticmethod
118
+ def _get_default_mtls_endpoint(api_endpoint):
119
+ """Converts api endpoint to mTLS endpoint.
120
+
121
+ Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to
122
+ "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively.
123
+ Args:
124
+ api_endpoint (Optional[str]): the api endpoint to convert.
125
+ Returns:
126
+ str: converted mTLS api endpoint.
127
+ """
128
+ if not api_endpoint:
129
+ return api_endpoint
130
+
131
+ mtls_endpoint_re = re.compile(
132
+ r"(?P<name>[^.]+)(?P<mtls>\.mtls)?(?P<sandbox>\.sandbox)?(?P<googledomain>\.googleapis\.com)?"
133
+ )
134
+
135
+ m = mtls_endpoint_re.match(api_endpoint)
136
+ name, mtls, sandbox, googledomain = m.groups()
137
+ if mtls or not googledomain:
138
+ return api_endpoint
139
+
140
+ if sandbox:
141
+ return api_endpoint.replace(
142
+ "sandbox.googleapis.com", "mtls.sandbox.googleapis.com"
143
+ )
144
+
145
+ return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com")
146
+
147
+ # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead.
148
+ DEFAULT_ENDPOINT = "generativelanguage.googleapis.com"
149
+ DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore
150
+ DEFAULT_ENDPOINT
151
+ )
152
+
153
+ _DEFAULT_ENDPOINT_TEMPLATE = "generativelanguage.{UNIVERSE_DOMAIN}"
154
+ _DEFAULT_UNIVERSE = "googleapis.com"
155
+
156
+ @classmethod
157
+ def from_service_account_info(cls, info: dict, *args, **kwargs):
158
+ """Creates an instance of this client using the provided credentials
159
+ info.
160
+
161
+ Args:
162
+ info (dict): The service account private key info.
163
+ args: Additional arguments to pass to the constructor.
164
+ kwargs: Additional arguments to pass to the constructor.
165
+
166
+ Returns:
167
+ PermissionServiceClient: The constructed client.
168
+ """
169
+ credentials = service_account.Credentials.from_service_account_info(info)
170
+ kwargs["credentials"] = credentials
171
+ return cls(*args, **kwargs)
172
+
173
+ @classmethod
174
+ def from_service_account_file(cls, filename: str, *args, **kwargs):
175
+ """Creates an instance of this client using the provided credentials
176
+ file.
177
+
178
+ Args:
179
+ filename (str): The path to the service account private key json
180
+ file.
181
+ args: Additional arguments to pass to the constructor.
182
+ kwargs: Additional arguments to pass to the constructor.
183
+
184
+ Returns:
185
+ PermissionServiceClient: The constructed client.
186
+ """
187
+ credentials = service_account.Credentials.from_service_account_file(filename)
188
+ kwargs["credentials"] = credentials
189
+ return cls(*args, **kwargs)
190
+
191
+ from_service_account_json = from_service_account_file
192
+
193
+ @property
194
+ def transport(self) -> PermissionServiceTransport:
195
+ """Returns the transport used by the client instance.
196
+
197
+ Returns:
198
+ PermissionServiceTransport: The transport used by the client
199
+ instance.
200
+ """
201
+ return self._transport
202
+
203
+ @staticmethod
204
+ def permission_path(
205
+ tuned_model: str,
206
+ permission: str,
207
+ ) -> str:
208
+ """Returns a fully-qualified permission string."""
209
+ return "tunedModels/{tuned_model}/permissions/{permission}".format(
210
+ tuned_model=tuned_model,
211
+ permission=permission,
212
+ )
213
+
214
+ @staticmethod
215
+ def parse_permission_path(path: str) -> Dict[str, str]:
216
+ """Parses a permission path into its component segments."""
217
+ m = re.match(
218
+ r"^tunedModels/(?P<tuned_model>.+?)/permissions/(?P<permission>.+?)$", path
219
+ )
220
+ return m.groupdict() if m else {}
221
+
222
+ @staticmethod
223
+ def common_billing_account_path(
224
+ billing_account: str,
225
+ ) -> str:
226
+ """Returns a fully-qualified billing_account string."""
227
+ return "billingAccounts/{billing_account}".format(
228
+ billing_account=billing_account,
229
+ )
230
+
231
+ @staticmethod
232
+ def parse_common_billing_account_path(path: str) -> Dict[str, str]:
233
+ """Parse a billing_account path into its component segments."""
234
+ m = re.match(r"^billingAccounts/(?P<billing_account>.+?)$", path)
235
+ return m.groupdict() if m else {}
236
+
237
+ @staticmethod
238
+ def common_folder_path(
239
+ folder: str,
240
+ ) -> str:
241
+ """Returns a fully-qualified folder string."""
242
+ return "folders/{folder}".format(
243
+ folder=folder,
244
+ )
245
+
246
+ @staticmethod
247
+ def parse_common_folder_path(path: str) -> Dict[str, str]:
248
+ """Parse a folder path into its component segments."""
249
+ m = re.match(r"^folders/(?P<folder>.+?)$", path)
250
+ return m.groupdict() if m else {}
251
+
252
+ @staticmethod
253
+ def common_organization_path(
254
+ organization: str,
255
+ ) -> str:
256
+ """Returns a fully-qualified organization string."""
257
+ return "organizations/{organization}".format(
258
+ organization=organization,
259
+ )
260
+
261
+ @staticmethod
262
+ def parse_common_organization_path(path: str) -> Dict[str, str]:
263
+ """Parse a organization path into its component segments."""
264
+ m = re.match(r"^organizations/(?P<organization>.+?)$", path)
265
+ return m.groupdict() if m else {}
266
+
267
+ @staticmethod
268
+ def common_project_path(
269
+ project: str,
270
+ ) -> str:
271
+ """Returns a fully-qualified project string."""
272
+ return "projects/{project}".format(
273
+ project=project,
274
+ )
275
+
276
+ @staticmethod
277
+ def parse_common_project_path(path: str) -> Dict[str, str]:
278
+ """Parse a project path into its component segments."""
279
+ m = re.match(r"^projects/(?P<project>.+?)$", path)
280
+ return m.groupdict() if m else {}
281
+
282
+ @staticmethod
283
+ def common_location_path(
284
+ project: str,
285
+ location: str,
286
+ ) -> str:
287
+ """Returns a fully-qualified location string."""
288
+ return "projects/{project}/locations/{location}".format(
289
+ project=project,
290
+ location=location,
291
+ )
292
+
293
+ @staticmethod
294
+ def parse_common_location_path(path: str) -> Dict[str, str]:
295
+ """Parse a location path into its component segments."""
296
+ m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path)
297
+ return m.groupdict() if m else {}
298
+
299
+ @classmethod
300
+ def get_mtls_endpoint_and_cert_source(
301
+ cls, client_options: Optional[client_options_lib.ClientOptions] = None
302
+ ):
303
+ """Deprecated. Return the API endpoint and client cert source for mutual TLS.
304
+
305
+ The client cert source is determined in the following order:
306
+ (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
307
+ client cert source is None.
308
+ (2) if `client_options.client_cert_source` is provided, use the provided one; if the
309
+ default client cert source exists, use the default one; otherwise the client cert
310
+ source is None.
311
+
312
+ The API endpoint is determined in the following order:
313
+ (1) if `client_options.api_endpoint` if provided, use the provided one.
314
+ (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
315
+ default mTLS endpoint; if the environment variable is "never", use the default API
316
+ endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
317
+ use the default API endpoint.
318
+
319
+ More details can be found at https://google.aip.dev/auth/4114.
320
+
321
+ Args:
322
+ client_options (google.api_core.client_options.ClientOptions): Custom options for the
323
+ client. Only the `api_endpoint` and `client_cert_source` properties may be used
324
+ in this method.
325
+
326
+ Returns:
327
+ Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
328
+ client cert source to use.
329
+
330
+ Raises:
331
+ google.auth.exceptions.MutualTLSChannelError: If any errors happen.
332
+ """
333
+
334
+ warnings.warn(
335
+ "get_mtls_endpoint_and_cert_source is deprecated. Use the api_endpoint property instead.",
336
+ DeprecationWarning,
337
+ )
338
+ if client_options is None:
339
+ client_options = client_options_lib.ClientOptions()
340
+ use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")
341
+ use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
342
+ if use_client_cert not in ("true", "false"):
343
+ raise ValueError(
344
+ "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
345
+ )
346
+ if use_mtls_endpoint not in ("auto", "never", "always"):
347
+ raise MutualTLSChannelError(
348
+ "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
349
+ )
350
+
351
+ # Figure out the client cert source to use.
352
+ client_cert_source = None
353
+ if use_client_cert == "true":
354
+ if client_options.client_cert_source:
355
+ client_cert_source = client_options.client_cert_source
356
+ elif mtls.has_default_client_cert_source():
357
+ client_cert_source = mtls.default_client_cert_source()
358
+
359
+ # Figure out which api endpoint to use.
360
+ if client_options.api_endpoint is not None:
361
+ api_endpoint = client_options.api_endpoint
362
+ elif use_mtls_endpoint == "always" or (
363
+ use_mtls_endpoint == "auto" and client_cert_source
364
+ ):
365
+ api_endpoint = cls.DEFAULT_MTLS_ENDPOINT
366
+ else:
367
+ api_endpoint = cls.DEFAULT_ENDPOINT
368
+
369
+ return api_endpoint, client_cert_source
370
+
371
+ @staticmethod
372
+ def _read_environment_variables():
373
+ """Returns the environment variables used by the client.
374
+
375
+ Returns:
376
+ Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE,
377
+ GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables.
378
+
379
+ Raises:
380
+ ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not
381
+ any of ["true", "false"].
382
+ google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT
383
+ is not any of ["auto", "never", "always"].
384
+ """
385
+ use_client_cert = os.getenv(
386
+ "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
387
+ ).lower()
388
+ use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower()
389
+ universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN")
390
+ if use_client_cert not in ("true", "false"):
391
+ raise ValueError(
392
+ "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
393
+ )
394
+ if use_mtls_endpoint not in ("auto", "never", "always"):
395
+ raise MutualTLSChannelError(
396
+ "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
397
+ )
398
+ return use_client_cert == "true", use_mtls_endpoint, universe_domain_env
399
+
400
+ @staticmethod
401
+ def _get_client_cert_source(provided_cert_source, use_cert_flag):
402
+ """Return the client cert source to be used by the client.
403
+
404
+ Args:
405
+ provided_cert_source (bytes): The client certificate source provided.
406
+ use_cert_flag (bool): A flag indicating whether to use the client certificate.
407
+
408
+ Returns:
409
+ bytes or None: The client cert source to be used by the client.
410
+ """
411
+ client_cert_source = None
412
+ if use_cert_flag:
413
+ if provided_cert_source:
414
+ client_cert_source = provided_cert_source
415
+ elif mtls.has_default_client_cert_source():
416
+ client_cert_source = mtls.default_client_cert_source()
417
+ return client_cert_source
418
+
419
+ @staticmethod
420
+ def _get_api_endpoint(
421
+ api_override, client_cert_source, universe_domain, use_mtls_endpoint
422
+ ):
423
+ """Return the API endpoint used by the client.
424
+
425
+ Args:
426
+ api_override (str): The API endpoint override. If specified, this is always
427
+ the return value of this function and the other arguments are not used.
428
+ client_cert_source (bytes): The client certificate source used by the client.
429
+ universe_domain (str): The universe domain used by the client.
430
+ use_mtls_endpoint (str): How to use the mTLS endpoint, which depends also on the other parameters.
431
+ Possible values are "always", "auto", or "never".
432
+
433
+ Returns:
434
+ str: The API endpoint to be used by the client.
435
+ """
436
+ if api_override is not None:
437
+ api_endpoint = api_override
438
+ elif use_mtls_endpoint == "always" or (
439
+ use_mtls_endpoint == "auto" and client_cert_source
440
+ ):
441
+ _default_universe = PermissionServiceClient._DEFAULT_UNIVERSE
442
+ if universe_domain != _default_universe:
443
+ raise MutualTLSChannelError(
444
+ f"mTLS is not supported in any universe other than {_default_universe}."
445
+ )
446
+ api_endpoint = PermissionServiceClient.DEFAULT_MTLS_ENDPOINT
447
+ else:
448
+ api_endpoint = PermissionServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(
449
+ UNIVERSE_DOMAIN=universe_domain
450
+ )
451
+ return api_endpoint
452
+
453
+ @staticmethod
454
+ def _get_universe_domain(
455
+ client_universe_domain: Optional[str], universe_domain_env: Optional[str]
456
+ ) -> str:
457
+ """Return the universe domain used by the client.
458
+
459
+ Args:
460
+ client_universe_domain (Optional[str]): The universe domain configured via the client options.
461
+ universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable.
462
+
463
+ Returns:
464
+ str: The universe domain to be used by the client.
465
+
466
+ Raises:
467
+ ValueError: If the universe domain is an empty string.
468
+ """
469
+ universe_domain = PermissionServiceClient._DEFAULT_UNIVERSE
470
+ if client_universe_domain is not None:
471
+ universe_domain = client_universe_domain
472
+ elif universe_domain_env is not None:
473
+ universe_domain = universe_domain_env
474
+ if len(universe_domain.strip()) == 0:
475
+ raise ValueError("Universe Domain cannot be an empty string.")
476
+ return universe_domain
477
+
478
+ def _validate_universe_domain(self):
479
+ """Validates client's and credentials' universe domains are consistent.
480
+
481
+ Returns:
482
+ bool: True iff the configured universe domain is valid.
483
+
484
+ Raises:
485
+ ValueError: If the configured universe domain is not valid.
486
+ """
487
+
488
+ # NOTE (b/349488459): universe validation is disabled until further notice.
489
+ return True
490
+
491
+ @property
492
+ def api_endpoint(self):
493
+ """Return the API endpoint used by the client instance.
494
+
495
+ Returns:
496
+ str: The API endpoint used by the client instance.
497
+ """
498
+ return self._api_endpoint
499
+
500
+ @property
501
+ def universe_domain(self) -> str:
502
+ """Return the universe domain used by the client instance.
503
+
504
+ Returns:
505
+ str: The universe domain used by the client instance.
506
+ """
507
+ return self._universe_domain
508
+
509
+ def __init__(
510
+ self,
511
+ *,
512
+ credentials: Optional[ga_credentials.Credentials] = None,
513
+ transport: Optional[
514
+ Union[
515
+ str,
516
+ PermissionServiceTransport,
517
+ Callable[..., PermissionServiceTransport],
518
+ ]
519
+ ] = None,
520
+ client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None,
521
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
522
+ ) -> None:
523
+ """Instantiates the permission service client.
524
+
525
+ Args:
526
+ credentials (Optional[google.auth.credentials.Credentials]): The
527
+ authorization credentials to attach to requests. These
528
+ credentials identify the application to the service; if none
529
+ are specified, the client will attempt to ascertain the
530
+ credentials from the environment.
531
+ transport (Optional[Union[str,PermissionServiceTransport,Callable[..., PermissionServiceTransport]]]):
532
+ The transport to use, or a Callable that constructs and returns a new transport.
533
+ If a Callable is given, it will be called with the same set of initialization
534
+ arguments as used in the PermissionServiceTransport constructor.
535
+ If set to None, a transport is chosen automatically.
536
+ client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]):
537
+ Custom options for the client.
538
+
539
+ 1. The ``api_endpoint`` property can be used to override the
540
+ default endpoint provided by the client when ``transport`` is
541
+ not explicitly provided. Only if this property is not set and
542
+ ``transport`` was not explicitly provided, the endpoint is
543
+ determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment
544
+ variable, which have one of the following values:
545
+ "always" (always use the default mTLS endpoint), "never" (always
546
+ use the default regular endpoint) and "auto" (auto-switch to the
547
+ default mTLS endpoint if client certificate is present; this is
548
+ the default value).
549
+
550
+ 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
551
+ is "true", then the ``client_cert_source`` property can be used
552
+ to provide a client certificate for mTLS transport. If
553
+ not provided, the default SSL client certificate will be used if
554
+ present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
555
+ set, no client certificate will be used.
556
+
557
+ 3. The ``universe_domain`` property can be used to override the
558
+ default "googleapis.com" universe. Note that the ``api_endpoint``
559
+ property still takes precedence; and ``universe_domain`` is
560
+ currently not supported for mTLS.
561
+
562
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
563
+ The client info used to send a user-agent string along with
564
+ API requests. If ``None``, then default info will be used.
565
+ Generally, you only need to set this if you're developing
566
+ your own client library.
567
+
568
+ Raises:
569
+ google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
570
+ creation failed for any reason.
571
+ """
572
+ self._client_options = client_options
573
+ if isinstance(self._client_options, dict):
574
+ self._client_options = client_options_lib.from_dict(self._client_options)
575
+ if self._client_options is None:
576
+ self._client_options = client_options_lib.ClientOptions()
577
+ self._client_options = cast(
578
+ client_options_lib.ClientOptions, self._client_options
579
+ )
580
+
581
+ universe_domain_opt = getattr(self._client_options, "universe_domain", None)
582
+
583
+ (
584
+ self._use_client_cert,
585
+ self._use_mtls_endpoint,
586
+ self._universe_domain_env,
587
+ ) = PermissionServiceClient._read_environment_variables()
588
+ self._client_cert_source = PermissionServiceClient._get_client_cert_source(
589
+ self._client_options.client_cert_source, self._use_client_cert
590
+ )
591
+ self._universe_domain = PermissionServiceClient._get_universe_domain(
592
+ universe_domain_opt, self._universe_domain_env
593
+ )
594
+ self._api_endpoint = None # updated below, depending on `transport`
595
+
596
+ # Initialize the universe domain validation.
597
+ self._is_universe_domain_valid = False
598
+
599
+ if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER
600
+ # Setup logging.
601
+ client_logging.initialize_logging()
602
+
603
+ api_key_value = getattr(self._client_options, "api_key", None)
604
+ if api_key_value and credentials:
605
+ raise ValueError(
606
+ "client_options.api_key and credentials are mutually exclusive"
607
+ )
608
+
609
+ # Save or instantiate the transport.
610
+ # Ordinarily, we provide the transport, but allowing a custom transport
611
+ # instance provides an extensibility point for unusual situations.
612
+ transport_provided = isinstance(transport, PermissionServiceTransport)
613
+ if transport_provided:
614
+ # transport is a PermissionServiceTransport instance.
615
+ if credentials or self._client_options.credentials_file or api_key_value:
616
+ raise ValueError(
617
+ "When providing a transport instance, "
618
+ "provide its credentials directly."
619
+ )
620
+ if self._client_options.scopes:
621
+ raise ValueError(
622
+ "When providing a transport instance, provide its scopes "
623
+ "directly."
624
+ )
625
+ self._transport = cast(PermissionServiceTransport, transport)
626
+ self._api_endpoint = self._transport.host
627
+
628
+ self._api_endpoint = (
629
+ self._api_endpoint
630
+ or PermissionServiceClient._get_api_endpoint(
631
+ self._client_options.api_endpoint,
632
+ self._client_cert_source,
633
+ self._universe_domain,
634
+ self._use_mtls_endpoint,
635
+ )
636
+ )
637
+
638
+ if not transport_provided:
639
+ import google.auth._default # type: ignore
640
+
641
+ if api_key_value and hasattr(
642
+ google.auth._default, "get_api_key_credentials"
643
+ ):
644
+ credentials = google.auth._default.get_api_key_credentials(
645
+ api_key_value
646
+ )
647
+
648
+ transport_init: Union[
649
+ Type[PermissionServiceTransport],
650
+ Callable[..., PermissionServiceTransport],
651
+ ] = (
652
+ PermissionServiceClient.get_transport_class(transport)
653
+ if isinstance(transport, str) or transport is None
654
+ else cast(Callable[..., PermissionServiceTransport], transport)
655
+ )
656
+ # initialize with the provided callable or the passed in class
657
+ self._transport = transport_init(
658
+ credentials=credentials,
659
+ credentials_file=self._client_options.credentials_file,
660
+ host=self._api_endpoint,
661
+ scopes=self._client_options.scopes,
662
+ client_cert_source_for_mtls=self._client_cert_source,
663
+ quota_project_id=self._client_options.quota_project_id,
664
+ client_info=client_info,
665
+ always_use_jwt_access=True,
666
+ api_audience=self._client_options.api_audience,
667
+ )
668
+
669
+ if "async" not in str(self._transport):
670
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
671
+ std_logging.DEBUG
672
+ ): # pragma: NO COVER
673
+ _LOGGER.debug(
674
+ "Created client `google.ai.generativelanguage_v1beta.PermissionServiceClient`.",
675
+ extra={
676
+ "serviceName": "google.ai.generativelanguage.v1beta.PermissionService",
677
+ "universeDomain": getattr(
678
+ self._transport._credentials, "universe_domain", ""
679
+ ),
680
+ "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}",
681
+ "credentialsInfo": getattr(
682
+ self.transport._credentials, "get_cred_info", lambda: None
683
+ )(),
684
+ }
685
+ if hasattr(self._transport, "_credentials")
686
+ else {
687
+ "serviceName": "google.ai.generativelanguage.v1beta.PermissionService",
688
+ "credentialsType": None,
689
+ },
690
+ )
691
+
692
+ def create_permission(
693
+ self,
694
+ request: Optional[
695
+ Union[permission_service.CreatePermissionRequest, dict]
696
+ ] = None,
697
+ *,
698
+ parent: Optional[str] = None,
699
+ permission: Optional[gag_permission.Permission] = None,
700
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
701
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
702
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
703
+ ) -> gag_permission.Permission:
704
+ r"""Create a permission to a specific resource.
705
+
706
+ .. code-block:: python
707
+
708
+ # This snippet has been automatically generated and should be regarded as a
709
+ # code template only.
710
+ # It will require modifications to work:
711
+ # - It may require correct/in-range values for request initialization.
712
+ # - It may require specifying regional endpoints when creating the service
713
+ # client as shown in:
714
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
715
+ from google.ai import generativelanguage_v1beta
716
+
717
+ def sample_create_permission():
718
+ # Create a client
719
+ client = generativelanguage_v1beta.PermissionServiceClient()
720
+
721
+ # Initialize request argument(s)
722
+ request = generativelanguage_v1beta.CreatePermissionRequest(
723
+ parent="parent_value",
724
+ )
725
+
726
+ # Make the request
727
+ response = client.create_permission(request=request)
728
+
729
+ # Handle the response
730
+ print(response)
731
+
732
+ Args:
733
+ request (Union[google.ai.generativelanguage_v1beta.types.CreatePermissionRequest, dict]):
734
+ The request object. Request to create a ``Permission``.
735
+ parent (str):
736
+ Required. The parent resource of the ``Permission``.
737
+ Formats: ``tunedModels/{tuned_model}``
738
+ ``corpora/{corpus}``
739
+
740
+ This corresponds to the ``parent`` field
741
+ on the ``request`` instance; if ``request`` is provided, this
742
+ should not be set.
743
+ permission (google.ai.generativelanguage_v1beta.types.Permission):
744
+ Required. The permission to create.
745
+ This corresponds to the ``permission`` field
746
+ on the ``request`` instance; if ``request`` is provided, this
747
+ should not be set.
748
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
749
+ should be retried.
750
+ timeout (float): The timeout for this request.
751
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
752
+ sent along with the request as metadata. Normally, each value must be of type `str`,
753
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
754
+ be of type `bytes`.
755
+
756
+ Returns:
757
+ google.ai.generativelanguage_v1beta.types.Permission:
758
+ Permission resource grants user,
759
+ group or the rest of the world access to
760
+ the PaLM API resource (e.g. a tuned
761
+ model, corpus).
762
+
763
+ A role is a collection of permitted
764
+ operations that allows users to perform
765
+ specific actions on PaLM API resources.
766
+ To make them available to users, groups,
767
+ or service accounts, you assign roles.
768
+ When you assign a role, you grant
769
+ permissions that the role contains.
770
+
771
+ There are three concentric roles. Each
772
+ role is a superset of the previous
773
+ role's permitted operations:
774
+
775
+ - reader can use the resource (e.g.
776
+ tuned model, corpus) for inference
777
+ - writer has reader's permissions and
778
+ additionally can edit and share
779
+ - owner has writer's permissions and
780
+ additionally can delete
781
+
782
+ """
783
+ # Create or coerce a protobuf request object.
784
+ # - Quick check: If we got a request object, we should *not* have
785
+ # gotten any keyword arguments that map to the request.
786
+ has_flattened_params = any([parent, permission])
787
+ if request is not None and has_flattened_params:
788
+ raise ValueError(
789
+ "If the `request` argument is set, then none of "
790
+ "the individual field arguments should be set."
791
+ )
792
+
793
+ # - Use the request object if provided (there's no risk of modifying the input as
794
+ # there are no flattened fields), or create one.
795
+ if not isinstance(request, permission_service.CreatePermissionRequest):
796
+ request = permission_service.CreatePermissionRequest(request)
797
+ # If we have keyword arguments corresponding to fields on the
798
+ # request, apply these.
799
+ if parent is not None:
800
+ request.parent = parent
801
+ if permission is not None:
802
+ request.permission = permission
803
+
804
+ # Wrap the RPC method; this adds retry and timeout information,
805
+ # and friendly error handling.
806
+ rpc = self._transport._wrapped_methods[self._transport.create_permission]
807
+
808
+ # Certain fields should be provided within the metadata header;
809
+ # add these here.
810
+ metadata = tuple(metadata) + (
811
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
812
+ )
813
+
814
+ # Validate the universe domain.
815
+ self._validate_universe_domain()
816
+
817
+ # Send the request.
818
+ response = rpc(
819
+ request,
820
+ retry=retry,
821
+ timeout=timeout,
822
+ metadata=metadata,
823
+ )
824
+
825
+ # Done; return the response.
826
+ return response
827
+
828
+ def get_permission(
829
+ self,
830
+ request: Optional[Union[permission_service.GetPermissionRequest, dict]] = None,
831
+ *,
832
+ name: Optional[str] = None,
833
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
834
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
835
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
836
+ ) -> permission.Permission:
837
+ r"""Gets information about a specific Permission.
838
+
839
+ .. code-block:: python
840
+
841
+ # This snippet has been automatically generated and should be regarded as a
842
+ # code template only.
843
+ # It will require modifications to work:
844
+ # - It may require correct/in-range values for request initialization.
845
+ # - It may require specifying regional endpoints when creating the service
846
+ # client as shown in:
847
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
848
+ from google.ai import generativelanguage_v1beta
849
+
850
+ def sample_get_permission():
851
+ # Create a client
852
+ client = generativelanguage_v1beta.PermissionServiceClient()
853
+
854
+ # Initialize request argument(s)
855
+ request = generativelanguage_v1beta.GetPermissionRequest(
856
+ name="name_value",
857
+ )
858
+
859
+ # Make the request
860
+ response = client.get_permission(request=request)
861
+
862
+ # Handle the response
863
+ print(response)
864
+
865
+ Args:
866
+ request (Union[google.ai.generativelanguage_v1beta.types.GetPermissionRequest, dict]):
867
+ The request object. Request for getting information about a specific
868
+ ``Permission``.
869
+ name (str):
870
+ Required. The resource name of the permission.
871
+
872
+ Formats:
873
+ ``tunedModels/{tuned_model}/permissions/{permission}``
874
+ ``corpora/{corpus}/permissions/{permission}``
875
+
876
+ This corresponds to the ``name`` field
877
+ on the ``request`` instance; if ``request`` is provided, this
878
+ should not be set.
879
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
880
+ should be retried.
881
+ timeout (float): The timeout for this request.
882
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
883
+ sent along with the request as metadata. Normally, each value must be of type `str`,
884
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
885
+ be of type `bytes`.
886
+
887
+ Returns:
888
+ google.ai.generativelanguage_v1beta.types.Permission:
889
+ Permission resource grants user,
890
+ group or the rest of the world access to
891
+ the PaLM API resource (e.g. a tuned
892
+ model, corpus).
893
+
894
+ A role is a collection of permitted
895
+ operations that allows users to perform
896
+ specific actions on PaLM API resources.
897
+ To make them available to users, groups,
898
+ or service accounts, you assign roles.
899
+ When you assign a role, you grant
900
+ permissions that the role contains.
901
+
902
+ There are three concentric roles. Each
903
+ role is a superset of the previous
904
+ role's permitted operations:
905
+
906
+ - reader can use the resource (e.g.
907
+ tuned model, corpus) for inference
908
+ - writer has reader's permissions and
909
+ additionally can edit and share
910
+ - owner has writer's permissions and
911
+ additionally can delete
912
+
913
+ """
914
+ # Create or coerce a protobuf request object.
915
+ # - Quick check: If we got a request object, we should *not* have
916
+ # gotten any keyword arguments that map to the request.
917
+ has_flattened_params = any([name])
918
+ if request is not None and has_flattened_params:
919
+ raise ValueError(
920
+ "If the `request` argument is set, then none of "
921
+ "the individual field arguments should be set."
922
+ )
923
+
924
+ # - Use the request object if provided (there's no risk of modifying the input as
925
+ # there are no flattened fields), or create one.
926
+ if not isinstance(request, permission_service.GetPermissionRequest):
927
+ request = permission_service.GetPermissionRequest(request)
928
+ # If we have keyword arguments corresponding to fields on the
929
+ # request, apply these.
930
+ if name is not None:
931
+ request.name = name
932
+
933
+ # Wrap the RPC method; this adds retry and timeout information,
934
+ # and friendly error handling.
935
+ rpc = self._transport._wrapped_methods[self._transport.get_permission]
936
+
937
+ # Certain fields should be provided within the metadata header;
938
+ # add these here.
939
+ metadata = tuple(metadata) + (
940
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
941
+ )
942
+
943
+ # Validate the universe domain.
944
+ self._validate_universe_domain()
945
+
946
+ # Send the request.
947
+ response = rpc(
948
+ request,
949
+ retry=retry,
950
+ timeout=timeout,
951
+ metadata=metadata,
952
+ )
953
+
954
+ # Done; return the response.
955
+ return response
956
+
957
+ def list_permissions(
958
+ self,
959
+ request: Optional[
960
+ Union[permission_service.ListPermissionsRequest, dict]
961
+ ] = None,
962
+ *,
963
+ parent: Optional[str] = None,
964
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
965
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
966
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
967
+ ) -> pagers.ListPermissionsPager:
968
+ r"""Lists permissions for the specific resource.
969
+
970
+ .. code-block:: python
971
+
972
+ # This snippet has been automatically generated and should be regarded as a
973
+ # code template only.
974
+ # It will require modifications to work:
975
+ # - It may require correct/in-range values for request initialization.
976
+ # - It may require specifying regional endpoints when creating the service
977
+ # client as shown in:
978
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
979
+ from google.ai import generativelanguage_v1beta
980
+
981
+ def sample_list_permissions():
982
+ # Create a client
983
+ client = generativelanguage_v1beta.PermissionServiceClient()
984
+
985
+ # Initialize request argument(s)
986
+ request = generativelanguage_v1beta.ListPermissionsRequest(
987
+ parent="parent_value",
988
+ )
989
+
990
+ # Make the request
991
+ page_result = client.list_permissions(request=request)
992
+
993
+ # Handle the response
994
+ for response in page_result:
995
+ print(response)
996
+
997
+ Args:
998
+ request (Union[google.ai.generativelanguage_v1beta.types.ListPermissionsRequest, dict]):
999
+ The request object. Request for listing permissions.
1000
+ parent (str):
1001
+ Required. The parent resource of the permissions.
1002
+ Formats: ``tunedModels/{tuned_model}``
1003
+ ``corpora/{corpus}``
1004
+
1005
+ This corresponds to the ``parent`` field
1006
+ on the ``request`` instance; if ``request`` is provided, this
1007
+ should not be set.
1008
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1009
+ should be retried.
1010
+ timeout (float): The timeout for this request.
1011
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1012
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1013
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1014
+ be of type `bytes`.
1015
+
1016
+ Returns:
1017
+ google.ai.generativelanguage_v1beta.services.permission_service.pagers.ListPermissionsPager:
1018
+ Response from ListPermissions containing a paginated list of
1019
+ permissions.
1020
+
1021
+ Iterating over this object will yield results and
1022
+ resolve additional pages automatically.
1023
+
1024
+ """
1025
+ # Create or coerce a protobuf request object.
1026
+ # - Quick check: If we got a request object, we should *not* have
1027
+ # gotten any keyword arguments that map to the request.
1028
+ has_flattened_params = any([parent])
1029
+ if request is not None and has_flattened_params:
1030
+ raise ValueError(
1031
+ "If the `request` argument is set, then none of "
1032
+ "the individual field arguments should be set."
1033
+ )
1034
+
1035
+ # - Use the request object if provided (there's no risk of modifying the input as
1036
+ # there are no flattened fields), or create one.
1037
+ if not isinstance(request, permission_service.ListPermissionsRequest):
1038
+ request = permission_service.ListPermissionsRequest(request)
1039
+ # If we have keyword arguments corresponding to fields on the
1040
+ # request, apply these.
1041
+ if parent is not None:
1042
+ request.parent = parent
1043
+
1044
+ # Wrap the RPC method; this adds retry and timeout information,
1045
+ # and friendly error handling.
1046
+ rpc = self._transport._wrapped_methods[self._transport.list_permissions]
1047
+
1048
+ # Certain fields should be provided within the metadata header;
1049
+ # add these here.
1050
+ metadata = tuple(metadata) + (
1051
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
1052
+ )
1053
+
1054
+ # Validate the universe domain.
1055
+ self._validate_universe_domain()
1056
+
1057
+ # Send the request.
1058
+ response = rpc(
1059
+ request,
1060
+ retry=retry,
1061
+ timeout=timeout,
1062
+ metadata=metadata,
1063
+ )
1064
+
1065
+ # This method is paged; wrap the response in a pager, which provides
1066
+ # an `__iter__` convenience method.
1067
+ response = pagers.ListPermissionsPager(
1068
+ method=rpc,
1069
+ request=request,
1070
+ response=response,
1071
+ retry=retry,
1072
+ timeout=timeout,
1073
+ metadata=metadata,
1074
+ )
1075
+
1076
+ # Done; return the response.
1077
+ return response
1078
+
1079
+ def update_permission(
1080
+ self,
1081
+ request: Optional[
1082
+ Union[permission_service.UpdatePermissionRequest, dict]
1083
+ ] = None,
1084
+ *,
1085
+ permission: Optional[gag_permission.Permission] = None,
1086
+ update_mask: Optional[field_mask_pb2.FieldMask] = None,
1087
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1088
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1089
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1090
+ ) -> gag_permission.Permission:
1091
+ r"""Updates the permission.
1092
+
1093
+ .. code-block:: python
1094
+
1095
+ # This snippet has been automatically generated and should be regarded as a
1096
+ # code template only.
1097
+ # It will require modifications to work:
1098
+ # - It may require correct/in-range values for request initialization.
1099
+ # - It may require specifying regional endpoints when creating the service
1100
+ # client as shown in:
1101
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1102
+ from google.ai import generativelanguage_v1beta
1103
+
1104
+ def sample_update_permission():
1105
+ # Create a client
1106
+ client = generativelanguage_v1beta.PermissionServiceClient()
1107
+
1108
+ # Initialize request argument(s)
1109
+ request = generativelanguage_v1beta.UpdatePermissionRequest(
1110
+ )
1111
+
1112
+ # Make the request
1113
+ response = client.update_permission(request=request)
1114
+
1115
+ # Handle the response
1116
+ print(response)
1117
+
1118
+ Args:
1119
+ request (Union[google.ai.generativelanguage_v1beta.types.UpdatePermissionRequest, dict]):
1120
+ The request object. Request to update the ``Permission``.
1121
+ permission (google.ai.generativelanguage_v1beta.types.Permission):
1122
+ Required. The permission to update.
1123
+
1124
+ The permission's ``name`` field is used to identify the
1125
+ permission to update.
1126
+
1127
+ This corresponds to the ``permission`` field
1128
+ on the ``request`` instance; if ``request`` is provided, this
1129
+ should not be set.
1130
+ update_mask (google.protobuf.field_mask_pb2.FieldMask):
1131
+ Required. The list of fields to update. Accepted ones:
1132
+
1133
+ - role (``Permission.role`` field)
1134
+
1135
+ This corresponds to the ``update_mask`` field
1136
+ on the ``request`` instance; if ``request`` is provided, this
1137
+ should not be set.
1138
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1139
+ should be retried.
1140
+ timeout (float): The timeout for this request.
1141
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1142
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1143
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1144
+ be of type `bytes`.
1145
+
1146
+ Returns:
1147
+ google.ai.generativelanguage_v1beta.types.Permission:
1148
+ Permission resource grants user,
1149
+ group or the rest of the world access to
1150
+ the PaLM API resource (e.g. a tuned
1151
+ model, corpus).
1152
+
1153
+ A role is a collection of permitted
1154
+ operations that allows users to perform
1155
+ specific actions on PaLM API resources.
1156
+ To make them available to users, groups,
1157
+ or service accounts, you assign roles.
1158
+ When you assign a role, you grant
1159
+ permissions that the role contains.
1160
+
1161
+ There are three concentric roles. Each
1162
+ role is a superset of the previous
1163
+ role's permitted operations:
1164
+
1165
+ - reader can use the resource (e.g.
1166
+ tuned model, corpus) for inference
1167
+ - writer has reader's permissions and
1168
+ additionally can edit and share
1169
+ - owner has writer's permissions and
1170
+ additionally can delete
1171
+
1172
+ """
1173
+ # Create or coerce a protobuf request object.
1174
+ # - Quick check: If we got a request object, we should *not* have
1175
+ # gotten any keyword arguments that map to the request.
1176
+ has_flattened_params = any([permission, update_mask])
1177
+ if request is not None and has_flattened_params:
1178
+ raise ValueError(
1179
+ "If the `request` argument is set, then none of "
1180
+ "the individual field arguments should be set."
1181
+ )
1182
+
1183
+ # - Use the request object if provided (there's no risk of modifying the input as
1184
+ # there are no flattened fields), or create one.
1185
+ if not isinstance(request, permission_service.UpdatePermissionRequest):
1186
+ request = permission_service.UpdatePermissionRequest(request)
1187
+ # If we have keyword arguments corresponding to fields on the
1188
+ # request, apply these.
1189
+ if permission is not None:
1190
+ request.permission = permission
1191
+ if update_mask is not None:
1192
+ request.update_mask = update_mask
1193
+
1194
+ # Wrap the RPC method; this adds retry and timeout information,
1195
+ # and friendly error handling.
1196
+ rpc = self._transport._wrapped_methods[self._transport.update_permission]
1197
+
1198
+ # Certain fields should be provided within the metadata header;
1199
+ # add these here.
1200
+ metadata = tuple(metadata) + (
1201
+ gapic_v1.routing_header.to_grpc_metadata(
1202
+ (("permission.name", request.permission.name),)
1203
+ ),
1204
+ )
1205
+
1206
+ # Validate the universe domain.
1207
+ self._validate_universe_domain()
1208
+
1209
+ # Send the request.
1210
+ response = rpc(
1211
+ request,
1212
+ retry=retry,
1213
+ timeout=timeout,
1214
+ metadata=metadata,
1215
+ )
1216
+
1217
+ # Done; return the response.
1218
+ return response
1219
+
1220
+ def delete_permission(
1221
+ self,
1222
+ request: Optional[
1223
+ Union[permission_service.DeletePermissionRequest, dict]
1224
+ ] = None,
1225
+ *,
1226
+ name: Optional[str] = None,
1227
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1228
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1229
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1230
+ ) -> None:
1231
+ r"""Deletes the permission.
1232
+
1233
+ .. code-block:: python
1234
+
1235
+ # This snippet has been automatically generated and should be regarded as a
1236
+ # code template only.
1237
+ # It will require modifications to work:
1238
+ # - It may require correct/in-range values for request initialization.
1239
+ # - It may require specifying regional endpoints when creating the service
1240
+ # client as shown in:
1241
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1242
+ from google.ai import generativelanguage_v1beta
1243
+
1244
+ def sample_delete_permission():
1245
+ # Create a client
1246
+ client = generativelanguage_v1beta.PermissionServiceClient()
1247
+
1248
+ # Initialize request argument(s)
1249
+ request = generativelanguage_v1beta.DeletePermissionRequest(
1250
+ name="name_value",
1251
+ )
1252
+
1253
+ # Make the request
1254
+ client.delete_permission(request=request)
1255
+
1256
+ Args:
1257
+ request (Union[google.ai.generativelanguage_v1beta.types.DeletePermissionRequest, dict]):
1258
+ The request object. Request to delete the ``Permission``.
1259
+ name (str):
1260
+ Required. The resource name of the permission. Formats:
1261
+ ``tunedModels/{tuned_model}/permissions/{permission}``
1262
+ ``corpora/{corpus}/permissions/{permission}``
1263
+
1264
+ This corresponds to the ``name`` field
1265
+ on the ``request`` instance; if ``request`` is provided, this
1266
+ should not be set.
1267
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1268
+ should be retried.
1269
+ timeout (float): The timeout for this request.
1270
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1271
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1272
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1273
+ be of type `bytes`.
1274
+ """
1275
+ # Create or coerce a protobuf request object.
1276
+ # - Quick check: If we got a request object, we should *not* have
1277
+ # gotten any keyword arguments that map to the request.
1278
+ has_flattened_params = any([name])
1279
+ if request is not None and has_flattened_params:
1280
+ raise ValueError(
1281
+ "If the `request` argument is set, then none of "
1282
+ "the individual field arguments should be set."
1283
+ )
1284
+
1285
+ # - Use the request object if provided (there's no risk of modifying the input as
1286
+ # there are no flattened fields), or create one.
1287
+ if not isinstance(request, permission_service.DeletePermissionRequest):
1288
+ request = permission_service.DeletePermissionRequest(request)
1289
+ # If we have keyword arguments corresponding to fields on the
1290
+ # request, apply these.
1291
+ if name is not None:
1292
+ request.name = name
1293
+
1294
+ # Wrap the RPC method; this adds retry and timeout information,
1295
+ # and friendly error handling.
1296
+ rpc = self._transport._wrapped_methods[self._transport.delete_permission]
1297
+
1298
+ # Certain fields should be provided within the metadata header;
1299
+ # add these here.
1300
+ metadata = tuple(metadata) + (
1301
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1302
+ )
1303
+
1304
+ # Validate the universe domain.
1305
+ self._validate_universe_domain()
1306
+
1307
+ # Send the request.
1308
+ rpc(
1309
+ request,
1310
+ retry=retry,
1311
+ timeout=timeout,
1312
+ metadata=metadata,
1313
+ )
1314
+
1315
+ def transfer_ownership(
1316
+ self,
1317
+ request: Optional[
1318
+ Union[permission_service.TransferOwnershipRequest, dict]
1319
+ ] = None,
1320
+ *,
1321
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1322
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1323
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1324
+ ) -> permission_service.TransferOwnershipResponse:
1325
+ r"""Transfers ownership of the tuned model.
1326
+ This is the only way to change ownership of the tuned
1327
+ model. The current owner will be downgraded to writer
1328
+ role.
1329
+
1330
+ .. code-block:: python
1331
+
1332
+ # This snippet has been automatically generated and should be regarded as a
1333
+ # code template only.
1334
+ # It will require modifications to work:
1335
+ # - It may require correct/in-range values for request initialization.
1336
+ # - It may require specifying regional endpoints when creating the service
1337
+ # client as shown in:
1338
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1339
+ from google.ai import generativelanguage_v1beta
1340
+
1341
+ def sample_transfer_ownership():
1342
+ # Create a client
1343
+ client = generativelanguage_v1beta.PermissionServiceClient()
1344
+
1345
+ # Initialize request argument(s)
1346
+ request = generativelanguage_v1beta.TransferOwnershipRequest(
1347
+ name="name_value",
1348
+ email_address="email_address_value",
1349
+ )
1350
+
1351
+ # Make the request
1352
+ response = client.transfer_ownership(request=request)
1353
+
1354
+ # Handle the response
1355
+ print(response)
1356
+
1357
+ Args:
1358
+ request (Union[google.ai.generativelanguage_v1beta.types.TransferOwnershipRequest, dict]):
1359
+ The request object. Request to transfer the ownership of
1360
+ the tuned model.
1361
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1362
+ should be retried.
1363
+ timeout (float): The timeout for this request.
1364
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1365
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1366
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1367
+ be of type `bytes`.
1368
+
1369
+ Returns:
1370
+ google.ai.generativelanguage_v1beta.types.TransferOwnershipResponse:
1371
+ Response from TransferOwnership.
1372
+ """
1373
+ # Create or coerce a protobuf request object.
1374
+ # - Use the request object if provided (there's no risk of modifying the input as
1375
+ # there are no flattened fields), or create one.
1376
+ if not isinstance(request, permission_service.TransferOwnershipRequest):
1377
+ request = permission_service.TransferOwnershipRequest(request)
1378
+
1379
+ # Wrap the RPC method; this adds retry and timeout information,
1380
+ # and friendly error handling.
1381
+ rpc = self._transport._wrapped_methods[self._transport.transfer_ownership]
1382
+
1383
+ # Certain fields should be provided within the metadata header;
1384
+ # add these here.
1385
+ metadata = tuple(metadata) + (
1386
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1387
+ )
1388
+
1389
+ # Validate the universe domain.
1390
+ self._validate_universe_domain()
1391
+
1392
+ # Send the request.
1393
+ response = rpc(
1394
+ request,
1395
+ retry=retry,
1396
+ timeout=timeout,
1397
+ metadata=metadata,
1398
+ )
1399
+
1400
+ # Done; return the response.
1401
+ return response
1402
+
1403
+ def __enter__(self) -> "PermissionServiceClient":
1404
+ return self
1405
+
1406
+ def __exit__(self, type, value, traceback):
1407
+ """Releases underlying transport's resources.
1408
+
1409
+ .. warning::
1410
+ ONLY use as a context manager if the transport is NOT shared
1411
+ with other clients! Exiting the with block will CLOSE the transport
1412
+ and may cause errors in other clients!
1413
+ """
1414
+ self.transport.close()
1415
+
1416
+ def list_operations(
1417
+ self,
1418
+ request: Optional[operations_pb2.ListOperationsRequest] = None,
1419
+ *,
1420
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1421
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1422
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1423
+ ) -> operations_pb2.ListOperationsResponse:
1424
+ r"""Lists operations that match the specified filter in the request.
1425
+
1426
+ Args:
1427
+ request (:class:`~.operations_pb2.ListOperationsRequest`):
1428
+ The request object. Request message for
1429
+ `ListOperations` method.
1430
+ retry (google.api_core.retry.Retry): Designation of what errors,
1431
+ if any, should be retried.
1432
+ timeout (float): The timeout for this request.
1433
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1434
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1435
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1436
+ be of type `bytes`.
1437
+ Returns:
1438
+ ~.operations_pb2.ListOperationsResponse:
1439
+ Response message for ``ListOperations`` method.
1440
+ """
1441
+ # Create or coerce a protobuf request object.
1442
+ # The request isn't a proto-plus wrapped type,
1443
+ # so it must be constructed via keyword expansion.
1444
+ if isinstance(request, dict):
1445
+ request = operations_pb2.ListOperationsRequest(**request)
1446
+
1447
+ # Wrap the RPC method; this adds retry and timeout information,
1448
+ # and friendly error handling.
1449
+ rpc = self._transport._wrapped_methods[self._transport.list_operations]
1450
+
1451
+ # Certain fields should be provided within the metadata header;
1452
+ # add these here.
1453
+ metadata = tuple(metadata) + (
1454
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1455
+ )
1456
+
1457
+ # Validate the universe domain.
1458
+ self._validate_universe_domain()
1459
+
1460
+ # Send the request.
1461
+ response = rpc(
1462
+ request,
1463
+ retry=retry,
1464
+ timeout=timeout,
1465
+ metadata=metadata,
1466
+ )
1467
+
1468
+ # Done; return the response.
1469
+ return response
1470
+
1471
+ def get_operation(
1472
+ self,
1473
+ request: Optional[operations_pb2.GetOperationRequest] = None,
1474
+ *,
1475
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1476
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1477
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1478
+ ) -> operations_pb2.Operation:
1479
+ r"""Gets the latest state of a long-running operation.
1480
+
1481
+ Args:
1482
+ request (:class:`~.operations_pb2.GetOperationRequest`):
1483
+ The request object. Request message for
1484
+ `GetOperation` method.
1485
+ retry (google.api_core.retry.Retry): Designation of what errors,
1486
+ if any, should be retried.
1487
+ timeout (float): The timeout for this request.
1488
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1489
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1490
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1491
+ be of type `bytes`.
1492
+ Returns:
1493
+ ~.operations_pb2.Operation:
1494
+ An ``Operation`` object.
1495
+ """
1496
+ # Create or coerce a protobuf request object.
1497
+ # The request isn't a proto-plus wrapped type,
1498
+ # so it must be constructed via keyword expansion.
1499
+ if isinstance(request, dict):
1500
+ request = operations_pb2.GetOperationRequest(**request)
1501
+
1502
+ # Wrap the RPC method; this adds retry and timeout information,
1503
+ # and friendly error handling.
1504
+ rpc = self._transport._wrapped_methods[self._transport.get_operation]
1505
+
1506
+ # Certain fields should be provided within the metadata header;
1507
+ # add these here.
1508
+ metadata = tuple(metadata) + (
1509
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1510
+ )
1511
+
1512
+ # Validate the universe domain.
1513
+ self._validate_universe_domain()
1514
+
1515
+ # Send the request.
1516
+ response = rpc(
1517
+ request,
1518
+ retry=retry,
1519
+ timeout=timeout,
1520
+ metadata=metadata,
1521
+ )
1522
+
1523
+ # Done; return the response.
1524
+ return response
1525
+
1526
+
1527
+ DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
1528
+ gapic_version=package_version.__version__
1529
+ )
1530
+
1531
+
1532
+ __all__ = ("PermissionServiceClient",)
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/pagers.py ADDED
@@ -0,0 +1,197 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ from typing import (
17
+ Any,
18
+ AsyncIterator,
19
+ Awaitable,
20
+ Callable,
21
+ Iterator,
22
+ Optional,
23
+ Sequence,
24
+ Tuple,
25
+ Union,
26
+ )
27
+
28
+ from google.api_core import gapic_v1
29
+ from google.api_core import retry as retries
30
+ from google.api_core import retry_async as retries_async
31
+
32
+ try:
33
+ OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
34
+ OptionalAsyncRetry = Union[
35
+ retries_async.AsyncRetry, gapic_v1.method._MethodDefault, None
36
+ ]
37
+ except AttributeError: # pragma: NO COVER
38
+ OptionalRetry = Union[retries.Retry, object, None] # type: ignore
39
+ OptionalAsyncRetry = Union[retries_async.AsyncRetry, object, None] # type: ignore
40
+
41
+ from google.ai.generativelanguage_v1beta.types import permission, permission_service
42
+
43
+
44
+ class ListPermissionsPager:
45
+ """A pager for iterating through ``list_permissions`` requests.
46
+
47
+ This class thinly wraps an initial
48
+ :class:`google.ai.generativelanguage_v1beta.types.ListPermissionsResponse` object, and
49
+ provides an ``__iter__`` method to iterate through its
50
+ ``permissions`` field.
51
+
52
+ If there are more pages, the ``__iter__`` method will make additional
53
+ ``ListPermissions`` requests and continue to iterate
54
+ through the ``permissions`` field on the
55
+ corresponding responses.
56
+
57
+ All the usual :class:`google.ai.generativelanguage_v1beta.types.ListPermissionsResponse`
58
+ attributes are available on the pager. If multiple requests are made, only
59
+ the most recent response is retained, and thus used for attribute lookup.
60
+ """
61
+
62
+ def __init__(
63
+ self,
64
+ method: Callable[..., permission_service.ListPermissionsResponse],
65
+ request: permission_service.ListPermissionsRequest,
66
+ response: permission_service.ListPermissionsResponse,
67
+ *,
68
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
69
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
70
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
71
+ ):
72
+ """Instantiate the pager.
73
+
74
+ Args:
75
+ method (Callable): The method that was originally called, and
76
+ which instantiated this pager.
77
+ request (google.ai.generativelanguage_v1beta.types.ListPermissionsRequest):
78
+ The initial request object.
79
+ response (google.ai.generativelanguage_v1beta.types.ListPermissionsResponse):
80
+ The initial response object.
81
+ retry (google.api_core.retry.Retry): Designation of what errors,
82
+ if any, should be retried.
83
+ timeout (float): The timeout for this request.
84
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
85
+ sent along with the request as metadata. Normally, each value must be of type `str`,
86
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
87
+ be of type `bytes`.
88
+ """
89
+ self._method = method
90
+ self._request = permission_service.ListPermissionsRequest(request)
91
+ self._response = response
92
+ self._retry = retry
93
+ self._timeout = timeout
94
+ self._metadata = metadata
95
+
96
+ def __getattr__(self, name: str) -> Any:
97
+ return getattr(self._response, name)
98
+
99
+ @property
100
+ def pages(self) -> Iterator[permission_service.ListPermissionsResponse]:
101
+ yield self._response
102
+ while self._response.next_page_token:
103
+ self._request.page_token = self._response.next_page_token
104
+ self._response = self._method(
105
+ self._request,
106
+ retry=self._retry,
107
+ timeout=self._timeout,
108
+ metadata=self._metadata,
109
+ )
110
+ yield self._response
111
+
112
+ def __iter__(self) -> Iterator[permission.Permission]:
113
+ for page in self.pages:
114
+ yield from page.permissions
115
+
116
+ def __repr__(self) -> str:
117
+ return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
118
+
119
+
120
+ class ListPermissionsAsyncPager:
121
+ """A pager for iterating through ``list_permissions`` requests.
122
+
123
+ This class thinly wraps an initial
124
+ :class:`google.ai.generativelanguage_v1beta.types.ListPermissionsResponse` object, and
125
+ provides an ``__aiter__`` method to iterate through its
126
+ ``permissions`` field.
127
+
128
+ If there are more pages, the ``__aiter__`` method will make additional
129
+ ``ListPermissions`` requests and continue to iterate
130
+ through the ``permissions`` field on the
131
+ corresponding responses.
132
+
133
+ All the usual :class:`google.ai.generativelanguage_v1beta.types.ListPermissionsResponse`
134
+ attributes are available on the pager. If multiple requests are made, only
135
+ the most recent response is retained, and thus used for attribute lookup.
136
+ """
137
+
138
+ def __init__(
139
+ self,
140
+ method: Callable[..., Awaitable[permission_service.ListPermissionsResponse]],
141
+ request: permission_service.ListPermissionsRequest,
142
+ response: permission_service.ListPermissionsResponse,
143
+ *,
144
+ retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT,
145
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
146
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
147
+ ):
148
+ """Instantiates the pager.
149
+
150
+ Args:
151
+ method (Callable): The method that was originally called, and
152
+ which instantiated this pager.
153
+ request (google.ai.generativelanguage_v1beta.types.ListPermissionsRequest):
154
+ The initial request object.
155
+ response (google.ai.generativelanguage_v1beta.types.ListPermissionsResponse):
156
+ The initial response object.
157
+ retry (google.api_core.retry.AsyncRetry): Designation of what errors,
158
+ if any, should be retried.
159
+ timeout (float): The timeout for this request.
160
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
161
+ sent along with the request as metadata. Normally, each value must be of type `str`,
162
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
163
+ be of type `bytes`.
164
+ """
165
+ self._method = method
166
+ self._request = permission_service.ListPermissionsRequest(request)
167
+ self._response = response
168
+ self._retry = retry
169
+ self._timeout = timeout
170
+ self._metadata = metadata
171
+
172
+ def __getattr__(self, name: str) -> Any:
173
+ return getattr(self._response, name)
174
+
175
+ @property
176
+ async def pages(self) -> AsyncIterator[permission_service.ListPermissionsResponse]:
177
+ yield self._response
178
+ while self._response.next_page_token:
179
+ self._request.page_token = self._response.next_page_token
180
+ self._response = await self._method(
181
+ self._request,
182
+ retry=self._retry,
183
+ timeout=self._timeout,
184
+ metadata=self._metadata,
185
+ )
186
+ yield self._response
187
+
188
+ def __aiter__(self) -> AsyncIterator[permission.Permission]:
189
+ async def async_generator():
190
+ async for page in self.pages:
191
+ for response in page.permissions:
192
+ yield response
193
+
194
+ return async_generator()
195
+
196
+ def __repr__(self) -> str:
197
+ return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/transports/__init__.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ from collections import OrderedDict
17
+ from typing import Dict, Type
18
+
19
+ from .base import PermissionServiceTransport
20
+ from .grpc import PermissionServiceGrpcTransport
21
+ from .grpc_asyncio import PermissionServiceGrpcAsyncIOTransport
22
+ from .rest import PermissionServiceRestInterceptor, PermissionServiceRestTransport
23
+
24
+ # Compile a registry of transports.
25
+ _transport_registry = OrderedDict() # type: Dict[str, Type[PermissionServiceTransport]]
26
+ _transport_registry["grpc"] = PermissionServiceGrpcTransport
27
+ _transport_registry["grpc_asyncio"] = PermissionServiceGrpcAsyncIOTransport
28
+ _transport_registry["rest"] = PermissionServiceRestTransport
29
+
30
+ __all__ = (
31
+ "PermissionServiceTransport",
32
+ "PermissionServiceGrpcTransport",
33
+ "PermissionServiceGrpcAsyncIOTransport",
34
+ "PermissionServiceRestTransport",
35
+ "PermissionServiceRestInterceptor",
36
+ )
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/transports/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (925 Bytes). View file
 
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/transports/__pycache__/base.cpython-311.pyc ADDED
Binary file (11.8 kB). View file
 
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/transports/__pycache__/grpc.cpython-311.pyc ADDED
Binary file (23.4 kB). View file
 
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/transports/__pycache__/grpc_asyncio.cpython-311.pyc ADDED
Binary file (27.1 kB). View file
 
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/transports/__pycache__/rest.cpython-311.pyc ADDED
Binary file (63.1 kB). View file
 
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/transports/__pycache__/rest_base.cpython-311.pyc ADDED
Binary file (22.7 kB). View file
 
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/transports/base.py ADDED
@@ -0,0 +1,317 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ import abc
17
+ from typing import Awaitable, Callable, Dict, Optional, Sequence, Union
18
+
19
+ import google.api_core
20
+ from google.api_core import exceptions as core_exceptions
21
+ from google.api_core import gapic_v1
22
+ from google.api_core import retry as retries
23
+ import google.auth # type: ignore
24
+ from google.auth import credentials as ga_credentials # type: ignore
25
+ from google.longrunning import operations_pb2 # type: ignore
26
+ from google.oauth2 import service_account # type: ignore
27
+ from google.protobuf import empty_pb2 # type: ignore
28
+
29
+ from google.ai.generativelanguage_v1beta import gapic_version as package_version
30
+ from google.ai.generativelanguage_v1beta.types import permission as gag_permission
31
+ from google.ai.generativelanguage_v1beta.types import permission
32
+ from google.ai.generativelanguage_v1beta.types import permission_service
33
+
34
+ DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
35
+ gapic_version=package_version.__version__
36
+ )
37
+
38
+
39
+ class PermissionServiceTransport(abc.ABC):
40
+ """Abstract transport class for PermissionService."""
41
+
42
+ AUTH_SCOPES = ()
43
+
44
+ DEFAULT_HOST: str = "generativelanguage.googleapis.com"
45
+
46
+ def __init__(
47
+ self,
48
+ *,
49
+ host: str = DEFAULT_HOST,
50
+ credentials: Optional[ga_credentials.Credentials] = None,
51
+ credentials_file: Optional[str] = None,
52
+ scopes: Optional[Sequence[str]] = None,
53
+ quota_project_id: Optional[str] = None,
54
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
55
+ always_use_jwt_access: Optional[bool] = False,
56
+ api_audience: Optional[str] = None,
57
+ **kwargs,
58
+ ) -> None:
59
+ """Instantiate the transport.
60
+
61
+ Args:
62
+ host (Optional[str]):
63
+ The hostname to connect to (default: 'generativelanguage.googleapis.com').
64
+ credentials (Optional[google.auth.credentials.Credentials]): The
65
+ authorization credentials to attach to requests. These
66
+ credentials identify the application to the service; if none
67
+ are specified, the client will attempt to ascertain the
68
+ credentials from the environment.
69
+ credentials_file (Optional[str]): A file with credentials that can
70
+ be loaded with :func:`google.auth.load_credentials_from_file`.
71
+ This argument is mutually exclusive with credentials.
72
+ scopes (Optional[Sequence[str]]): A list of scopes.
73
+ quota_project_id (Optional[str]): An optional project to use for billing
74
+ and quota.
75
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
76
+ The client info used to send a user-agent string along with
77
+ API requests. If ``None``, then default info will be used.
78
+ Generally, you only need to set this if you're developing
79
+ your own client library.
80
+ always_use_jwt_access (Optional[bool]): Whether self signed JWT should
81
+ be used for service account credentials.
82
+ """
83
+
84
+ scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES}
85
+
86
+ # Save the scopes.
87
+ self._scopes = scopes
88
+ if not hasattr(self, "_ignore_credentials"):
89
+ self._ignore_credentials: bool = False
90
+
91
+ # If no credentials are provided, then determine the appropriate
92
+ # defaults.
93
+ if credentials and credentials_file:
94
+ raise core_exceptions.DuplicateCredentialArgs(
95
+ "'credentials_file' and 'credentials' are mutually exclusive"
96
+ )
97
+
98
+ if credentials_file is not None:
99
+ credentials, _ = google.auth.load_credentials_from_file(
100
+ credentials_file, **scopes_kwargs, quota_project_id=quota_project_id
101
+ )
102
+ elif credentials is None and not self._ignore_credentials:
103
+ credentials, _ = google.auth.default(
104
+ **scopes_kwargs, quota_project_id=quota_project_id
105
+ )
106
+ # Don't apply audience if the credentials file passed from user.
107
+ if hasattr(credentials, "with_gdch_audience"):
108
+ credentials = credentials.with_gdch_audience(
109
+ api_audience if api_audience else host
110
+ )
111
+
112
+ # If the credentials are service account credentials, then always try to use self signed JWT.
113
+ if (
114
+ always_use_jwt_access
115
+ and isinstance(credentials, service_account.Credentials)
116
+ and hasattr(service_account.Credentials, "with_always_use_jwt_access")
117
+ ):
118
+ credentials = credentials.with_always_use_jwt_access(True)
119
+
120
+ # Save the credentials.
121
+ self._credentials = credentials
122
+
123
+ # Save the hostname. Default to port 443 (HTTPS) if none is specified.
124
+ if ":" not in host:
125
+ host += ":443"
126
+ self._host = host
127
+
128
+ @property
129
+ def host(self):
130
+ return self._host
131
+
132
+ def _prep_wrapped_messages(self, client_info):
133
+ # Precompute the wrapped methods.
134
+ self._wrapped_methods = {
135
+ self.create_permission: gapic_v1.method.wrap_method(
136
+ self.create_permission,
137
+ default_retry=retries.Retry(
138
+ initial=1.0,
139
+ maximum=10.0,
140
+ multiplier=1.3,
141
+ predicate=retries.if_exception_type(
142
+ core_exceptions.ServiceUnavailable,
143
+ ),
144
+ deadline=60.0,
145
+ ),
146
+ default_timeout=60.0,
147
+ client_info=client_info,
148
+ ),
149
+ self.get_permission: gapic_v1.method.wrap_method(
150
+ self.get_permission,
151
+ default_retry=retries.Retry(
152
+ initial=1.0,
153
+ maximum=10.0,
154
+ multiplier=1.3,
155
+ predicate=retries.if_exception_type(
156
+ core_exceptions.ServiceUnavailable,
157
+ ),
158
+ deadline=60.0,
159
+ ),
160
+ default_timeout=60.0,
161
+ client_info=client_info,
162
+ ),
163
+ self.list_permissions: gapic_v1.method.wrap_method(
164
+ self.list_permissions,
165
+ default_timeout=None,
166
+ client_info=client_info,
167
+ ),
168
+ self.update_permission: gapic_v1.method.wrap_method(
169
+ self.update_permission,
170
+ default_retry=retries.Retry(
171
+ initial=1.0,
172
+ maximum=10.0,
173
+ multiplier=1.3,
174
+ predicate=retries.if_exception_type(
175
+ core_exceptions.ServiceUnavailable,
176
+ ),
177
+ deadline=60.0,
178
+ ),
179
+ default_timeout=60.0,
180
+ client_info=client_info,
181
+ ),
182
+ self.delete_permission: gapic_v1.method.wrap_method(
183
+ self.delete_permission,
184
+ default_retry=retries.Retry(
185
+ initial=1.0,
186
+ maximum=10.0,
187
+ multiplier=1.3,
188
+ predicate=retries.if_exception_type(
189
+ core_exceptions.ServiceUnavailable,
190
+ ),
191
+ deadline=60.0,
192
+ ),
193
+ default_timeout=60.0,
194
+ client_info=client_info,
195
+ ),
196
+ self.transfer_ownership: gapic_v1.method.wrap_method(
197
+ self.transfer_ownership,
198
+ default_retry=retries.Retry(
199
+ initial=1.0,
200
+ maximum=10.0,
201
+ multiplier=1.3,
202
+ predicate=retries.if_exception_type(
203
+ core_exceptions.ServiceUnavailable,
204
+ ),
205
+ deadline=60.0,
206
+ ),
207
+ default_timeout=60.0,
208
+ client_info=client_info,
209
+ ),
210
+ self.get_operation: gapic_v1.method.wrap_method(
211
+ self.get_operation,
212
+ default_timeout=None,
213
+ client_info=client_info,
214
+ ),
215
+ self.list_operations: gapic_v1.method.wrap_method(
216
+ self.list_operations,
217
+ default_timeout=None,
218
+ client_info=client_info,
219
+ ),
220
+ }
221
+
222
+ def close(self):
223
+ """Closes resources associated with the transport.
224
+
225
+ .. warning::
226
+ Only call this method if the transport is NOT shared
227
+ with other clients - this may cause errors in other clients!
228
+ """
229
+ raise NotImplementedError()
230
+
231
+ @property
232
+ def create_permission(
233
+ self,
234
+ ) -> Callable[
235
+ [permission_service.CreatePermissionRequest],
236
+ Union[gag_permission.Permission, Awaitable[gag_permission.Permission]],
237
+ ]:
238
+ raise NotImplementedError()
239
+
240
+ @property
241
+ def get_permission(
242
+ self,
243
+ ) -> Callable[
244
+ [permission_service.GetPermissionRequest],
245
+ Union[permission.Permission, Awaitable[permission.Permission]],
246
+ ]:
247
+ raise NotImplementedError()
248
+
249
+ @property
250
+ def list_permissions(
251
+ self,
252
+ ) -> Callable[
253
+ [permission_service.ListPermissionsRequest],
254
+ Union[
255
+ permission_service.ListPermissionsResponse,
256
+ Awaitable[permission_service.ListPermissionsResponse],
257
+ ],
258
+ ]:
259
+ raise NotImplementedError()
260
+
261
+ @property
262
+ def update_permission(
263
+ self,
264
+ ) -> Callable[
265
+ [permission_service.UpdatePermissionRequest],
266
+ Union[gag_permission.Permission, Awaitable[gag_permission.Permission]],
267
+ ]:
268
+ raise NotImplementedError()
269
+
270
+ @property
271
+ def delete_permission(
272
+ self,
273
+ ) -> Callable[
274
+ [permission_service.DeletePermissionRequest],
275
+ Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]],
276
+ ]:
277
+ raise NotImplementedError()
278
+
279
+ @property
280
+ def transfer_ownership(
281
+ self,
282
+ ) -> Callable[
283
+ [permission_service.TransferOwnershipRequest],
284
+ Union[
285
+ permission_service.TransferOwnershipResponse,
286
+ Awaitable[permission_service.TransferOwnershipResponse],
287
+ ],
288
+ ]:
289
+ raise NotImplementedError()
290
+
291
+ @property
292
+ def list_operations(
293
+ self,
294
+ ) -> Callable[
295
+ [operations_pb2.ListOperationsRequest],
296
+ Union[
297
+ operations_pb2.ListOperationsResponse,
298
+ Awaitable[operations_pb2.ListOperationsResponse],
299
+ ],
300
+ ]:
301
+ raise NotImplementedError()
302
+
303
+ @property
304
+ def get_operation(
305
+ self,
306
+ ) -> Callable[
307
+ [operations_pb2.GetOperationRequest],
308
+ Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]],
309
+ ]:
310
+ raise NotImplementedError()
311
+
312
+ @property
313
+ def kind(self) -> str:
314
+ raise NotImplementedError()
315
+
316
+
317
+ __all__ = ("PermissionServiceTransport",)
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/transports/grpc.py ADDED
@@ -0,0 +1,541 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ import json
17
+ import logging as std_logging
18
+ import pickle
19
+ from typing import Callable, Dict, Optional, Sequence, Tuple, Union
20
+ import warnings
21
+
22
+ from google.api_core import gapic_v1, grpc_helpers
23
+ import google.auth # type: ignore
24
+ from google.auth import credentials as ga_credentials # type: ignore
25
+ from google.auth.transport.grpc import SslCredentials # type: ignore
26
+ from google.longrunning import operations_pb2 # type: ignore
27
+ from google.protobuf import empty_pb2 # type: ignore
28
+ from google.protobuf.json_format import MessageToJson
29
+ import google.protobuf.message
30
+ import grpc # type: ignore
31
+ import proto # type: ignore
32
+
33
+ from google.ai.generativelanguage_v1beta.types import permission as gag_permission
34
+ from google.ai.generativelanguage_v1beta.types import permission
35
+ from google.ai.generativelanguage_v1beta.types import permission_service
36
+
37
+ from .base import DEFAULT_CLIENT_INFO, PermissionServiceTransport
38
+
39
+ try:
40
+ from google.api_core import client_logging # type: ignore
41
+
42
+ CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
43
+ except ImportError: # pragma: NO COVER
44
+ CLIENT_LOGGING_SUPPORTED = False
45
+
46
+ _LOGGER = std_logging.getLogger(__name__)
47
+
48
+
49
+ class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER
50
+ def intercept_unary_unary(self, continuation, client_call_details, request):
51
+ logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
52
+ std_logging.DEBUG
53
+ )
54
+ if logging_enabled: # pragma: NO COVER
55
+ request_metadata = client_call_details.metadata
56
+ if isinstance(request, proto.Message):
57
+ request_payload = type(request).to_json(request)
58
+ elif isinstance(request, google.protobuf.message.Message):
59
+ request_payload = MessageToJson(request)
60
+ else:
61
+ request_payload = f"{type(request).__name__}: {pickle.dumps(request)}"
62
+
63
+ request_metadata = {
64
+ key: value.decode("utf-8") if isinstance(value, bytes) else value
65
+ for key, value in request_metadata
66
+ }
67
+ grpc_request = {
68
+ "payload": request_payload,
69
+ "requestMethod": "grpc",
70
+ "metadata": dict(request_metadata),
71
+ }
72
+ _LOGGER.debug(
73
+ f"Sending request for {client_call_details.method}",
74
+ extra={
75
+ "serviceName": "google.ai.generativelanguage.v1beta.PermissionService",
76
+ "rpcName": client_call_details.method,
77
+ "request": grpc_request,
78
+ "metadata": grpc_request["metadata"],
79
+ },
80
+ )
81
+
82
+ response = continuation(client_call_details, request)
83
+ if logging_enabled: # pragma: NO COVER
84
+ response_metadata = response.trailing_metadata()
85
+ # Convert gRPC metadata `<class 'grpc.aio._metadata.Metadata'>` to list of tuples
86
+ metadata = (
87
+ dict([(k, str(v)) for k, v in response_metadata])
88
+ if response_metadata
89
+ else None
90
+ )
91
+ result = response.result()
92
+ if isinstance(result, proto.Message):
93
+ response_payload = type(result).to_json(result)
94
+ elif isinstance(result, google.protobuf.message.Message):
95
+ response_payload = MessageToJson(result)
96
+ else:
97
+ response_payload = f"{type(result).__name__}: {pickle.dumps(result)}"
98
+ grpc_response = {
99
+ "payload": response_payload,
100
+ "metadata": metadata,
101
+ "status": "OK",
102
+ }
103
+ _LOGGER.debug(
104
+ f"Received response for {client_call_details.method}.",
105
+ extra={
106
+ "serviceName": "google.ai.generativelanguage.v1beta.PermissionService",
107
+ "rpcName": client_call_details.method,
108
+ "response": grpc_response,
109
+ "metadata": grpc_response["metadata"],
110
+ },
111
+ )
112
+ return response
113
+
114
+
115
+ class PermissionServiceGrpcTransport(PermissionServiceTransport):
116
+ """gRPC backend transport for PermissionService.
117
+
118
+ Provides methods for managing permissions to PaLM API
119
+ resources.
120
+
121
+ This class defines the same methods as the primary client, so the
122
+ primary client can load the underlying transport implementation
123
+ and call it.
124
+
125
+ It sends protocol buffers over the wire using gRPC (which is built on
126
+ top of HTTP/2); the ``grpcio`` package must be installed.
127
+ """
128
+
129
+ _stubs: Dict[str, Callable]
130
+
131
+ def __init__(
132
+ self,
133
+ *,
134
+ host: str = "generativelanguage.googleapis.com",
135
+ credentials: Optional[ga_credentials.Credentials] = None,
136
+ credentials_file: Optional[str] = None,
137
+ scopes: Optional[Sequence[str]] = None,
138
+ channel: Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]] = None,
139
+ api_mtls_endpoint: Optional[str] = None,
140
+ client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
141
+ ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None,
142
+ client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
143
+ quota_project_id: Optional[str] = None,
144
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
145
+ always_use_jwt_access: Optional[bool] = False,
146
+ api_audience: Optional[str] = None,
147
+ ) -> None:
148
+ """Instantiate the transport.
149
+
150
+ Args:
151
+ host (Optional[str]):
152
+ The hostname to connect to (default: 'generativelanguage.googleapis.com').
153
+ credentials (Optional[google.auth.credentials.Credentials]): The
154
+ authorization credentials to attach to requests. These
155
+ credentials identify the application to the service; if none
156
+ are specified, the client will attempt to ascertain the
157
+ credentials from the environment.
158
+ This argument is ignored if a ``channel`` instance is provided.
159
+ credentials_file (Optional[str]): A file with credentials that can
160
+ be loaded with :func:`google.auth.load_credentials_from_file`.
161
+ This argument is ignored if a ``channel`` instance is provided.
162
+ scopes (Optional(Sequence[str])): A list of scopes. This argument is
163
+ ignored if a ``channel`` instance is provided.
164
+ channel (Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]]):
165
+ A ``Channel`` instance through which to make calls, or a Callable
166
+ that constructs and returns one. If set to None, ``self.create_channel``
167
+ is used to create the channel. If a Callable is given, it will be called
168
+ with the same arguments as used in ``self.create_channel``.
169
+ api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint.
170
+ If provided, it overrides the ``host`` argument and tries to create
171
+ a mutual TLS channel with client SSL credentials from
172
+ ``client_cert_source`` or application default SSL credentials.
173
+ client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]):
174
+ Deprecated. A callback to provide client SSL certificate bytes and
175
+ private key bytes, both in PEM format. It is ignored if
176
+ ``api_mtls_endpoint`` is None.
177
+ ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials
178
+ for the grpc channel. It is ignored if a ``channel`` instance is provided.
179
+ client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]):
180
+ A callback to provide client certificate bytes and private key bytes,
181
+ both in PEM format. It is used to configure a mutual TLS channel. It is
182
+ ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided.
183
+ quota_project_id (Optional[str]): An optional project to use for billing
184
+ and quota.
185
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
186
+ The client info used to send a user-agent string along with
187
+ API requests. If ``None``, then default info will be used.
188
+ Generally, you only need to set this if you're developing
189
+ your own client library.
190
+ always_use_jwt_access (Optional[bool]): Whether self signed JWT should
191
+ be used for service account credentials.
192
+
193
+ Raises:
194
+ google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
195
+ creation failed for any reason.
196
+ google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
197
+ and ``credentials_file`` are passed.
198
+ """
199
+ self._grpc_channel = None
200
+ self._ssl_channel_credentials = ssl_channel_credentials
201
+ self._stubs: Dict[str, Callable] = {}
202
+
203
+ if api_mtls_endpoint:
204
+ warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
205
+ if client_cert_source:
206
+ warnings.warn("client_cert_source is deprecated", DeprecationWarning)
207
+
208
+ if isinstance(channel, grpc.Channel):
209
+ # Ignore credentials if a channel was passed.
210
+ credentials = None
211
+ self._ignore_credentials = True
212
+ # If a channel was explicitly provided, set it.
213
+ self._grpc_channel = channel
214
+ self._ssl_channel_credentials = None
215
+
216
+ else:
217
+ if api_mtls_endpoint:
218
+ host = api_mtls_endpoint
219
+
220
+ # Create SSL credentials with client_cert_source or application
221
+ # default SSL credentials.
222
+ if client_cert_source:
223
+ cert, key = client_cert_source()
224
+ self._ssl_channel_credentials = grpc.ssl_channel_credentials(
225
+ certificate_chain=cert, private_key=key
226
+ )
227
+ else:
228
+ self._ssl_channel_credentials = SslCredentials().ssl_credentials
229
+
230
+ else:
231
+ if client_cert_source_for_mtls and not ssl_channel_credentials:
232
+ cert, key = client_cert_source_for_mtls()
233
+ self._ssl_channel_credentials = grpc.ssl_channel_credentials(
234
+ certificate_chain=cert, private_key=key
235
+ )
236
+
237
+ # The base transport sets the host, credentials and scopes
238
+ super().__init__(
239
+ host=host,
240
+ credentials=credentials,
241
+ credentials_file=credentials_file,
242
+ scopes=scopes,
243
+ quota_project_id=quota_project_id,
244
+ client_info=client_info,
245
+ always_use_jwt_access=always_use_jwt_access,
246
+ api_audience=api_audience,
247
+ )
248
+
249
+ if not self._grpc_channel:
250
+ # initialize with the provided callable or the default channel
251
+ channel_init = channel or type(self).create_channel
252
+ self._grpc_channel = channel_init(
253
+ self._host,
254
+ # use the credentials which are saved
255
+ credentials=self._credentials,
256
+ # Set ``credentials_file`` to ``None`` here as
257
+ # the credentials that we saved earlier should be used.
258
+ credentials_file=None,
259
+ scopes=self._scopes,
260
+ ssl_credentials=self._ssl_channel_credentials,
261
+ quota_project_id=quota_project_id,
262
+ options=[
263
+ ("grpc.max_send_message_length", -1),
264
+ ("grpc.max_receive_message_length", -1),
265
+ ],
266
+ )
267
+
268
+ self._interceptor = _LoggingClientInterceptor()
269
+ self._logged_channel = grpc.intercept_channel(
270
+ self._grpc_channel, self._interceptor
271
+ )
272
+
273
+ # Wrap messages. This must be done after self._logged_channel exists
274
+ self._prep_wrapped_messages(client_info)
275
+
276
+ @classmethod
277
+ def create_channel(
278
+ cls,
279
+ host: str = "generativelanguage.googleapis.com",
280
+ credentials: Optional[ga_credentials.Credentials] = None,
281
+ credentials_file: Optional[str] = None,
282
+ scopes: Optional[Sequence[str]] = None,
283
+ quota_project_id: Optional[str] = None,
284
+ **kwargs,
285
+ ) -> grpc.Channel:
286
+ """Create and return a gRPC channel object.
287
+ Args:
288
+ host (Optional[str]): The host for the channel to use.
289
+ credentials (Optional[~.Credentials]): The
290
+ authorization credentials to attach to requests. These
291
+ credentials identify this application to the service. If
292
+ none are specified, the client will attempt to ascertain
293
+ the credentials from the environment.
294
+ credentials_file (Optional[str]): A file with credentials that can
295
+ be loaded with :func:`google.auth.load_credentials_from_file`.
296
+ This argument is mutually exclusive with credentials.
297
+ scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
298
+ service. These are only used when credentials are not specified and
299
+ are passed to :func:`google.auth.default`.
300
+ quota_project_id (Optional[str]): An optional project to use for billing
301
+ and quota.
302
+ kwargs (Optional[dict]): Keyword arguments, which are passed to the
303
+ channel creation.
304
+ Returns:
305
+ grpc.Channel: A gRPC channel object.
306
+
307
+ Raises:
308
+ google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
309
+ and ``credentials_file`` are passed.
310
+ """
311
+
312
+ return grpc_helpers.create_channel(
313
+ host,
314
+ credentials=credentials,
315
+ credentials_file=credentials_file,
316
+ quota_project_id=quota_project_id,
317
+ default_scopes=cls.AUTH_SCOPES,
318
+ scopes=scopes,
319
+ default_host=cls.DEFAULT_HOST,
320
+ **kwargs,
321
+ )
322
+
323
+ @property
324
+ def grpc_channel(self) -> grpc.Channel:
325
+ """Return the channel designed to connect to this service."""
326
+ return self._grpc_channel
327
+
328
+ @property
329
+ def create_permission(
330
+ self,
331
+ ) -> Callable[
332
+ [permission_service.CreatePermissionRequest], gag_permission.Permission
333
+ ]:
334
+ r"""Return a callable for the create permission method over gRPC.
335
+
336
+ Create a permission to a specific resource.
337
+
338
+ Returns:
339
+ Callable[[~.CreatePermissionRequest],
340
+ ~.Permission]:
341
+ A function that, when called, will call the underlying RPC
342
+ on the server.
343
+ """
344
+ # Generate a "stub function" on-the-fly which will actually make
345
+ # the request.
346
+ # gRPC handles serialization and deserialization, so we just need
347
+ # to pass in the functions for each.
348
+ if "create_permission" not in self._stubs:
349
+ self._stubs["create_permission"] = self._logged_channel.unary_unary(
350
+ "/google.ai.generativelanguage.v1beta.PermissionService/CreatePermission",
351
+ request_serializer=permission_service.CreatePermissionRequest.serialize,
352
+ response_deserializer=gag_permission.Permission.deserialize,
353
+ )
354
+ return self._stubs["create_permission"]
355
+
356
+ @property
357
+ def get_permission(
358
+ self,
359
+ ) -> Callable[[permission_service.GetPermissionRequest], permission.Permission]:
360
+ r"""Return a callable for the get permission method over gRPC.
361
+
362
+ Gets information about a specific Permission.
363
+
364
+ Returns:
365
+ Callable[[~.GetPermissionRequest],
366
+ ~.Permission]:
367
+ A function that, when called, will call the underlying RPC
368
+ on the server.
369
+ """
370
+ # Generate a "stub function" on-the-fly which will actually make
371
+ # the request.
372
+ # gRPC handles serialization and deserialization, so we just need
373
+ # to pass in the functions for each.
374
+ if "get_permission" not in self._stubs:
375
+ self._stubs["get_permission"] = self._logged_channel.unary_unary(
376
+ "/google.ai.generativelanguage.v1beta.PermissionService/GetPermission",
377
+ request_serializer=permission_service.GetPermissionRequest.serialize,
378
+ response_deserializer=permission.Permission.deserialize,
379
+ )
380
+ return self._stubs["get_permission"]
381
+
382
+ @property
383
+ def list_permissions(
384
+ self,
385
+ ) -> Callable[
386
+ [permission_service.ListPermissionsRequest],
387
+ permission_service.ListPermissionsResponse,
388
+ ]:
389
+ r"""Return a callable for the list permissions method over gRPC.
390
+
391
+ Lists permissions for the specific resource.
392
+
393
+ Returns:
394
+ Callable[[~.ListPermissionsRequest],
395
+ ~.ListPermissionsResponse]:
396
+ A function that, when called, will call the underlying RPC
397
+ on the server.
398
+ """
399
+ # Generate a "stub function" on-the-fly which will actually make
400
+ # the request.
401
+ # gRPC handles serialization and deserialization, so we just need
402
+ # to pass in the functions for each.
403
+ if "list_permissions" not in self._stubs:
404
+ self._stubs["list_permissions"] = self._logged_channel.unary_unary(
405
+ "/google.ai.generativelanguage.v1beta.PermissionService/ListPermissions",
406
+ request_serializer=permission_service.ListPermissionsRequest.serialize,
407
+ response_deserializer=permission_service.ListPermissionsResponse.deserialize,
408
+ )
409
+ return self._stubs["list_permissions"]
410
+
411
+ @property
412
+ def update_permission(
413
+ self,
414
+ ) -> Callable[
415
+ [permission_service.UpdatePermissionRequest], gag_permission.Permission
416
+ ]:
417
+ r"""Return a callable for the update permission method over gRPC.
418
+
419
+ Updates the permission.
420
+
421
+ Returns:
422
+ Callable[[~.UpdatePermissionRequest],
423
+ ~.Permission]:
424
+ A function that, when called, will call the underlying RPC
425
+ on the server.
426
+ """
427
+ # Generate a "stub function" on-the-fly which will actually make
428
+ # the request.
429
+ # gRPC handles serialization and deserialization, so we just need
430
+ # to pass in the functions for each.
431
+ if "update_permission" not in self._stubs:
432
+ self._stubs["update_permission"] = self._logged_channel.unary_unary(
433
+ "/google.ai.generativelanguage.v1beta.PermissionService/UpdatePermission",
434
+ request_serializer=permission_service.UpdatePermissionRequest.serialize,
435
+ response_deserializer=gag_permission.Permission.deserialize,
436
+ )
437
+ return self._stubs["update_permission"]
438
+
439
+ @property
440
+ def delete_permission(
441
+ self,
442
+ ) -> Callable[[permission_service.DeletePermissionRequest], empty_pb2.Empty]:
443
+ r"""Return a callable for the delete permission method over gRPC.
444
+
445
+ Deletes the permission.
446
+
447
+ Returns:
448
+ Callable[[~.DeletePermissionRequest],
449
+ ~.Empty]:
450
+ A function that, when called, will call the underlying RPC
451
+ on the server.
452
+ """
453
+ # Generate a "stub function" on-the-fly which will actually make
454
+ # the request.
455
+ # gRPC handles serialization and deserialization, so we just need
456
+ # to pass in the functions for each.
457
+ if "delete_permission" not in self._stubs:
458
+ self._stubs["delete_permission"] = self._logged_channel.unary_unary(
459
+ "/google.ai.generativelanguage.v1beta.PermissionService/DeletePermission",
460
+ request_serializer=permission_service.DeletePermissionRequest.serialize,
461
+ response_deserializer=empty_pb2.Empty.FromString,
462
+ )
463
+ return self._stubs["delete_permission"]
464
+
465
+ @property
466
+ def transfer_ownership(
467
+ self,
468
+ ) -> Callable[
469
+ [permission_service.TransferOwnershipRequest],
470
+ permission_service.TransferOwnershipResponse,
471
+ ]:
472
+ r"""Return a callable for the transfer ownership method over gRPC.
473
+
474
+ Transfers ownership of the tuned model.
475
+ This is the only way to change ownership of the tuned
476
+ model. The current owner will be downgraded to writer
477
+ role.
478
+
479
+ Returns:
480
+ Callable[[~.TransferOwnershipRequest],
481
+ ~.TransferOwnershipResponse]:
482
+ A function that, when called, will call the underlying RPC
483
+ on the server.
484
+ """
485
+ # Generate a "stub function" on-the-fly which will actually make
486
+ # the request.
487
+ # gRPC handles serialization and deserialization, so we just need
488
+ # to pass in the functions for each.
489
+ if "transfer_ownership" not in self._stubs:
490
+ self._stubs["transfer_ownership"] = self._logged_channel.unary_unary(
491
+ "/google.ai.generativelanguage.v1beta.PermissionService/TransferOwnership",
492
+ request_serializer=permission_service.TransferOwnershipRequest.serialize,
493
+ response_deserializer=permission_service.TransferOwnershipResponse.deserialize,
494
+ )
495
+ return self._stubs["transfer_ownership"]
496
+
497
+ def close(self):
498
+ self._logged_channel.close()
499
+
500
+ @property
501
+ def get_operation(
502
+ self,
503
+ ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]:
504
+ r"""Return a callable for the get_operation method over gRPC."""
505
+ # Generate a "stub function" on-the-fly which will actually make
506
+ # the request.
507
+ # gRPC handles serialization and deserialization, so we just need
508
+ # to pass in the functions for each.
509
+ if "get_operation" not in self._stubs:
510
+ self._stubs["get_operation"] = self._logged_channel.unary_unary(
511
+ "/google.longrunning.Operations/GetOperation",
512
+ request_serializer=operations_pb2.GetOperationRequest.SerializeToString,
513
+ response_deserializer=operations_pb2.Operation.FromString,
514
+ )
515
+ return self._stubs["get_operation"]
516
+
517
+ @property
518
+ def list_operations(
519
+ self,
520
+ ) -> Callable[
521
+ [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse
522
+ ]:
523
+ r"""Return a callable for the list_operations method over gRPC."""
524
+ # Generate a "stub function" on-the-fly which will actually make
525
+ # the request.
526
+ # gRPC handles serialization and deserialization, so we just need
527
+ # to pass in the functions for each.
528
+ if "list_operations" not in self._stubs:
529
+ self._stubs["list_operations"] = self._logged_channel.unary_unary(
530
+ "/google.longrunning.Operations/ListOperations",
531
+ request_serializer=operations_pb2.ListOperationsRequest.SerializeToString,
532
+ response_deserializer=operations_pb2.ListOperationsResponse.FromString,
533
+ )
534
+ return self._stubs["list_operations"]
535
+
536
+ @property
537
+ def kind(self) -> str:
538
+ return "grpc"
539
+
540
+
541
+ __all__ = ("PermissionServiceGrpcTransport",)
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/transports/grpc_asyncio.py ADDED
@@ -0,0 +1,649 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ import inspect
17
+ import json
18
+ import logging as std_logging
19
+ import pickle
20
+ from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union
21
+ import warnings
22
+
23
+ from google.api_core import exceptions as core_exceptions
24
+ from google.api_core import gapic_v1, grpc_helpers_async
25
+ from google.api_core import retry_async as retries
26
+ from google.auth import credentials as ga_credentials # type: ignore
27
+ from google.auth.transport.grpc import SslCredentials # type: ignore
28
+ from google.longrunning import operations_pb2 # type: ignore
29
+ from google.protobuf import empty_pb2 # type: ignore
30
+ from google.protobuf.json_format import MessageToJson
31
+ import google.protobuf.message
32
+ import grpc # type: ignore
33
+ from grpc.experimental import aio # type: ignore
34
+ import proto # type: ignore
35
+
36
+ from google.ai.generativelanguage_v1beta.types import permission as gag_permission
37
+ from google.ai.generativelanguage_v1beta.types import permission
38
+ from google.ai.generativelanguage_v1beta.types import permission_service
39
+
40
+ from .base import DEFAULT_CLIENT_INFO, PermissionServiceTransport
41
+ from .grpc import PermissionServiceGrpcTransport
42
+
43
+ try:
44
+ from google.api_core import client_logging # type: ignore
45
+
46
+ CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
47
+ except ImportError: # pragma: NO COVER
48
+ CLIENT_LOGGING_SUPPORTED = False
49
+
50
+ _LOGGER = std_logging.getLogger(__name__)
51
+
52
+
53
+ class _LoggingClientAIOInterceptor(
54
+ grpc.aio.UnaryUnaryClientInterceptor
55
+ ): # pragma: NO COVER
56
+ async def intercept_unary_unary(self, continuation, client_call_details, request):
57
+ logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
58
+ std_logging.DEBUG
59
+ )
60
+ if logging_enabled: # pragma: NO COVER
61
+ request_metadata = client_call_details.metadata
62
+ if isinstance(request, proto.Message):
63
+ request_payload = type(request).to_json(request)
64
+ elif isinstance(request, google.protobuf.message.Message):
65
+ request_payload = MessageToJson(request)
66
+ else:
67
+ request_payload = f"{type(request).__name__}: {pickle.dumps(request)}"
68
+
69
+ request_metadata = {
70
+ key: value.decode("utf-8") if isinstance(value, bytes) else value
71
+ for key, value in request_metadata
72
+ }
73
+ grpc_request = {
74
+ "payload": request_payload,
75
+ "requestMethod": "grpc",
76
+ "metadata": dict(request_metadata),
77
+ }
78
+ _LOGGER.debug(
79
+ f"Sending request for {client_call_details.method}",
80
+ extra={
81
+ "serviceName": "google.ai.generativelanguage.v1beta.PermissionService",
82
+ "rpcName": str(client_call_details.method),
83
+ "request": grpc_request,
84
+ "metadata": grpc_request["metadata"],
85
+ },
86
+ )
87
+ response = await continuation(client_call_details, request)
88
+ if logging_enabled: # pragma: NO COVER
89
+ response_metadata = await response.trailing_metadata()
90
+ # Convert gRPC metadata `<class 'grpc.aio._metadata.Metadata'>` to list of tuples
91
+ metadata = (
92
+ dict([(k, str(v)) for k, v in response_metadata])
93
+ if response_metadata
94
+ else None
95
+ )
96
+ result = await response
97
+ if isinstance(result, proto.Message):
98
+ response_payload = type(result).to_json(result)
99
+ elif isinstance(result, google.protobuf.message.Message):
100
+ response_payload = MessageToJson(result)
101
+ else:
102
+ response_payload = f"{type(result).__name__}: {pickle.dumps(result)}"
103
+ grpc_response = {
104
+ "payload": response_payload,
105
+ "metadata": metadata,
106
+ "status": "OK",
107
+ }
108
+ _LOGGER.debug(
109
+ f"Received response to rpc {client_call_details.method}.",
110
+ extra={
111
+ "serviceName": "google.ai.generativelanguage.v1beta.PermissionService",
112
+ "rpcName": str(client_call_details.method),
113
+ "response": grpc_response,
114
+ "metadata": grpc_response["metadata"],
115
+ },
116
+ )
117
+ return response
118
+
119
+
120
+ class PermissionServiceGrpcAsyncIOTransport(PermissionServiceTransport):
121
+ """gRPC AsyncIO backend transport for PermissionService.
122
+
123
+ Provides methods for managing permissions to PaLM API
124
+ resources.
125
+
126
+ This class defines the same methods as the primary client, so the
127
+ primary client can load the underlying transport implementation
128
+ and call it.
129
+
130
+ It sends protocol buffers over the wire using gRPC (which is built on
131
+ top of HTTP/2); the ``grpcio`` package must be installed.
132
+ """
133
+
134
+ _grpc_channel: aio.Channel
135
+ _stubs: Dict[str, Callable] = {}
136
+
137
+ @classmethod
138
+ def create_channel(
139
+ cls,
140
+ host: str = "generativelanguage.googleapis.com",
141
+ credentials: Optional[ga_credentials.Credentials] = None,
142
+ credentials_file: Optional[str] = None,
143
+ scopes: Optional[Sequence[str]] = None,
144
+ quota_project_id: Optional[str] = None,
145
+ **kwargs,
146
+ ) -> aio.Channel:
147
+ """Create and return a gRPC AsyncIO channel object.
148
+ Args:
149
+ host (Optional[str]): The host for the channel to use.
150
+ credentials (Optional[~.Credentials]): The
151
+ authorization credentials to attach to requests. These
152
+ credentials identify this application to the service. If
153
+ none are specified, the client will attempt to ascertain
154
+ the credentials from the environment.
155
+ credentials_file (Optional[str]): A file with credentials that can
156
+ be loaded with :func:`google.auth.load_credentials_from_file`.
157
+ scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
158
+ service. These are only used when credentials are not specified and
159
+ are passed to :func:`google.auth.default`.
160
+ quota_project_id (Optional[str]): An optional project to use for billing
161
+ and quota.
162
+ kwargs (Optional[dict]): Keyword arguments, which are passed to the
163
+ channel creation.
164
+ Returns:
165
+ aio.Channel: A gRPC AsyncIO channel object.
166
+ """
167
+
168
+ return grpc_helpers_async.create_channel(
169
+ host,
170
+ credentials=credentials,
171
+ credentials_file=credentials_file,
172
+ quota_project_id=quota_project_id,
173
+ default_scopes=cls.AUTH_SCOPES,
174
+ scopes=scopes,
175
+ default_host=cls.DEFAULT_HOST,
176
+ **kwargs,
177
+ )
178
+
179
+ def __init__(
180
+ self,
181
+ *,
182
+ host: str = "generativelanguage.googleapis.com",
183
+ credentials: Optional[ga_credentials.Credentials] = None,
184
+ credentials_file: Optional[str] = None,
185
+ scopes: Optional[Sequence[str]] = None,
186
+ channel: Optional[Union[aio.Channel, Callable[..., aio.Channel]]] = None,
187
+ api_mtls_endpoint: Optional[str] = None,
188
+ client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
189
+ ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None,
190
+ client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
191
+ quota_project_id: Optional[str] = None,
192
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
193
+ always_use_jwt_access: Optional[bool] = False,
194
+ api_audience: Optional[str] = None,
195
+ ) -> None:
196
+ """Instantiate the transport.
197
+
198
+ Args:
199
+ host (Optional[str]):
200
+ The hostname to connect to (default: 'generativelanguage.googleapis.com').
201
+ credentials (Optional[google.auth.credentials.Credentials]): The
202
+ authorization credentials to attach to requests. These
203
+ credentials identify the application to the service; if none
204
+ are specified, the client will attempt to ascertain the
205
+ credentials from the environment.
206
+ This argument is ignored if a ``channel`` instance is provided.
207
+ credentials_file (Optional[str]): A file with credentials that can
208
+ be loaded with :func:`google.auth.load_credentials_from_file`.
209
+ This argument is ignored if a ``channel`` instance is provided.
210
+ scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
211
+ service. These are only used when credentials are not specified and
212
+ are passed to :func:`google.auth.default`.
213
+ channel (Optional[Union[aio.Channel, Callable[..., aio.Channel]]]):
214
+ A ``Channel`` instance through which to make calls, or a Callable
215
+ that constructs and returns one. If set to None, ``self.create_channel``
216
+ is used to create the channel. If a Callable is given, it will be called
217
+ with the same arguments as used in ``self.create_channel``.
218
+ api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint.
219
+ If provided, it overrides the ``host`` argument and tries to create
220
+ a mutual TLS channel with client SSL credentials from
221
+ ``client_cert_source`` or application default SSL credentials.
222
+ client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]):
223
+ Deprecated. A callback to provide client SSL certificate bytes and
224
+ private key bytes, both in PEM format. It is ignored if
225
+ ``api_mtls_endpoint`` is None.
226
+ ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials
227
+ for the grpc channel. It is ignored if a ``channel`` instance is provided.
228
+ client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]):
229
+ A callback to provide client certificate bytes and private key bytes,
230
+ both in PEM format. It is used to configure a mutual TLS channel. It is
231
+ ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided.
232
+ quota_project_id (Optional[str]): An optional project to use for billing
233
+ and quota.
234
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
235
+ The client info used to send a user-agent string along with
236
+ API requests. If ``None``, then default info will be used.
237
+ Generally, you only need to set this if you're developing
238
+ your own client library.
239
+ always_use_jwt_access (Optional[bool]): Whether self signed JWT should
240
+ be used for service account credentials.
241
+
242
+ Raises:
243
+ google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
244
+ creation failed for any reason.
245
+ google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
246
+ and ``credentials_file`` are passed.
247
+ """
248
+ self._grpc_channel = None
249
+ self._ssl_channel_credentials = ssl_channel_credentials
250
+ self._stubs: Dict[str, Callable] = {}
251
+
252
+ if api_mtls_endpoint:
253
+ warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
254
+ if client_cert_source:
255
+ warnings.warn("client_cert_source is deprecated", DeprecationWarning)
256
+
257
+ if isinstance(channel, aio.Channel):
258
+ # Ignore credentials if a channel was passed.
259
+ credentials = None
260
+ self._ignore_credentials = True
261
+ # If a channel was explicitly provided, set it.
262
+ self._grpc_channel = channel
263
+ self._ssl_channel_credentials = None
264
+ else:
265
+ if api_mtls_endpoint:
266
+ host = api_mtls_endpoint
267
+
268
+ # Create SSL credentials with client_cert_source or application
269
+ # default SSL credentials.
270
+ if client_cert_source:
271
+ cert, key = client_cert_source()
272
+ self._ssl_channel_credentials = grpc.ssl_channel_credentials(
273
+ certificate_chain=cert, private_key=key
274
+ )
275
+ else:
276
+ self._ssl_channel_credentials = SslCredentials().ssl_credentials
277
+
278
+ else:
279
+ if client_cert_source_for_mtls and not ssl_channel_credentials:
280
+ cert, key = client_cert_source_for_mtls()
281
+ self._ssl_channel_credentials = grpc.ssl_channel_credentials(
282
+ certificate_chain=cert, private_key=key
283
+ )
284
+
285
+ # The base transport sets the host, credentials and scopes
286
+ super().__init__(
287
+ host=host,
288
+ credentials=credentials,
289
+ credentials_file=credentials_file,
290
+ scopes=scopes,
291
+ quota_project_id=quota_project_id,
292
+ client_info=client_info,
293
+ always_use_jwt_access=always_use_jwt_access,
294
+ api_audience=api_audience,
295
+ )
296
+
297
+ if not self._grpc_channel:
298
+ # initialize with the provided callable or the default channel
299
+ channel_init = channel or type(self).create_channel
300
+ self._grpc_channel = channel_init(
301
+ self._host,
302
+ # use the credentials which are saved
303
+ credentials=self._credentials,
304
+ # Set ``credentials_file`` to ``None`` here as
305
+ # the credentials that we saved earlier should be used.
306
+ credentials_file=None,
307
+ scopes=self._scopes,
308
+ ssl_credentials=self._ssl_channel_credentials,
309
+ quota_project_id=quota_project_id,
310
+ options=[
311
+ ("grpc.max_send_message_length", -1),
312
+ ("grpc.max_receive_message_length", -1),
313
+ ],
314
+ )
315
+
316
+ self._interceptor = _LoggingClientAIOInterceptor()
317
+ self._grpc_channel._unary_unary_interceptors.append(self._interceptor)
318
+ self._logged_channel = self._grpc_channel
319
+ self._wrap_with_kind = (
320
+ "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters
321
+ )
322
+ # Wrap messages. This must be done after self._logged_channel exists
323
+ self._prep_wrapped_messages(client_info)
324
+
325
+ @property
326
+ def grpc_channel(self) -> aio.Channel:
327
+ """Create the channel designed to connect to this service.
328
+
329
+ This property caches on the instance; repeated calls return
330
+ the same channel.
331
+ """
332
+ # Return the channel from cache.
333
+ return self._grpc_channel
334
+
335
+ @property
336
+ def create_permission(
337
+ self,
338
+ ) -> Callable[
339
+ [permission_service.CreatePermissionRequest],
340
+ Awaitable[gag_permission.Permission],
341
+ ]:
342
+ r"""Return a callable for the create permission method over gRPC.
343
+
344
+ Create a permission to a specific resource.
345
+
346
+ Returns:
347
+ Callable[[~.CreatePermissionRequest],
348
+ Awaitable[~.Permission]]:
349
+ A function that, when called, will call the underlying RPC
350
+ on the server.
351
+ """
352
+ # Generate a "stub function" on-the-fly which will actually make
353
+ # the request.
354
+ # gRPC handles serialization and deserialization, so we just need
355
+ # to pass in the functions for each.
356
+ if "create_permission" not in self._stubs:
357
+ self._stubs["create_permission"] = self._logged_channel.unary_unary(
358
+ "/google.ai.generativelanguage.v1beta.PermissionService/CreatePermission",
359
+ request_serializer=permission_service.CreatePermissionRequest.serialize,
360
+ response_deserializer=gag_permission.Permission.deserialize,
361
+ )
362
+ return self._stubs["create_permission"]
363
+
364
+ @property
365
+ def get_permission(
366
+ self,
367
+ ) -> Callable[
368
+ [permission_service.GetPermissionRequest], Awaitable[permission.Permission]
369
+ ]:
370
+ r"""Return a callable for the get permission method over gRPC.
371
+
372
+ Gets information about a specific Permission.
373
+
374
+ Returns:
375
+ Callable[[~.GetPermissionRequest],
376
+ Awaitable[~.Permission]]:
377
+ A function that, when called, will call the underlying RPC
378
+ on the server.
379
+ """
380
+ # Generate a "stub function" on-the-fly which will actually make
381
+ # the request.
382
+ # gRPC handles serialization and deserialization, so we just need
383
+ # to pass in the functions for each.
384
+ if "get_permission" not in self._stubs:
385
+ self._stubs["get_permission"] = self._logged_channel.unary_unary(
386
+ "/google.ai.generativelanguage.v1beta.PermissionService/GetPermission",
387
+ request_serializer=permission_service.GetPermissionRequest.serialize,
388
+ response_deserializer=permission.Permission.deserialize,
389
+ )
390
+ return self._stubs["get_permission"]
391
+
392
+ @property
393
+ def list_permissions(
394
+ self,
395
+ ) -> Callable[
396
+ [permission_service.ListPermissionsRequest],
397
+ Awaitable[permission_service.ListPermissionsResponse],
398
+ ]:
399
+ r"""Return a callable for the list permissions method over gRPC.
400
+
401
+ Lists permissions for the specific resource.
402
+
403
+ Returns:
404
+ Callable[[~.ListPermissionsRequest],
405
+ Awaitable[~.ListPermissionsResponse]]:
406
+ A function that, when called, will call the underlying RPC
407
+ on the server.
408
+ """
409
+ # Generate a "stub function" on-the-fly which will actually make
410
+ # the request.
411
+ # gRPC handles serialization and deserialization, so we just need
412
+ # to pass in the functions for each.
413
+ if "list_permissions" not in self._stubs:
414
+ self._stubs["list_permissions"] = self._logged_channel.unary_unary(
415
+ "/google.ai.generativelanguage.v1beta.PermissionService/ListPermissions",
416
+ request_serializer=permission_service.ListPermissionsRequest.serialize,
417
+ response_deserializer=permission_service.ListPermissionsResponse.deserialize,
418
+ )
419
+ return self._stubs["list_permissions"]
420
+
421
+ @property
422
+ def update_permission(
423
+ self,
424
+ ) -> Callable[
425
+ [permission_service.UpdatePermissionRequest],
426
+ Awaitable[gag_permission.Permission],
427
+ ]:
428
+ r"""Return a callable for the update permission method over gRPC.
429
+
430
+ Updates the permission.
431
+
432
+ Returns:
433
+ Callable[[~.UpdatePermissionRequest],
434
+ Awaitable[~.Permission]]:
435
+ A function that, when called, will call the underlying RPC
436
+ on the server.
437
+ """
438
+ # Generate a "stub function" on-the-fly which will actually make
439
+ # the request.
440
+ # gRPC handles serialization and deserialization, so we just need
441
+ # to pass in the functions for each.
442
+ if "update_permission" not in self._stubs:
443
+ self._stubs["update_permission"] = self._logged_channel.unary_unary(
444
+ "/google.ai.generativelanguage.v1beta.PermissionService/UpdatePermission",
445
+ request_serializer=permission_service.UpdatePermissionRequest.serialize,
446
+ response_deserializer=gag_permission.Permission.deserialize,
447
+ )
448
+ return self._stubs["update_permission"]
449
+
450
+ @property
451
+ def delete_permission(
452
+ self,
453
+ ) -> Callable[
454
+ [permission_service.DeletePermissionRequest], Awaitable[empty_pb2.Empty]
455
+ ]:
456
+ r"""Return a callable for the delete permission method over gRPC.
457
+
458
+ Deletes the permission.
459
+
460
+ Returns:
461
+ Callable[[~.DeletePermissionRequest],
462
+ Awaitable[~.Empty]]:
463
+ A function that, when called, will call the underlying RPC
464
+ on the server.
465
+ """
466
+ # Generate a "stub function" on-the-fly which will actually make
467
+ # the request.
468
+ # gRPC handles serialization and deserialization, so we just need
469
+ # to pass in the functions for each.
470
+ if "delete_permission" not in self._stubs:
471
+ self._stubs["delete_permission"] = self._logged_channel.unary_unary(
472
+ "/google.ai.generativelanguage.v1beta.PermissionService/DeletePermission",
473
+ request_serializer=permission_service.DeletePermissionRequest.serialize,
474
+ response_deserializer=empty_pb2.Empty.FromString,
475
+ )
476
+ return self._stubs["delete_permission"]
477
+
478
+ @property
479
+ def transfer_ownership(
480
+ self,
481
+ ) -> Callable[
482
+ [permission_service.TransferOwnershipRequest],
483
+ Awaitable[permission_service.TransferOwnershipResponse],
484
+ ]:
485
+ r"""Return a callable for the transfer ownership method over gRPC.
486
+
487
+ Transfers ownership of the tuned model.
488
+ This is the only way to change ownership of the tuned
489
+ model. The current owner will be downgraded to writer
490
+ role.
491
+
492
+ Returns:
493
+ Callable[[~.TransferOwnershipRequest],
494
+ Awaitable[~.TransferOwnershipResponse]]:
495
+ A function that, when called, will call the underlying RPC
496
+ on the server.
497
+ """
498
+ # Generate a "stub function" on-the-fly which will actually make
499
+ # the request.
500
+ # gRPC handles serialization and deserialization, so we just need
501
+ # to pass in the functions for each.
502
+ if "transfer_ownership" not in self._stubs:
503
+ self._stubs["transfer_ownership"] = self._logged_channel.unary_unary(
504
+ "/google.ai.generativelanguage.v1beta.PermissionService/TransferOwnership",
505
+ request_serializer=permission_service.TransferOwnershipRequest.serialize,
506
+ response_deserializer=permission_service.TransferOwnershipResponse.deserialize,
507
+ )
508
+ return self._stubs["transfer_ownership"]
509
+
510
+ def _prep_wrapped_messages(self, client_info):
511
+ """Precompute the wrapped methods, overriding the base class method to use async wrappers."""
512
+ self._wrapped_methods = {
513
+ self.create_permission: self._wrap_method(
514
+ self.create_permission,
515
+ default_retry=retries.AsyncRetry(
516
+ initial=1.0,
517
+ maximum=10.0,
518
+ multiplier=1.3,
519
+ predicate=retries.if_exception_type(
520
+ core_exceptions.ServiceUnavailable,
521
+ ),
522
+ deadline=60.0,
523
+ ),
524
+ default_timeout=60.0,
525
+ client_info=client_info,
526
+ ),
527
+ self.get_permission: self._wrap_method(
528
+ self.get_permission,
529
+ default_retry=retries.AsyncRetry(
530
+ initial=1.0,
531
+ maximum=10.0,
532
+ multiplier=1.3,
533
+ predicate=retries.if_exception_type(
534
+ core_exceptions.ServiceUnavailable,
535
+ ),
536
+ deadline=60.0,
537
+ ),
538
+ default_timeout=60.0,
539
+ client_info=client_info,
540
+ ),
541
+ self.list_permissions: self._wrap_method(
542
+ self.list_permissions,
543
+ default_timeout=None,
544
+ client_info=client_info,
545
+ ),
546
+ self.update_permission: self._wrap_method(
547
+ self.update_permission,
548
+ default_retry=retries.AsyncRetry(
549
+ initial=1.0,
550
+ maximum=10.0,
551
+ multiplier=1.3,
552
+ predicate=retries.if_exception_type(
553
+ core_exceptions.ServiceUnavailable,
554
+ ),
555
+ deadline=60.0,
556
+ ),
557
+ default_timeout=60.0,
558
+ client_info=client_info,
559
+ ),
560
+ self.delete_permission: self._wrap_method(
561
+ self.delete_permission,
562
+ default_retry=retries.AsyncRetry(
563
+ initial=1.0,
564
+ maximum=10.0,
565
+ multiplier=1.3,
566
+ predicate=retries.if_exception_type(
567
+ core_exceptions.ServiceUnavailable,
568
+ ),
569
+ deadline=60.0,
570
+ ),
571
+ default_timeout=60.0,
572
+ client_info=client_info,
573
+ ),
574
+ self.transfer_ownership: self._wrap_method(
575
+ self.transfer_ownership,
576
+ default_retry=retries.AsyncRetry(
577
+ initial=1.0,
578
+ maximum=10.0,
579
+ multiplier=1.3,
580
+ predicate=retries.if_exception_type(
581
+ core_exceptions.ServiceUnavailable,
582
+ ),
583
+ deadline=60.0,
584
+ ),
585
+ default_timeout=60.0,
586
+ client_info=client_info,
587
+ ),
588
+ self.get_operation: self._wrap_method(
589
+ self.get_operation,
590
+ default_timeout=None,
591
+ client_info=client_info,
592
+ ),
593
+ self.list_operations: self._wrap_method(
594
+ self.list_operations,
595
+ default_timeout=None,
596
+ client_info=client_info,
597
+ ),
598
+ }
599
+
600
+ def _wrap_method(self, func, *args, **kwargs):
601
+ if self._wrap_with_kind: # pragma: NO COVER
602
+ kwargs["kind"] = self.kind
603
+ return gapic_v1.method_async.wrap_method(func, *args, **kwargs)
604
+
605
+ def close(self):
606
+ return self._logged_channel.close()
607
+
608
+ @property
609
+ def kind(self) -> str:
610
+ return "grpc_asyncio"
611
+
612
+ @property
613
+ def get_operation(
614
+ self,
615
+ ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]:
616
+ r"""Return a callable for the get_operation method over gRPC."""
617
+ # Generate a "stub function" on-the-fly which will actually make
618
+ # the request.
619
+ # gRPC handles serialization and deserialization, so we just need
620
+ # to pass in the functions for each.
621
+ if "get_operation" not in self._stubs:
622
+ self._stubs["get_operation"] = self._logged_channel.unary_unary(
623
+ "/google.longrunning.Operations/GetOperation",
624
+ request_serializer=operations_pb2.GetOperationRequest.SerializeToString,
625
+ response_deserializer=operations_pb2.Operation.FromString,
626
+ )
627
+ return self._stubs["get_operation"]
628
+
629
+ @property
630
+ def list_operations(
631
+ self,
632
+ ) -> Callable[
633
+ [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse
634
+ ]:
635
+ r"""Return a callable for the list_operations method over gRPC."""
636
+ # Generate a "stub function" on-the-fly which will actually make
637
+ # the request.
638
+ # gRPC handles serialization and deserialization, so we just need
639
+ # to pass in the functions for each.
640
+ if "list_operations" not in self._stubs:
641
+ self._stubs["list_operations"] = self._logged_channel.unary_unary(
642
+ "/google.longrunning.Operations/ListOperations",
643
+ request_serializer=operations_pb2.ListOperationsRequest.SerializeToString,
644
+ response_deserializer=operations_pb2.ListOperationsResponse.FromString,
645
+ )
646
+ return self._stubs["list_operations"]
647
+
648
+
649
+ __all__ = ("PermissionServiceGrpcAsyncIOTransport",)
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/transports/rest.py ADDED
@@ -0,0 +1,1671 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ import dataclasses
17
+ import json # type: ignore
18
+ import logging
19
+ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
20
+ import warnings
21
+
22
+ from google.api_core import exceptions as core_exceptions
23
+ from google.api_core import gapic_v1, rest_helpers, rest_streaming
24
+ from google.api_core import retry as retries
25
+ from google.auth import credentials as ga_credentials # type: ignore
26
+ from google.auth.transport.requests import AuthorizedSession # type: ignore
27
+ from google.longrunning import operations_pb2 # type: ignore
28
+ from google.protobuf import empty_pb2 # type: ignore
29
+ from google.protobuf import json_format
30
+ from requests import __version__ as requests_version
31
+
32
+ from google.ai.generativelanguage_v1beta.types import permission as gag_permission
33
+ from google.ai.generativelanguage_v1beta.types import permission
34
+ from google.ai.generativelanguage_v1beta.types import permission_service
35
+
36
+ from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO
37
+ from .rest_base import _BasePermissionServiceRestTransport
38
+
39
+ try:
40
+ OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
41
+ except AttributeError: # pragma: NO COVER
42
+ OptionalRetry = Union[retries.Retry, object, None] # type: ignore
43
+
44
+ try:
45
+ from google.api_core import client_logging # type: ignore
46
+
47
+ CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
48
+ except ImportError: # pragma: NO COVER
49
+ CLIENT_LOGGING_SUPPORTED = False
50
+
51
+ _LOGGER = logging.getLogger(__name__)
52
+
53
+ DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
54
+ gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version,
55
+ grpc_version=None,
56
+ rest_version=f"requests@{requests_version}",
57
+ )
58
+
59
+
60
+ class PermissionServiceRestInterceptor:
61
+ """Interceptor for PermissionService.
62
+
63
+ Interceptors are used to manipulate requests, request metadata, and responses
64
+ in arbitrary ways.
65
+ Example use cases include:
66
+ * Logging
67
+ * Verifying requests according to service or custom semantics
68
+ * Stripping extraneous information from responses
69
+
70
+ These use cases and more can be enabled by injecting an
71
+ instance of a custom subclass when constructing the PermissionServiceRestTransport.
72
+
73
+ .. code-block:: python
74
+ class MyCustomPermissionServiceInterceptor(PermissionServiceRestInterceptor):
75
+ def pre_create_permission(self, request, metadata):
76
+ logging.log(f"Received request: {request}")
77
+ return request, metadata
78
+
79
+ def post_create_permission(self, response):
80
+ logging.log(f"Received response: {response}")
81
+ return response
82
+
83
+ def pre_delete_permission(self, request, metadata):
84
+ logging.log(f"Received request: {request}")
85
+ return request, metadata
86
+
87
+ def pre_get_permission(self, request, metadata):
88
+ logging.log(f"Received request: {request}")
89
+ return request, metadata
90
+
91
+ def post_get_permission(self, response):
92
+ logging.log(f"Received response: {response}")
93
+ return response
94
+
95
+ def pre_list_permissions(self, request, metadata):
96
+ logging.log(f"Received request: {request}")
97
+ return request, metadata
98
+
99
+ def post_list_permissions(self, response):
100
+ logging.log(f"Received response: {response}")
101
+ return response
102
+
103
+ def pre_transfer_ownership(self, request, metadata):
104
+ logging.log(f"Received request: {request}")
105
+ return request, metadata
106
+
107
+ def post_transfer_ownership(self, response):
108
+ logging.log(f"Received response: {response}")
109
+ return response
110
+
111
+ def pre_update_permission(self, request, metadata):
112
+ logging.log(f"Received request: {request}")
113
+ return request, metadata
114
+
115
+ def post_update_permission(self, response):
116
+ logging.log(f"Received response: {response}")
117
+ return response
118
+
119
+ transport = PermissionServiceRestTransport(interceptor=MyCustomPermissionServiceInterceptor())
120
+ client = PermissionServiceClient(transport=transport)
121
+
122
+
123
+ """
124
+
125
+ def pre_create_permission(
126
+ self,
127
+ request: permission_service.CreatePermissionRequest,
128
+ metadata: Sequence[Tuple[str, Union[str, bytes]]],
129
+ ) -> Tuple[
130
+ permission_service.CreatePermissionRequest,
131
+ Sequence[Tuple[str, Union[str, bytes]]],
132
+ ]:
133
+ """Pre-rpc interceptor for create_permission
134
+
135
+ Override in a subclass to manipulate the request or metadata
136
+ before they are sent to the PermissionService server.
137
+ """
138
+ return request, metadata
139
+
140
+ def post_create_permission(
141
+ self, response: gag_permission.Permission
142
+ ) -> gag_permission.Permission:
143
+ """Post-rpc interceptor for create_permission
144
+
145
+ Override in a subclass to manipulate the response
146
+ after it is returned by the PermissionService server but before
147
+ it is returned to user code.
148
+ """
149
+ return response
150
+
151
+ def pre_delete_permission(
152
+ self,
153
+ request: permission_service.DeletePermissionRequest,
154
+ metadata: Sequence[Tuple[str, Union[str, bytes]]],
155
+ ) -> Tuple[
156
+ permission_service.DeletePermissionRequest,
157
+ Sequence[Tuple[str, Union[str, bytes]]],
158
+ ]:
159
+ """Pre-rpc interceptor for delete_permission
160
+
161
+ Override in a subclass to manipulate the request or metadata
162
+ before they are sent to the PermissionService server.
163
+ """
164
+ return request, metadata
165
+
166
+ def pre_get_permission(
167
+ self,
168
+ request: permission_service.GetPermissionRequest,
169
+ metadata: Sequence[Tuple[str, Union[str, bytes]]],
170
+ ) -> Tuple[
171
+ permission_service.GetPermissionRequest, Sequence[Tuple[str, Union[str, bytes]]]
172
+ ]:
173
+ """Pre-rpc interceptor for get_permission
174
+
175
+ Override in a subclass to manipulate the request or metadata
176
+ before they are sent to the PermissionService server.
177
+ """
178
+ return request, metadata
179
+
180
+ def post_get_permission(
181
+ self, response: permission.Permission
182
+ ) -> permission.Permission:
183
+ """Post-rpc interceptor for get_permission
184
+
185
+ Override in a subclass to manipulate the response
186
+ after it is returned by the PermissionService server but before
187
+ it is returned to user code.
188
+ """
189
+ return response
190
+
191
+ def pre_list_permissions(
192
+ self,
193
+ request: permission_service.ListPermissionsRequest,
194
+ metadata: Sequence[Tuple[str, Union[str, bytes]]],
195
+ ) -> Tuple[
196
+ permission_service.ListPermissionsRequest,
197
+ Sequence[Tuple[str, Union[str, bytes]]],
198
+ ]:
199
+ """Pre-rpc interceptor for list_permissions
200
+
201
+ Override in a subclass to manipulate the request or metadata
202
+ before they are sent to the PermissionService server.
203
+ """
204
+ return request, metadata
205
+
206
+ def post_list_permissions(
207
+ self, response: permission_service.ListPermissionsResponse
208
+ ) -> permission_service.ListPermissionsResponse:
209
+ """Post-rpc interceptor for list_permissions
210
+
211
+ Override in a subclass to manipulate the response
212
+ after it is returned by the PermissionService server but before
213
+ it is returned to user code.
214
+ """
215
+ return response
216
+
217
+ def pre_transfer_ownership(
218
+ self,
219
+ request: permission_service.TransferOwnershipRequest,
220
+ metadata: Sequence[Tuple[str, Union[str, bytes]]],
221
+ ) -> Tuple[
222
+ permission_service.TransferOwnershipRequest,
223
+ Sequence[Tuple[str, Union[str, bytes]]],
224
+ ]:
225
+ """Pre-rpc interceptor for transfer_ownership
226
+
227
+ Override in a subclass to manipulate the request or metadata
228
+ before they are sent to the PermissionService server.
229
+ """
230
+ return request, metadata
231
+
232
+ def post_transfer_ownership(
233
+ self, response: permission_service.TransferOwnershipResponse
234
+ ) -> permission_service.TransferOwnershipResponse:
235
+ """Post-rpc interceptor for transfer_ownership
236
+
237
+ Override in a subclass to manipulate the response
238
+ after it is returned by the PermissionService server but before
239
+ it is returned to user code.
240
+ """
241
+ return response
242
+
243
+ def pre_update_permission(
244
+ self,
245
+ request: permission_service.UpdatePermissionRequest,
246
+ metadata: Sequence[Tuple[str, Union[str, bytes]]],
247
+ ) -> Tuple[
248
+ permission_service.UpdatePermissionRequest,
249
+ Sequence[Tuple[str, Union[str, bytes]]],
250
+ ]:
251
+ """Pre-rpc interceptor for update_permission
252
+
253
+ Override in a subclass to manipulate the request or metadata
254
+ before they are sent to the PermissionService server.
255
+ """
256
+ return request, metadata
257
+
258
+ def post_update_permission(
259
+ self, response: gag_permission.Permission
260
+ ) -> gag_permission.Permission:
261
+ """Post-rpc interceptor for update_permission
262
+
263
+ Override in a subclass to manipulate the response
264
+ after it is returned by the PermissionService server but before
265
+ it is returned to user code.
266
+ """
267
+ return response
268
+
269
+ def pre_get_operation(
270
+ self,
271
+ request: operations_pb2.GetOperationRequest,
272
+ metadata: Sequence[Tuple[str, Union[str, bytes]]],
273
+ ) -> Tuple[
274
+ operations_pb2.GetOperationRequest, Sequence[Tuple[str, Union[str, bytes]]]
275
+ ]:
276
+ """Pre-rpc interceptor for get_operation
277
+
278
+ Override in a subclass to manipulate the request or metadata
279
+ before they are sent to the PermissionService server.
280
+ """
281
+ return request, metadata
282
+
283
+ def post_get_operation(
284
+ self, response: operations_pb2.Operation
285
+ ) -> operations_pb2.Operation:
286
+ """Post-rpc interceptor for get_operation
287
+
288
+ Override in a subclass to manipulate the response
289
+ after it is returned by the PermissionService server but before
290
+ it is returned to user code.
291
+ """
292
+ return response
293
+
294
+ def pre_list_operations(
295
+ self,
296
+ request: operations_pb2.ListOperationsRequest,
297
+ metadata: Sequence[Tuple[str, Union[str, bytes]]],
298
+ ) -> Tuple[
299
+ operations_pb2.ListOperationsRequest, Sequence[Tuple[str, Union[str, bytes]]]
300
+ ]:
301
+ """Pre-rpc interceptor for list_operations
302
+
303
+ Override in a subclass to manipulate the request or metadata
304
+ before they are sent to the PermissionService server.
305
+ """
306
+ return request, metadata
307
+
308
+ def post_list_operations(
309
+ self, response: operations_pb2.ListOperationsResponse
310
+ ) -> operations_pb2.ListOperationsResponse:
311
+ """Post-rpc interceptor for list_operations
312
+
313
+ Override in a subclass to manipulate the response
314
+ after it is returned by the PermissionService server but before
315
+ it is returned to user code.
316
+ """
317
+ return response
318
+
319
+
320
+ @dataclasses.dataclass
321
+ class PermissionServiceRestStub:
322
+ _session: AuthorizedSession
323
+ _host: str
324
+ _interceptor: PermissionServiceRestInterceptor
325
+
326
+
327
+ class PermissionServiceRestTransport(_BasePermissionServiceRestTransport):
328
+ """REST backend synchronous transport for PermissionService.
329
+
330
+ Provides methods for managing permissions to PaLM API
331
+ resources.
332
+
333
+ This class defines the same methods as the primary client, so the
334
+ primary client can load the underlying transport implementation
335
+ and call it.
336
+
337
+ It sends JSON representations of protocol buffers over HTTP/1.1
338
+ """
339
+
340
+ def __init__(
341
+ self,
342
+ *,
343
+ host: str = "generativelanguage.googleapis.com",
344
+ credentials: Optional[ga_credentials.Credentials] = None,
345
+ credentials_file: Optional[str] = None,
346
+ scopes: Optional[Sequence[str]] = None,
347
+ client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
348
+ quota_project_id: Optional[str] = None,
349
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
350
+ always_use_jwt_access: Optional[bool] = False,
351
+ url_scheme: str = "https",
352
+ interceptor: Optional[PermissionServiceRestInterceptor] = None,
353
+ api_audience: Optional[str] = None,
354
+ ) -> None:
355
+ """Instantiate the transport.
356
+
357
+ Args:
358
+ host (Optional[str]):
359
+ The hostname to connect to (default: 'generativelanguage.googleapis.com').
360
+ credentials (Optional[google.auth.credentials.Credentials]): The
361
+ authorization credentials to attach to requests. These
362
+ credentials identify the application to the service; if none
363
+ are specified, the client will attempt to ascertain the
364
+ credentials from the environment.
365
+
366
+ credentials_file (Optional[str]): A file with credentials that can
367
+ be loaded with :func:`google.auth.load_credentials_from_file`.
368
+ This argument is ignored if ``channel`` is provided.
369
+ scopes (Optional(Sequence[str])): A list of scopes. This argument is
370
+ ignored if ``channel`` is provided.
371
+ client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client
372
+ certificate to configure mutual TLS HTTP channel. It is ignored
373
+ if ``channel`` is provided.
374
+ quota_project_id (Optional[str]): An optional project to use for billing
375
+ and quota.
376
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
377
+ The client info used to send a user-agent string along with
378
+ API requests. If ``None``, then default info will be used.
379
+ Generally, you only need to set this if you are developing
380
+ your own client library.
381
+ always_use_jwt_access (Optional[bool]): Whether self signed JWT should
382
+ be used for service account credentials.
383
+ url_scheme: the protocol scheme for the API endpoint. Normally
384
+ "https", but for testing or local servers,
385
+ "http" can be specified.
386
+ """
387
+ # Run the base constructor
388
+ # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc.
389
+ # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the
390
+ # credentials object
391
+ super().__init__(
392
+ host=host,
393
+ credentials=credentials,
394
+ client_info=client_info,
395
+ always_use_jwt_access=always_use_jwt_access,
396
+ url_scheme=url_scheme,
397
+ api_audience=api_audience,
398
+ )
399
+ self._session = AuthorizedSession(
400
+ self._credentials, default_host=self.DEFAULT_HOST
401
+ )
402
+ if client_cert_source_for_mtls:
403
+ self._session.configure_mtls_channel(client_cert_source_for_mtls)
404
+ self._interceptor = interceptor or PermissionServiceRestInterceptor()
405
+ self._prep_wrapped_messages(client_info)
406
+
407
+ class _CreatePermission(
408
+ _BasePermissionServiceRestTransport._BaseCreatePermission,
409
+ PermissionServiceRestStub,
410
+ ):
411
+ def __hash__(self):
412
+ return hash("PermissionServiceRestTransport.CreatePermission")
413
+
414
+ @staticmethod
415
+ def _get_response(
416
+ host,
417
+ metadata,
418
+ query_params,
419
+ session,
420
+ timeout,
421
+ transcoded_request,
422
+ body=None,
423
+ ):
424
+ uri = transcoded_request["uri"]
425
+ method = transcoded_request["method"]
426
+ headers = dict(metadata)
427
+ headers["Content-Type"] = "application/json"
428
+ response = getattr(session, method)(
429
+ "{host}{uri}".format(host=host, uri=uri),
430
+ timeout=timeout,
431
+ headers=headers,
432
+ params=rest_helpers.flatten_query_params(query_params, strict=True),
433
+ data=body,
434
+ )
435
+ return response
436
+
437
+ def __call__(
438
+ self,
439
+ request: permission_service.CreatePermissionRequest,
440
+ *,
441
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
442
+ timeout: Optional[float] = None,
443
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
444
+ ) -> gag_permission.Permission:
445
+ r"""Call the create permission method over HTTP.
446
+
447
+ Args:
448
+ request (~.permission_service.CreatePermissionRequest):
449
+ The request object. Request to create a ``Permission``.
450
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
451
+ should be retried.
452
+ timeout (float): The timeout for this request.
453
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
454
+ sent along with the request as metadata. Normally, each value must be of type `str`,
455
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
456
+ be of type `bytes`.
457
+
458
+ Returns:
459
+ ~.gag_permission.Permission:
460
+ Permission resource grants user,
461
+ group or the rest of the world access to
462
+ the PaLM API resource (e.g. a tuned
463
+ model, corpus).
464
+
465
+ A role is a collection of permitted
466
+ operations that allows users to perform
467
+ specific actions on PaLM API resources.
468
+ To make them available to users, groups,
469
+ or service accounts, you assign roles.
470
+ When you assign a role, you grant
471
+ permissions that the role contains.
472
+
473
+ There are three concentric roles. Each
474
+ role is a superset of the previous
475
+ role's permitted operations:
476
+
477
+ - reader can use the resource (e.g.
478
+ tuned model, corpus) for inference
479
+ - writer has reader's permissions and
480
+ additionally can edit and share
481
+ - owner has writer's permissions and
482
+ additionally can delete
483
+
484
+ """
485
+
486
+ http_options = (
487
+ _BasePermissionServiceRestTransport._BaseCreatePermission._get_http_options()
488
+ )
489
+
490
+ request, metadata = self._interceptor.pre_create_permission(
491
+ request, metadata
492
+ )
493
+ transcoded_request = _BasePermissionServiceRestTransport._BaseCreatePermission._get_transcoded_request(
494
+ http_options, request
495
+ )
496
+
497
+ body = _BasePermissionServiceRestTransport._BaseCreatePermission._get_request_body_json(
498
+ transcoded_request
499
+ )
500
+
501
+ # Jsonify the query params
502
+ query_params = _BasePermissionServiceRestTransport._BaseCreatePermission._get_query_params_json(
503
+ transcoded_request
504
+ )
505
+
506
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
507
+ logging.DEBUG
508
+ ): # pragma: NO COVER
509
+ request_url = "{host}{uri}".format(
510
+ host=self._host, uri=transcoded_request["uri"]
511
+ )
512
+ method = transcoded_request["method"]
513
+ try:
514
+ request_payload = type(request).to_json(request)
515
+ except:
516
+ request_payload = None
517
+ http_request = {
518
+ "payload": request_payload,
519
+ "requestMethod": method,
520
+ "requestUrl": request_url,
521
+ "headers": dict(metadata),
522
+ }
523
+ _LOGGER.debug(
524
+ f"Sending request for google.ai.generativelanguage_v1beta.PermissionServiceClient.CreatePermission",
525
+ extra={
526
+ "serviceName": "google.ai.generativelanguage.v1beta.PermissionService",
527
+ "rpcName": "CreatePermission",
528
+ "httpRequest": http_request,
529
+ "metadata": http_request["headers"],
530
+ },
531
+ )
532
+
533
+ # Send the request
534
+ response = PermissionServiceRestTransport._CreatePermission._get_response(
535
+ self._host,
536
+ metadata,
537
+ query_params,
538
+ self._session,
539
+ timeout,
540
+ transcoded_request,
541
+ body,
542
+ )
543
+
544
+ # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
545
+ # subclass.
546
+ if response.status_code >= 400:
547
+ raise core_exceptions.from_http_response(response)
548
+
549
+ # Return the response
550
+ resp = gag_permission.Permission()
551
+ pb_resp = gag_permission.Permission.pb(resp)
552
+
553
+ json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
554
+
555
+ resp = self._interceptor.post_create_permission(resp)
556
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
557
+ logging.DEBUG
558
+ ): # pragma: NO COVER
559
+ try:
560
+ response_payload = gag_permission.Permission.to_json(response)
561
+ except:
562
+ response_payload = None
563
+ http_response = {
564
+ "payload": response_payload,
565
+ "headers": dict(response.headers),
566
+ "status": response.status_code,
567
+ }
568
+ _LOGGER.debug(
569
+ "Received response for google.ai.generativelanguage_v1beta.PermissionServiceClient.create_permission",
570
+ extra={
571
+ "serviceName": "google.ai.generativelanguage.v1beta.PermissionService",
572
+ "rpcName": "CreatePermission",
573
+ "metadata": http_response["headers"],
574
+ "httpResponse": http_response,
575
+ },
576
+ )
577
+ return resp
578
+
579
+ class _DeletePermission(
580
+ _BasePermissionServiceRestTransport._BaseDeletePermission,
581
+ PermissionServiceRestStub,
582
+ ):
583
+ def __hash__(self):
584
+ return hash("PermissionServiceRestTransport.DeletePermission")
585
+
586
+ @staticmethod
587
+ def _get_response(
588
+ host,
589
+ metadata,
590
+ query_params,
591
+ session,
592
+ timeout,
593
+ transcoded_request,
594
+ body=None,
595
+ ):
596
+ uri = transcoded_request["uri"]
597
+ method = transcoded_request["method"]
598
+ headers = dict(metadata)
599
+ headers["Content-Type"] = "application/json"
600
+ response = getattr(session, method)(
601
+ "{host}{uri}".format(host=host, uri=uri),
602
+ timeout=timeout,
603
+ headers=headers,
604
+ params=rest_helpers.flatten_query_params(query_params, strict=True),
605
+ )
606
+ return response
607
+
608
+ def __call__(
609
+ self,
610
+ request: permission_service.DeletePermissionRequest,
611
+ *,
612
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
613
+ timeout: Optional[float] = None,
614
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
615
+ ):
616
+ r"""Call the delete permission method over HTTP.
617
+
618
+ Args:
619
+ request (~.permission_service.DeletePermissionRequest):
620
+ The request object. Request to delete the ``Permission``.
621
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
622
+ should be retried.
623
+ timeout (float): The timeout for this request.
624
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
625
+ sent along with the request as metadata. Normally, each value must be of type `str`,
626
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
627
+ be of type `bytes`.
628
+ """
629
+
630
+ http_options = (
631
+ _BasePermissionServiceRestTransport._BaseDeletePermission._get_http_options()
632
+ )
633
+
634
+ request, metadata = self._interceptor.pre_delete_permission(
635
+ request, metadata
636
+ )
637
+ transcoded_request = _BasePermissionServiceRestTransport._BaseDeletePermission._get_transcoded_request(
638
+ http_options, request
639
+ )
640
+
641
+ # Jsonify the query params
642
+ query_params = _BasePermissionServiceRestTransport._BaseDeletePermission._get_query_params_json(
643
+ transcoded_request
644
+ )
645
+
646
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
647
+ logging.DEBUG
648
+ ): # pragma: NO COVER
649
+ request_url = "{host}{uri}".format(
650
+ host=self._host, uri=transcoded_request["uri"]
651
+ )
652
+ method = transcoded_request["method"]
653
+ try:
654
+ request_payload = json_format.MessageToJson(request)
655
+ except:
656
+ request_payload = None
657
+ http_request = {
658
+ "payload": request_payload,
659
+ "requestMethod": method,
660
+ "requestUrl": request_url,
661
+ "headers": dict(metadata),
662
+ }
663
+ _LOGGER.debug(
664
+ f"Sending request for google.ai.generativelanguage_v1beta.PermissionServiceClient.DeletePermission",
665
+ extra={
666
+ "serviceName": "google.ai.generativelanguage.v1beta.PermissionService",
667
+ "rpcName": "DeletePermission",
668
+ "httpRequest": http_request,
669
+ "metadata": http_request["headers"],
670
+ },
671
+ )
672
+
673
+ # Send the request
674
+ response = PermissionServiceRestTransport._DeletePermission._get_response(
675
+ self._host,
676
+ metadata,
677
+ query_params,
678
+ self._session,
679
+ timeout,
680
+ transcoded_request,
681
+ )
682
+
683
+ # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
684
+ # subclass.
685
+ if response.status_code >= 400:
686
+ raise core_exceptions.from_http_response(response)
687
+
688
+ class _GetPermission(
689
+ _BasePermissionServiceRestTransport._BaseGetPermission,
690
+ PermissionServiceRestStub,
691
+ ):
692
+ def __hash__(self):
693
+ return hash("PermissionServiceRestTransport.GetPermission")
694
+
695
+ @staticmethod
696
+ def _get_response(
697
+ host,
698
+ metadata,
699
+ query_params,
700
+ session,
701
+ timeout,
702
+ transcoded_request,
703
+ body=None,
704
+ ):
705
+ uri = transcoded_request["uri"]
706
+ method = transcoded_request["method"]
707
+ headers = dict(metadata)
708
+ headers["Content-Type"] = "application/json"
709
+ response = getattr(session, method)(
710
+ "{host}{uri}".format(host=host, uri=uri),
711
+ timeout=timeout,
712
+ headers=headers,
713
+ params=rest_helpers.flatten_query_params(query_params, strict=True),
714
+ )
715
+ return response
716
+
717
+ def __call__(
718
+ self,
719
+ request: permission_service.GetPermissionRequest,
720
+ *,
721
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
722
+ timeout: Optional[float] = None,
723
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
724
+ ) -> permission.Permission:
725
+ r"""Call the get permission method over HTTP.
726
+
727
+ Args:
728
+ request (~.permission_service.GetPermissionRequest):
729
+ The request object. Request for getting information about a specific
730
+ ``Permission``.
731
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
732
+ should be retried.
733
+ timeout (float): The timeout for this request.
734
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
735
+ sent along with the request as metadata. Normally, each value must be of type `str`,
736
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
737
+ be of type `bytes`.
738
+
739
+ Returns:
740
+ ~.permission.Permission:
741
+ Permission resource grants user,
742
+ group or the rest of the world access to
743
+ the PaLM API resource (e.g. a tuned
744
+ model, corpus).
745
+
746
+ A role is a collection of permitted
747
+ operations that allows users to perform
748
+ specific actions on PaLM API resources.
749
+ To make them available to users, groups,
750
+ or service accounts, you assign roles.
751
+ When you assign a role, you grant
752
+ permissions that the role contains.
753
+
754
+ There are three concentric roles. Each
755
+ role is a superset of the previous
756
+ role's permitted operations:
757
+
758
+ - reader can use the resource (e.g.
759
+ tuned model, corpus) for inference
760
+ - writer has reader's permissions and
761
+ additionally can edit and share
762
+ - owner has writer's permissions and
763
+ additionally can delete
764
+
765
+ """
766
+
767
+ http_options = (
768
+ _BasePermissionServiceRestTransport._BaseGetPermission._get_http_options()
769
+ )
770
+
771
+ request, metadata = self._interceptor.pre_get_permission(request, metadata)
772
+ transcoded_request = _BasePermissionServiceRestTransport._BaseGetPermission._get_transcoded_request(
773
+ http_options, request
774
+ )
775
+
776
+ # Jsonify the query params
777
+ query_params = _BasePermissionServiceRestTransport._BaseGetPermission._get_query_params_json(
778
+ transcoded_request
779
+ )
780
+
781
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
782
+ logging.DEBUG
783
+ ): # pragma: NO COVER
784
+ request_url = "{host}{uri}".format(
785
+ host=self._host, uri=transcoded_request["uri"]
786
+ )
787
+ method = transcoded_request["method"]
788
+ try:
789
+ request_payload = type(request).to_json(request)
790
+ except:
791
+ request_payload = None
792
+ http_request = {
793
+ "payload": request_payload,
794
+ "requestMethod": method,
795
+ "requestUrl": request_url,
796
+ "headers": dict(metadata),
797
+ }
798
+ _LOGGER.debug(
799
+ f"Sending request for google.ai.generativelanguage_v1beta.PermissionServiceClient.GetPermission",
800
+ extra={
801
+ "serviceName": "google.ai.generativelanguage.v1beta.PermissionService",
802
+ "rpcName": "GetPermission",
803
+ "httpRequest": http_request,
804
+ "metadata": http_request["headers"],
805
+ },
806
+ )
807
+
808
+ # Send the request
809
+ response = PermissionServiceRestTransport._GetPermission._get_response(
810
+ self._host,
811
+ metadata,
812
+ query_params,
813
+ self._session,
814
+ timeout,
815
+ transcoded_request,
816
+ )
817
+
818
+ # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
819
+ # subclass.
820
+ if response.status_code >= 400:
821
+ raise core_exceptions.from_http_response(response)
822
+
823
+ # Return the response
824
+ resp = permission.Permission()
825
+ pb_resp = permission.Permission.pb(resp)
826
+
827
+ json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
828
+
829
+ resp = self._interceptor.post_get_permission(resp)
830
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
831
+ logging.DEBUG
832
+ ): # pragma: NO COVER
833
+ try:
834
+ response_payload = permission.Permission.to_json(response)
835
+ except:
836
+ response_payload = None
837
+ http_response = {
838
+ "payload": response_payload,
839
+ "headers": dict(response.headers),
840
+ "status": response.status_code,
841
+ }
842
+ _LOGGER.debug(
843
+ "Received response for google.ai.generativelanguage_v1beta.PermissionServiceClient.get_permission",
844
+ extra={
845
+ "serviceName": "google.ai.generativelanguage.v1beta.PermissionService",
846
+ "rpcName": "GetPermission",
847
+ "metadata": http_response["headers"],
848
+ "httpResponse": http_response,
849
+ },
850
+ )
851
+ return resp
852
+
853
+ class _ListPermissions(
854
+ _BasePermissionServiceRestTransport._BaseListPermissions,
855
+ PermissionServiceRestStub,
856
+ ):
857
+ def __hash__(self):
858
+ return hash("PermissionServiceRestTransport.ListPermissions")
859
+
860
+ @staticmethod
861
+ def _get_response(
862
+ host,
863
+ metadata,
864
+ query_params,
865
+ session,
866
+ timeout,
867
+ transcoded_request,
868
+ body=None,
869
+ ):
870
+ uri = transcoded_request["uri"]
871
+ method = transcoded_request["method"]
872
+ headers = dict(metadata)
873
+ headers["Content-Type"] = "application/json"
874
+ response = getattr(session, method)(
875
+ "{host}{uri}".format(host=host, uri=uri),
876
+ timeout=timeout,
877
+ headers=headers,
878
+ params=rest_helpers.flatten_query_params(query_params, strict=True),
879
+ )
880
+ return response
881
+
882
+ def __call__(
883
+ self,
884
+ request: permission_service.ListPermissionsRequest,
885
+ *,
886
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
887
+ timeout: Optional[float] = None,
888
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
889
+ ) -> permission_service.ListPermissionsResponse:
890
+ r"""Call the list permissions method over HTTP.
891
+
892
+ Args:
893
+ request (~.permission_service.ListPermissionsRequest):
894
+ The request object. Request for listing permissions.
895
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
896
+ should be retried.
897
+ timeout (float): The timeout for this request.
898
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
899
+ sent along with the request as metadata. Normally, each value must be of type `str`,
900
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
901
+ be of type `bytes`.
902
+
903
+ Returns:
904
+ ~.permission_service.ListPermissionsResponse:
905
+ Response from ``ListPermissions`` containing a paginated
906
+ list of permissions.
907
+
908
+ """
909
+
910
+ http_options = (
911
+ _BasePermissionServiceRestTransport._BaseListPermissions._get_http_options()
912
+ )
913
+
914
+ request, metadata = self._interceptor.pre_list_permissions(
915
+ request, metadata
916
+ )
917
+ transcoded_request = _BasePermissionServiceRestTransport._BaseListPermissions._get_transcoded_request(
918
+ http_options, request
919
+ )
920
+
921
+ # Jsonify the query params
922
+ query_params = _BasePermissionServiceRestTransport._BaseListPermissions._get_query_params_json(
923
+ transcoded_request
924
+ )
925
+
926
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
927
+ logging.DEBUG
928
+ ): # pragma: NO COVER
929
+ request_url = "{host}{uri}".format(
930
+ host=self._host, uri=transcoded_request["uri"]
931
+ )
932
+ method = transcoded_request["method"]
933
+ try:
934
+ request_payload = type(request).to_json(request)
935
+ except:
936
+ request_payload = None
937
+ http_request = {
938
+ "payload": request_payload,
939
+ "requestMethod": method,
940
+ "requestUrl": request_url,
941
+ "headers": dict(metadata),
942
+ }
943
+ _LOGGER.debug(
944
+ f"Sending request for google.ai.generativelanguage_v1beta.PermissionServiceClient.ListPermissions",
945
+ extra={
946
+ "serviceName": "google.ai.generativelanguage.v1beta.PermissionService",
947
+ "rpcName": "ListPermissions",
948
+ "httpRequest": http_request,
949
+ "metadata": http_request["headers"],
950
+ },
951
+ )
952
+
953
+ # Send the request
954
+ response = PermissionServiceRestTransport._ListPermissions._get_response(
955
+ self._host,
956
+ metadata,
957
+ query_params,
958
+ self._session,
959
+ timeout,
960
+ transcoded_request,
961
+ )
962
+
963
+ # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
964
+ # subclass.
965
+ if response.status_code >= 400:
966
+ raise core_exceptions.from_http_response(response)
967
+
968
+ # Return the response
969
+ resp = permission_service.ListPermissionsResponse()
970
+ pb_resp = permission_service.ListPermissionsResponse.pb(resp)
971
+
972
+ json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
973
+
974
+ resp = self._interceptor.post_list_permissions(resp)
975
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
976
+ logging.DEBUG
977
+ ): # pragma: NO COVER
978
+ try:
979
+ response_payload = (
980
+ permission_service.ListPermissionsResponse.to_json(response)
981
+ )
982
+ except:
983
+ response_payload = None
984
+ http_response = {
985
+ "payload": response_payload,
986
+ "headers": dict(response.headers),
987
+ "status": response.status_code,
988
+ }
989
+ _LOGGER.debug(
990
+ "Received response for google.ai.generativelanguage_v1beta.PermissionServiceClient.list_permissions",
991
+ extra={
992
+ "serviceName": "google.ai.generativelanguage.v1beta.PermissionService",
993
+ "rpcName": "ListPermissions",
994
+ "metadata": http_response["headers"],
995
+ "httpResponse": http_response,
996
+ },
997
+ )
998
+ return resp
999
+
1000
+ class _TransferOwnership(
1001
+ _BasePermissionServiceRestTransport._BaseTransferOwnership,
1002
+ PermissionServiceRestStub,
1003
+ ):
1004
+ def __hash__(self):
1005
+ return hash("PermissionServiceRestTransport.TransferOwnership")
1006
+
1007
+ @staticmethod
1008
+ def _get_response(
1009
+ host,
1010
+ metadata,
1011
+ query_params,
1012
+ session,
1013
+ timeout,
1014
+ transcoded_request,
1015
+ body=None,
1016
+ ):
1017
+ uri = transcoded_request["uri"]
1018
+ method = transcoded_request["method"]
1019
+ headers = dict(metadata)
1020
+ headers["Content-Type"] = "application/json"
1021
+ response = getattr(session, method)(
1022
+ "{host}{uri}".format(host=host, uri=uri),
1023
+ timeout=timeout,
1024
+ headers=headers,
1025
+ params=rest_helpers.flatten_query_params(query_params, strict=True),
1026
+ data=body,
1027
+ )
1028
+ return response
1029
+
1030
+ def __call__(
1031
+ self,
1032
+ request: permission_service.TransferOwnershipRequest,
1033
+ *,
1034
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1035
+ timeout: Optional[float] = None,
1036
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1037
+ ) -> permission_service.TransferOwnershipResponse:
1038
+ r"""Call the transfer ownership method over HTTP.
1039
+
1040
+ Args:
1041
+ request (~.permission_service.TransferOwnershipRequest):
1042
+ The request object. Request to transfer the ownership of
1043
+ the tuned model.
1044
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1045
+ should be retried.
1046
+ timeout (float): The timeout for this request.
1047
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1048
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1049
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1050
+ be of type `bytes`.
1051
+
1052
+ Returns:
1053
+ ~.permission_service.TransferOwnershipResponse:
1054
+ Response from ``TransferOwnership``.
1055
+ """
1056
+
1057
+ http_options = (
1058
+ _BasePermissionServiceRestTransport._BaseTransferOwnership._get_http_options()
1059
+ )
1060
+
1061
+ request, metadata = self._interceptor.pre_transfer_ownership(
1062
+ request, metadata
1063
+ )
1064
+ transcoded_request = _BasePermissionServiceRestTransport._BaseTransferOwnership._get_transcoded_request(
1065
+ http_options, request
1066
+ )
1067
+
1068
+ body = _BasePermissionServiceRestTransport._BaseTransferOwnership._get_request_body_json(
1069
+ transcoded_request
1070
+ )
1071
+
1072
+ # Jsonify the query params
1073
+ query_params = _BasePermissionServiceRestTransport._BaseTransferOwnership._get_query_params_json(
1074
+ transcoded_request
1075
+ )
1076
+
1077
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1078
+ logging.DEBUG
1079
+ ): # pragma: NO COVER
1080
+ request_url = "{host}{uri}".format(
1081
+ host=self._host, uri=transcoded_request["uri"]
1082
+ )
1083
+ method = transcoded_request["method"]
1084
+ try:
1085
+ request_payload = type(request).to_json(request)
1086
+ except:
1087
+ request_payload = None
1088
+ http_request = {
1089
+ "payload": request_payload,
1090
+ "requestMethod": method,
1091
+ "requestUrl": request_url,
1092
+ "headers": dict(metadata),
1093
+ }
1094
+ _LOGGER.debug(
1095
+ f"Sending request for google.ai.generativelanguage_v1beta.PermissionServiceClient.TransferOwnership",
1096
+ extra={
1097
+ "serviceName": "google.ai.generativelanguage.v1beta.PermissionService",
1098
+ "rpcName": "TransferOwnership",
1099
+ "httpRequest": http_request,
1100
+ "metadata": http_request["headers"],
1101
+ },
1102
+ )
1103
+
1104
+ # Send the request
1105
+ response = PermissionServiceRestTransport._TransferOwnership._get_response(
1106
+ self._host,
1107
+ metadata,
1108
+ query_params,
1109
+ self._session,
1110
+ timeout,
1111
+ transcoded_request,
1112
+ body,
1113
+ )
1114
+
1115
+ # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1116
+ # subclass.
1117
+ if response.status_code >= 400:
1118
+ raise core_exceptions.from_http_response(response)
1119
+
1120
+ # Return the response
1121
+ resp = permission_service.TransferOwnershipResponse()
1122
+ pb_resp = permission_service.TransferOwnershipResponse.pb(resp)
1123
+
1124
+ json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
1125
+
1126
+ resp = self._interceptor.post_transfer_ownership(resp)
1127
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1128
+ logging.DEBUG
1129
+ ): # pragma: NO COVER
1130
+ try:
1131
+ response_payload = (
1132
+ permission_service.TransferOwnershipResponse.to_json(response)
1133
+ )
1134
+ except:
1135
+ response_payload = None
1136
+ http_response = {
1137
+ "payload": response_payload,
1138
+ "headers": dict(response.headers),
1139
+ "status": response.status_code,
1140
+ }
1141
+ _LOGGER.debug(
1142
+ "Received response for google.ai.generativelanguage_v1beta.PermissionServiceClient.transfer_ownership",
1143
+ extra={
1144
+ "serviceName": "google.ai.generativelanguage.v1beta.PermissionService",
1145
+ "rpcName": "TransferOwnership",
1146
+ "metadata": http_response["headers"],
1147
+ "httpResponse": http_response,
1148
+ },
1149
+ )
1150
+ return resp
1151
+
1152
+ class _UpdatePermission(
1153
+ _BasePermissionServiceRestTransport._BaseUpdatePermission,
1154
+ PermissionServiceRestStub,
1155
+ ):
1156
+ def __hash__(self):
1157
+ return hash("PermissionServiceRestTransport.UpdatePermission")
1158
+
1159
+ @staticmethod
1160
+ def _get_response(
1161
+ host,
1162
+ metadata,
1163
+ query_params,
1164
+ session,
1165
+ timeout,
1166
+ transcoded_request,
1167
+ body=None,
1168
+ ):
1169
+ uri = transcoded_request["uri"]
1170
+ method = transcoded_request["method"]
1171
+ headers = dict(metadata)
1172
+ headers["Content-Type"] = "application/json"
1173
+ response = getattr(session, method)(
1174
+ "{host}{uri}".format(host=host, uri=uri),
1175
+ timeout=timeout,
1176
+ headers=headers,
1177
+ params=rest_helpers.flatten_query_params(query_params, strict=True),
1178
+ data=body,
1179
+ )
1180
+ return response
1181
+
1182
+ def __call__(
1183
+ self,
1184
+ request: permission_service.UpdatePermissionRequest,
1185
+ *,
1186
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1187
+ timeout: Optional[float] = None,
1188
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1189
+ ) -> gag_permission.Permission:
1190
+ r"""Call the update permission method over HTTP.
1191
+
1192
+ Args:
1193
+ request (~.permission_service.UpdatePermissionRequest):
1194
+ The request object. Request to update the ``Permission``.
1195
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1196
+ should be retried.
1197
+ timeout (float): The timeout for this request.
1198
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1199
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1200
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1201
+ be of type `bytes`.
1202
+
1203
+ Returns:
1204
+ ~.gag_permission.Permission:
1205
+ Permission resource grants user,
1206
+ group or the rest of the world access to
1207
+ the PaLM API resource (e.g. a tuned
1208
+ model, corpus).
1209
+
1210
+ A role is a collection of permitted
1211
+ operations that allows users to perform
1212
+ specific actions on PaLM API resources.
1213
+ To make them available to users, groups,
1214
+ or service accounts, you assign roles.
1215
+ When you assign a role, you grant
1216
+ permissions that the role contains.
1217
+
1218
+ There are three concentric roles. Each
1219
+ role is a superset of the previous
1220
+ role's permitted operations:
1221
+
1222
+ - reader can use the resource (e.g.
1223
+ tuned model, corpus) for inference
1224
+ - writer has reader's permissions and
1225
+ additionally can edit and share
1226
+ - owner has writer's permissions and
1227
+ additionally can delete
1228
+
1229
+ """
1230
+
1231
+ http_options = (
1232
+ _BasePermissionServiceRestTransport._BaseUpdatePermission._get_http_options()
1233
+ )
1234
+
1235
+ request, metadata = self._interceptor.pre_update_permission(
1236
+ request, metadata
1237
+ )
1238
+ transcoded_request = _BasePermissionServiceRestTransport._BaseUpdatePermission._get_transcoded_request(
1239
+ http_options, request
1240
+ )
1241
+
1242
+ body = _BasePermissionServiceRestTransport._BaseUpdatePermission._get_request_body_json(
1243
+ transcoded_request
1244
+ )
1245
+
1246
+ # Jsonify the query params
1247
+ query_params = _BasePermissionServiceRestTransport._BaseUpdatePermission._get_query_params_json(
1248
+ transcoded_request
1249
+ )
1250
+
1251
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1252
+ logging.DEBUG
1253
+ ): # pragma: NO COVER
1254
+ request_url = "{host}{uri}".format(
1255
+ host=self._host, uri=transcoded_request["uri"]
1256
+ )
1257
+ method = transcoded_request["method"]
1258
+ try:
1259
+ request_payload = type(request).to_json(request)
1260
+ except:
1261
+ request_payload = None
1262
+ http_request = {
1263
+ "payload": request_payload,
1264
+ "requestMethod": method,
1265
+ "requestUrl": request_url,
1266
+ "headers": dict(metadata),
1267
+ }
1268
+ _LOGGER.debug(
1269
+ f"Sending request for google.ai.generativelanguage_v1beta.PermissionServiceClient.UpdatePermission",
1270
+ extra={
1271
+ "serviceName": "google.ai.generativelanguage.v1beta.PermissionService",
1272
+ "rpcName": "UpdatePermission",
1273
+ "httpRequest": http_request,
1274
+ "metadata": http_request["headers"],
1275
+ },
1276
+ )
1277
+
1278
+ # Send the request
1279
+ response = PermissionServiceRestTransport._UpdatePermission._get_response(
1280
+ self._host,
1281
+ metadata,
1282
+ query_params,
1283
+ self._session,
1284
+ timeout,
1285
+ transcoded_request,
1286
+ body,
1287
+ )
1288
+
1289
+ # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1290
+ # subclass.
1291
+ if response.status_code >= 400:
1292
+ raise core_exceptions.from_http_response(response)
1293
+
1294
+ # Return the response
1295
+ resp = gag_permission.Permission()
1296
+ pb_resp = gag_permission.Permission.pb(resp)
1297
+
1298
+ json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
1299
+
1300
+ resp = self._interceptor.post_update_permission(resp)
1301
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1302
+ logging.DEBUG
1303
+ ): # pragma: NO COVER
1304
+ try:
1305
+ response_payload = gag_permission.Permission.to_json(response)
1306
+ except:
1307
+ response_payload = None
1308
+ http_response = {
1309
+ "payload": response_payload,
1310
+ "headers": dict(response.headers),
1311
+ "status": response.status_code,
1312
+ }
1313
+ _LOGGER.debug(
1314
+ "Received response for google.ai.generativelanguage_v1beta.PermissionServiceClient.update_permission",
1315
+ extra={
1316
+ "serviceName": "google.ai.generativelanguage.v1beta.PermissionService",
1317
+ "rpcName": "UpdatePermission",
1318
+ "metadata": http_response["headers"],
1319
+ "httpResponse": http_response,
1320
+ },
1321
+ )
1322
+ return resp
1323
+
1324
+ @property
1325
+ def create_permission(
1326
+ self,
1327
+ ) -> Callable[
1328
+ [permission_service.CreatePermissionRequest], gag_permission.Permission
1329
+ ]:
1330
+ # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
1331
+ # In C++ this would require a dynamic_cast
1332
+ return self._CreatePermission(self._session, self._host, self._interceptor) # type: ignore
1333
+
1334
+ @property
1335
+ def delete_permission(
1336
+ self,
1337
+ ) -> Callable[[permission_service.DeletePermissionRequest], empty_pb2.Empty]:
1338
+ # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
1339
+ # In C++ this would require a dynamic_cast
1340
+ return self._DeletePermission(self._session, self._host, self._interceptor) # type: ignore
1341
+
1342
+ @property
1343
+ def get_permission(
1344
+ self,
1345
+ ) -> Callable[[permission_service.GetPermissionRequest], permission.Permission]:
1346
+ # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
1347
+ # In C++ this would require a dynamic_cast
1348
+ return self._GetPermission(self._session, self._host, self._interceptor) # type: ignore
1349
+
1350
+ @property
1351
+ def list_permissions(
1352
+ self,
1353
+ ) -> Callable[
1354
+ [permission_service.ListPermissionsRequest],
1355
+ permission_service.ListPermissionsResponse,
1356
+ ]:
1357
+ # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
1358
+ # In C++ this would require a dynamic_cast
1359
+ return self._ListPermissions(self._session, self._host, self._interceptor) # type: ignore
1360
+
1361
+ @property
1362
+ def transfer_ownership(
1363
+ self,
1364
+ ) -> Callable[
1365
+ [permission_service.TransferOwnershipRequest],
1366
+ permission_service.TransferOwnershipResponse,
1367
+ ]:
1368
+ # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
1369
+ # In C++ this would require a dynamic_cast
1370
+ return self._TransferOwnership(self._session, self._host, self._interceptor) # type: ignore
1371
+
1372
+ @property
1373
+ def update_permission(
1374
+ self,
1375
+ ) -> Callable[
1376
+ [permission_service.UpdatePermissionRequest], gag_permission.Permission
1377
+ ]:
1378
+ # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
1379
+ # In C++ this would require a dynamic_cast
1380
+ return self._UpdatePermission(self._session, self._host, self._interceptor) # type: ignore
1381
+
1382
+ @property
1383
+ def get_operation(self):
1384
+ return self._GetOperation(self._session, self._host, self._interceptor) # type: ignore
1385
+
1386
+ class _GetOperation(
1387
+ _BasePermissionServiceRestTransport._BaseGetOperation, PermissionServiceRestStub
1388
+ ):
1389
+ def __hash__(self):
1390
+ return hash("PermissionServiceRestTransport.GetOperation")
1391
+
1392
+ @staticmethod
1393
+ def _get_response(
1394
+ host,
1395
+ metadata,
1396
+ query_params,
1397
+ session,
1398
+ timeout,
1399
+ transcoded_request,
1400
+ body=None,
1401
+ ):
1402
+ uri = transcoded_request["uri"]
1403
+ method = transcoded_request["method"]
1404
+ headers = dict(metadata)
1405
+ headers["Content-Type"] = "application/json"
1406
+ response = getattr(session, method)(
1407
+ "{host}{uri}".format(host=host, uri=uri),
1408
+ timeout=timeout,
1409
+ headers=headers,
1410
+ params=rest_helpers.flatten_query_params(query_params, strict=True),
1411
+ )
1412
+ return response
1413
+
1414
+ def __call__(
1415
+ self,
1416
+ request: operations_pb2.GetOperationRequest,
1417
+ *,
1418
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1419
+ timeout: Optional[float] = None,
1420
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1421
+ ) -> operations_pb2.Operation:
1422
+ r"""Call the get operation method over HTTP.
1423
+
1424
+ Args:
1425
+ request (operations_pb2.GetOperationRequest):
1426
+ The request object for GetOperation method.
1427
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1428
+ should be retried.
1429
+ timeout (float): The timeout for this request.
1430
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1431
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1432
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1433
+ be of type `bytes`.
1434
+
1435
+ Returns:
1436
+ operations_pb2.Operation: Response from GetOperation method.
1437
+ """
1438
+
1439
+ http_options = (
1440
+ _BasePermissionServiceRestTransport._BaseGetOperation._get_http_options()
1441
+ )
1442
+
1443
+ request, metadata = self._interceptor.pre_get_operation(request, metadata)
1444
+ transcoded_request = _BasePermissionServiceRestTransport._BaseGetOperation._get_transcoded_request(
1445
+ http_options, request
1446
+ )
1447
+
1448
+ # Jsonify the query params
1449
+ query_params = _BasePermissionServiceRestTransport._BaseGetOperation._get_query_params_json(
1450
+ transcoded_request
1451
+ )
1452
+
1453
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1454
+ logging.DEBUG
1455
+ ): # pragma: NO COVER
1456
+ request_url = "{host}{uri}".format(
1457
+ host=self._host, uri=transcoded_request["uri"]
1458
+ )
1459
+ method = transcoded_request["method"]
1460
+ try:
1461
+ request_payload = json_format.MessageToJson(request)
1462
+ except:
1463
+ request_payload = None
1464
+ http_request = {
1465
+ "payload": request_payload,
1466
+ "requestMethod": method,
1467
+ "requestUrl": request_url,
1468
+ "headers": dict(metadata),
1469
+ }
1470
+ _LOGGER.debug(
1471
+ f"Sending request for google.ai.generativelanguage_v1beta.PermissionServiceClient.GetOperation",
1472
+ extra={
1473
+ "serviceName": "google.ai.generativelanguage.v1beta.PermissionService",
1474
+ "rpcName": "GetOperation",
1475
+ "httpRequest": http_request,
1476
+ "metadata": http_request["headers"],
1477
+ },
1478
+ )
1479
+
1480
+ # Send the request
1481
+ response = PermissionServiceRestTransport._GetOperation._get_response(
1482
+ self._host,
1483
+ metadata,
1484
+ query_params,
1485
+ self._session,
1486
+ timeout,
1487
+ transcoded_request,
1488
+ )
1489
+
1490
+ # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1491
+ # subclass.
1492
+ if response.status_code >= 400:
1493
+ raise core_exceptions.from_http_response(response)
1494
+
1495
+ content = response.content.decode("utf-8")
1496
+ resp = operations_pb2.Operation()
1497
+ resp = json_format.Parse(content, resp)
1498
+ resp = self._interceptor.post_get_operation(resp)
1499
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1500
+ logging.DEBUG
1501
+ ): # pragma: NO COVER
1502
+ try:
1503
+ response_payload = json_format.MessageToJson(resp)
1504
+ except:
1505
+ response_payload = None
1506
+ http_response = {
1507
+ "payload": response_payload,
1508
+ "headers": dict(response.headers),
1509
+ "status": response.status_code,
1510
+ }
1511
+ _LOGGER.debug(
1512
+ "Received response for google.ai.generativelanguage_v1beta.PermissionServiceAsyncClient.GetOperation",
1513
+ extra={
1514
+ "serviceName": "google.ai.generativelanguage.v1beta.PermissionService",
1515
+ "rpcName": "GetOperation",
1516
+ "httpResponse": http_response,
1517
+ "metadata": http_response["headers"],
1518
+ },
1519
+ )
1520
+ return resp
1521
+
1522
+ @property
1523
+ def list_operations(self):
1524
+ return self._ListOperations(self._session, self._host, self._interceptor) # type: ignore
1525
+
1526
+ class _ListOperations(
1527
+ _BasePermissionServiceRestTransport._BaseListOperations,
1528
+ PermissionServiceRestStub,
1529
+ ):
1530
+ def __hash__(self):
1531
+ return hash("PermissionServiceRestTransport.ListOperations")
1532
+
1533
+ @staticmethod
1534
+ def _get_response(
1535
+ host,
1536
+ metadata,
1537
+ query_params,
1538
+ session,
1539
+ timeout,
1540
+ transcoded_request,
1541
+ body=None,
1542
+ ):
1543
+ uri = transcoded_request["uri"]
1544
+ method = transcoded_request["method"]
1545
+ headers = dict(metadata)
1546
+ headers["Content-Type"] = "application/json"
1547
+ response = getattr(session, method)(
1548
+ "{host}{uri}".format(host=host, uri=uri),
1549
+ timeout=timeout,
1550
+ headers=headers,
1551
+ params=rest_helpers.flatten_query_params(query_params, strict=True),
1552
+ )
1553
+ return response
1554
+
1555
+ def __call__(
1556
+ self,
1557
+ request: operations_pb2.ListOperationsRequest,
1558
+ *,
1559
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1560
+ timeout: Optional[float] = None,
1561
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1562
+ ) -> operations_pb2.ListOperationsResponse:
1563
+ r"""Call the list operations method over HTTP.
1564
+
1565
+ Args:
1566
+ request (operations_pb2.ListOperationsRequest):
1567
+ The request object for ListOperations method.
1568
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1569
+ should be retried.
1570
+ timeout (float): The timeout for this request.
1571
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1572
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1573
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1574
+ be of type `bytes`.
1575
+
1576
+ Returns:
1577
+ operations_pb2.ListOperationsResponse: Response from ListOperations method.
1578
+ """
1579
+
1580
+ http_options = (
1581
+ _BasePermissionServiceRestTransport._BaseListOperations._get_http_options()
1582
+ )
1583
+
1584
+ request, metadata = self._interceptor.pre_list_operations(request, metadata)
1585
+ transcoded_request = _BasePermissionServiceRestTransport._BaseListOperations._get_transcoded_request(
1586
+ http_options, request
1587
+ )
1588
+
1589
+ # Jsonify the query params
1590
+ query_params = _BasePermissionServiceRestTransport._BaseListOperations._get_query_params_json(
1591
+ transcoded_request
1592
+ )
1593
+
1594
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1595
+ logging.DEBUG
1596
+ ): # pragma: NO COVER
1597
+ request_url = "{host}{uri}".format(
1598
+ host=self._host, uri=transcoded_request["uri"]
1599
+ )
1600
+ method = transcoded_request["method"]
1601
+ try:
1602
+ request_payload = json_format.MessageToJson(request)
1603
+ except:
1604
+ request_payload = None
1605
+ http_request = {
1606
+ "payload": request_payload,
1607
+ "requestMethod": method,
1608
+ "requestUrl": request_url,
1609
+ "headers": dict(metadata),
1610
+ }
1611
+ _LOGGER.debug(
1612
+ f"Sending request for google.ai.generativelanguage_v1beta.PermissionServiceClient.ListOperations",
1613
+ extra={
1614
+ "serviceName": "google.ai.generativelanguage.v1beta.PermissionService",
1615
+ "rpcName": "ListOperations",
1616
+ "httpRequest": http_request,
1617
+ "metadata": http_request["headers"],
1618
+ },
1619
+ )
1620
+
1621
+ # Send the request
1622
+ response = PermissionServiceRestTransport._ListOperations._get_response(
1623
+ self._host,
1624
+ metadata,
1625
+ query_params,
1626
+ self._session,
1627
+ timeout,
1628
+ transcoded_request,
1629
+ )
1630
+
1631
+ # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
1632
+ # subclass.
1633
+ if response.status_code >= 400:
1634
+ raise core_exceptions.from_http_response(response)
1635
+
1636
+ content = response.content.decode("utf-8")
1637
+ resp = operations_pb2.ListOperationsResponse()
1638
+ resp = json_format.Parse(content, resp)
1639
+ resp = self._interceptor.post_list_operations(resp)
1640
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
1641
+ logging.DEBUG
1642
+ ): # pragma: NO COVER
1643
+ try:
1644
+ response_payload = json_format.MessageToJson(resp)
1645
+ except:
1646
+ response_payload = None
1647
+ http_response = {
1648
+ "payload": response_payload,
1649
+ "headers": dict(response.headers),
1650
+ "status": response.status_code,
1651
+ }
1652
+ _LOGGER.debug(
1653
+ "Received response for google.ai.generativelanguage_v1beta.PermissionServiceAsyncClient.ListOperations",
1654
+ extra={
1655
+ "serviceName": "google.ai.generativelanguage.v1beta.PermissionService",
1656
+ "rpcName": "ListOperations",
1657
+ "httpResponse": http_response,
1658
+ "metadata": http_response["headers"],
1659
+ },
1660
+ )
1661
+ return resp
1662
+
1663
+ @property
1664
+ def kind(self) -> str:
1665
+ return "rest"
1666
+
1667
+ def close(self):
1668
+ self._session.close()
1669
+
1670
+
1671
+ __all__ = ("PermissionServiceRestTransport",)
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/permission_service/transports/rest_base.py ADDED
@@ -0,0 +1,493 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ import json # type: ignore
17
+ import re
18
+ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
19
+
20
+ from google.api_core import gapic_v1, path_template
21
+ from google.longrunning import operations_pb2 # type: ignore
22
+ from google.protobuf import empty_pb2 # type: ignore
23
+ from google.protobuf import json_format
24
+
25
+ from google.ai.generativelanguage_v1beta.types import permission as gag_permission
26
+ from google.ai.generativelanguage_v1beta.types import permission
27
+ from google.ai.generativelanguage_v1beta.types import permission_service
28
+
29
+ from .base import DEFAULT_CLIENT_INFO, PermissionServiceTransport
30
+
31
+
32
+ class _BasePermissionServiceRestTransport(PermissionServiceTransport):
33
+ """Base REST backend transport for PermissionService.
34
+
35
+ Note: This class is not meant to be used directly. Use its sync and
36
+ async sub-classes instead.
37
+
38
+ This class defines the same methods as the primary client, so the
39
+ primary client can load the underlying transport implementation
40
+ and call it.
41
+
42
+ It sends JSON representations of protocol buffers over HTTP/1.1
43
+ """
44
+
45
+ def __init__(
46
+ self,
47
+ *,
48
+ host: str = "generativelanguage.googleapis.com",
49
+ credentials: Optional[Any] = None,
50
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
51
+ always_use_jwt_access: Optional[bool] = False,
52
+ url_scheme: str = "https",
53
+ api_audience: Optional[str] = None,
54
+ ) -> None:
55
+ """Instantiate the transport.
56
+ Args:
57
+ host (Optional[str]):
58
+ The hostname to connect to (default: 'generativelanguage.googleapis.com').
59
+ credentials (Optional[Any]): The
60
+ authorization credentials to attach to requests. These
61
+ credentials identify the application to the service; if none
62
+ are specified, the client will attempt to ascertain the
63
+ credentials from the environment.
64
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
65
+ The client info used to send a user-agent string along with
66
+ API requests. If ``None``, then default info will be used.
67
+ Generally, you only need to set this if you are developing
68
+ your own client library.
69
+ always_use_jwt_access (Optional[bool]): Whether self signed JWT should
70
+ be used for service account credentials.
71
+ url_scheme: the protocol scheme for the API endpoint. Normally
72
+ "https", but for testing or local servers,
73
+ "http" can be specified.
74
+ """
75
+ # Run the base constructor
76
+ maybe_url_match = re.match("^(?P<scheme>http(?:s)?://)?(?P<host>.*)$", host)
77
+ if maybe_url_match is None:
78
+ raise ValueError(
79
+ f"Unexpected hostname structure: {host}"
80
+ ) # pragma: NO COVER
81
+
82
+ url_match_items = maybe_url_match.groupdict()
83
+
84
+ host = f"{url_scheme}://{host}" if not url_match_items["scheme"] else host
85
+
86
+ super().__init__(
87
+ host=host,
88
+ credentials=credentials,
89
+ client_info=client_info,
90
+ always_use_jwt_access=always_use_jwt_access,
91
+ api_audience=api_audience,
92
+ )
93
+
94
+ class _BaseCreatePermission:
95
+ def __hash__(self): # pragma: NO COVER
96
+ return NotImplementedError("__hash__ must be implemented.")
97
+
98
+ __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
99
+
100
+ @classmethod
101
+ def _get_unset_required_fields(cls, message_dict):
102
+ return {
103
+ k: v
104
+ for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
105
+ if k not in message_dict
106
+ }
107
+
108
+ @staticmethod
109
+ def _get_http_options():
110
+ http_options: List[Dict[str, str]] = [
111
+ {
112
+ "method": "post",
113
+ "uri": "/v1beta/{parent=tunedModels/*}/permissions",
114
+ "body": "permission",
115
+ },
116
+ {
117
+ "method": "post",
118
+ "uri": "/v1beta/{parent=corpora/*}/permissions",
119
+ "body": "permission",
120
+ },
121
+ ]
122
+ return http_options
123
+
124
+ @staticmethod
125
+ def _get_transcoded_request(http_options, request):
126
+ pb_request = permission_service.CreatePermissionRequest.pb(request)
127
+ transcoded_request = path_template.transcode(http_options, pb_request)
128
+ return transcoded_request
129
+
130
+ @staticmethod
131
+ def _get_request_body_json(transcoded_request):
132
+ # Jsonify the request body
133
+
134
+ body = json_format.MessageToJson(
135
+ transcoded_request["body"], use_integers_for_enums=True
136
+ )
137
+ return body
138
+
139
+ @staticmethod
140
+ def _get_query_params_json(transcoded_request):
141
+ query_params = json.loads(
142
+ json_format.MessageToJson(
143
+ transcoded_request["query_params"],
144
+ use_integers_for_enums=True,
145
+ )
146
+ )
147
+ query_params.update(
148
+ _BasePermissionServiceRestTransport._BaseCreatePermission._get_unset_required_fields(
149
+ query_params
150
+ )
151
+ )
152
+
153
+ query_params["$alt"] = "json;enum-encoding=int"
154
+ return query_params
155
+
156
+ class _BaseDeletePermission:
157
+ def __hash__(self): # pragma: NO COVER
158
+ return NotImplementedError("__hash__ must be implemented.")
159
+
160
+ __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
161
+
162
+ @classmethod
163
+ def _get_unset_required_fields(cls, message_dict):
164
+ return {
165
+ k: v
166
+ for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
167
+ if k not in message_dict
168
+ }
169
+
170
+ @staticmethod
171
+ def _get_http_options():
172
+ http_options: List[Dict[str, str]] = [
173
+ {
174
+ "method": "delete",
175
+ "uri": "/v1beta/{name=tunedModels/*/permissions/*}",
176
+ },
177
+ {
178
+ "method": "delete",
179
+ "uri": "/v1beta/{name=corpora/*/permissions/*}",
180
+ },
181
+ ]
182
+ return http_options
183
+
184
+ @staticmethod
185
+ def _get_transcoded_request(http_options, request):
186
+ pb_request = permission_service.DeletePermissionRequest.pb(request)
187
+ transcoded_request = path_template.transcode(http_options, pb_request)
188
+ return transcoded_request
189
+
190
+ @staticmethod
191
+ def _get_query_params_json(transcoded_request):
192
+ query_params = json.loads(
193
+ json_format.MessageToJson(
194
+ transcoded_request["query_params"],
195
+ use_integers_for_enums=True,
196
+ )
197
+ )
198
+ query_params.update(
199
+ _BasePermissionServiceRestTransport._BaseDeletePermission._get_unset_required_fields(
200
+ query_params
201
+ )
202
+ )
203
+
204
+ query_params["$alt"] = "json;enum-encoding=int"
205
+ return query_params
206
+
207
+ class _BaseGetPermission:
208
+ def __hash__(self): # pragma: NO COVER
209
+ return NotImplementedError("__hash__ must be implemented.")
210
+
211
+ __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
212
+
213
+ @classmethod
214
+ def _get_unset_required_fields(cls, message_dict):
215
+ return {
216
+ k: v
217
+ for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
218
+ if k not in message_dict
219
+ }
220
+
221
+ @staticmethod
222
+ def _get_http_options():
223
+ http_options: List[Dict[str, str]] = [
224
+ {
225
+ "method": "get",
226
+ "uri": "/v1beta/{name=tunedModels/*/permissions/*}",
227
+ },
228
+ {
229
+ "method": "get",
230
+ "uri": "/v1beta/{name=corpora/*/permissions/*}",
231
+ },
232
+ ]
233
+ return http_options
234
+
235
+ @staticmethod
236
+ def _get_transcoded_request(http_options, request):
237
+ pb_request = permission_service.GetPermissionRequest.pb(request)
238
+ transcoded_request = path_template.transcode(http_options, pb_request)
239
+ return transcoded_request
240
+
241
+ @staticmethod
242
+ def _get_query_params_json(transcoded_request):
243
+ query_params = json.loads(
244
+ json_format.MessageToJson(
245
+ transcoded_request["query_params"],
246
+ use_integers_for_enums=True,
247
+ )
248
+ )
249
+ query_params.update(
250
+ _BasePermissionServiceRestTransport._BaseGetPermission._get_unset_required_fields(
251
+ query_params
252
+ )
253
+ )
254
+
255
+ query_params["$alt"] = "json;enum-encoding=int"
256
+ return query_params
257
+
258
+ class _BaseListPermissions:
259
+ def __hash__(self): # pragma: NO COVER
260
+ return NotImplementedError("__hash__ must be implemented.")
261
+
262
+ __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
263
+
264
+ @classmethod
265
+ def _get_unset_required_fields(cls, message_dict):
266
+ return {
267
+ k: v
268
+ for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
269
+ if k not in message_dict
270
+ }
271
+
272
+ @staticmethod
273
+ def _get_http_options():
274
+ http_options: List[Dict[str, str]] = [
275
+ {
276
+ "method": "get",
277
+ "uri": "/v1beta/{parent=tunedModels/*}/permissions",
278
+ },
279
+ {
280
+ "method": "get",
281
+ "uri": "/v1beta/{parent=corpora/*}/permissions",
282
+ },
283
+ ]
284
+ return http_options
285
+
286
+ @staticmethod
287
+ def _get_transcoded_request(http_options, request):
288
+ pb_request = permission_service.ListPermissionsRequest.pb(request)
289
+ transcoded_request = path_template.transcode(http_options, pb_request)
290
+ return transcoded_request
291
+
292
+ @staticmethod
293
+ def _get_query_params_json(transcoded_request):
294
+ query_params = json.loads(
295
+ json_format.MessageToJson(
296
+ transcoded_request["query_params"],
297
+ use_integers_for_enums=True,
298
+ )
299
+ )
300
+ query_params.update(
301
+ _BasePermissionServiceRestTransport._BaseListPermissions._get_unset_required_fields(
302
+ query_params
303
+ )
304
+ )
305
+
306
+ query_params["$alt"] = "json;enum-encoding=int"
307
+ return query_params
308
+
309
+ class _BaseTransferOwnership:
310
+ def __hash__(self): # pragma: NO COVER
311
+ return NotImplementedError("__hash__ must be implemented.")
312
+
313
+ __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
314
+
315
+ @classmethod
316
+ def _get_unset_required_fields(cls, message_dict):
317
+ return {
318
+ k: v
319
+ for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
320
+ if k not in message_dict
321
+ }
322
+
323
+ @staticmethod
324
+ def _get_http_options():
325
+ http_options: List[Dict[str, str]] = [
326
+ {
327
+ "method": "post",
328
+ "uri": "/v1beta/{name=tunedModels/*}:transferOwnership",
329
+ "body": "*",
330
+ },
331
+ ]
332
+ return http_options
333
+
334
+ @staticmethod
335
+ def _get_transcoded_request(http_options, request):
336
+ pb_request = permission_service.TransferOwnershipRequest.pb(request)
337
+ transcoded_request = path_template.transcode(http_options, pb_request)
338
+ return transcoded_request
339
+
340
+ @staticmethod
341
+ def _get_request_body_json(transcoded_request):
342
+ # Jsonify the request body
343
+
344
+ body = json_format.MessageToJson(
345
+ transcoded_request["body"], use_integers_for_enums=True
346
+ )
347
+ return body
348
+
349
+ @staticmethod
350
+ def _get_query_params_json(transcoded_request):
351
+ query_params = json.loads(
352
+ json_format.MessageToJson(
353
+ transcoded_request["query_params"],
354
+ use_integers_for_enums=True,
355
+ )
356
+ )
357
+ query_params.update(
358
+ _BasePermissionServiceRestTransport._BaseTransferOwnership._get_unset_required_fields(
359
+ query_params
360
+ )
361
+ )
362
+
363
+ query_params["$alt"] = "json;enum-encoding=int"
364
+ return query_params
365
+
366
+ class _BaseUpdatePermission:
367
+ def __hash__(self): # pragma: NO COVER
368
+ return NotImplementedError("__hash__ must be implemented.")
369
+
370
+ __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
371
+ "updateMask": {},
372
+ }
373
+
374
+ @classmethod
375
+ def _get_unset_required_fields(cls, message_dict):
376
+ return {
377
+ k: v
378
+ for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
379
+ if k not in message_dict
380
+ }
381
+
382
+ @staticmethod
383
+ def _get_http_options():
384
+ http_options: List[Dict[str, str]] = [
385
+ {
386
+ "method": "patch",
387
+ "uri": "/v1beta/{permission.name=tunedModels/*/permissions/*}",
388
+ "body": "permission",
389
+ },
390
+ {
391
+ "method": "patch",
392
+ "uri": "/v1beta/{permission.name=corpora/*/permissions/*}",
393
+ "body": "permission",
394
+ },
395
+ ]
396
+ return http_options
397
+
398
+ @staticmethod
399
+ def _get_transcoded_request(http_options, request):
400
+ pb_request = permission_service.UpdatePermissionRequest.pb(request)
401
+ transcoded_request = path_template.transcode(http_options, pb_request)
402
+ return transcoded_request
403
+
404
+ @staticmethod
405
+ def _get_request_body_json(transcoded_request):
406
+ # Jsonify the request body
407
+
408
+ body = json_format.MessageToJson(
409
+ transcoded_request["body"], use_integers_for_enums=True
410
+ )
411
+ return body
412
+
413
+ @staticmethod
414
+ def _get_query_params_json(transcoded_request):
415
+ query_params = json.loads(
416
+ json_format.MessageToJson(
417
+ transcoded_request["query_params"],
418
+ use_integers_for_enums=True,
419
+ )
420
+ )
421
+ query_params.update(
422
+ _BasePermissionServiceRestTransport._BaseUpdatePermission._get_unset_required_fields(
423
+ query_params
424
+ )
425
+ )
426
+
427
+ query_params["$alt"] = "json;enum-encoding=int"
428
+ return query_params
429
+
430
+ class _BaseGetOperation:
431
+ def __hash__(self): # pragma: NO COVER
432
+ return NotImplementedError("__hash__ must be implemented.")
433
+
434
+ @staticmethod
435
+ def _get_http_options():
436
+ http_options: List[Dict[str, str]] = [
437
+ {
438
+ "method": "get",
439
+ "uri": "/v1beta/{name=tunedModels/*/operations/*}",
440
+ },
441
+ {
442
+ "method": "get",
443
+ "uri": "/v1beta/{name=generatedFiles/*/operations/*}",
444
+ },
445
+ {
446
+ "method": "get",
447
+ "uri": "/v1beta/{name=models/*/operations/*}",
448
+ },
449
+ ]
450
+ return http_options
451
+
452
+ @staticmethod
453
+ def _get_transcoded_request(http_options, request):
454
+ request_kwargs = json_format.MessageToDict(request)
455
+ transcoded_request = path_template.transcode(http_options, **request_kwargs)
456
+ return transcoded_request
457
+
458
+ @staticmethod
459
+ def _get_query_params_json(transcoded_request):
460
+ query_params = json.loads(json.dumps(transcoded_request["query_params"]))
461
+ return query_params
462
+
463
+ class _BaseListOperations:
464
+ def __hash__(self): # pragma: NO COVER
465
+ return NotImplementedError("__hash__ must be implemented.")
466
+
467
+ @staticmethod
468
+ def _get_http_options():
469
+ http_options: List[Dict[str, str]] = [
470
+ {
471
+ "method": "get",
472
+ "uri": "/v1beta/{name=tunedModels/*}/operations",
473
+ },
474
+ {
475
+ "method": "get",
476
+ "uri": "/v1beta/{name=models/*}/operations",
477
+ },
478
+ ]
479
+ return http_options
480
+
481
+ @staticmethod
482
+ def _get_transcoded_request(http_options, request):
483
+ request_kwargs = json_format.MessageToDict(request)
484
+ transcoded_request = path_template.transcode(http_options, **request_kwargs)
485
+ return transcoded_request
486
+
487
+ @staticmethod
488
+ def _get_query_params_json(transcoded_request):
489
+ query_params = json.loads(json.dumps(transcoded_request["query_params"]))
490
+ return query_params
491
+
492
+
493
+ __all__ = ("_BasePermissionServiceRestTransport",)
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/prediction_service/__init__.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ from .async_client import PredictionServiceAsyncClient
17
+ from .client import PredictionServiceClient
18
+
19
+ __all__ = (
20
+ "PredictionServiceClient",
21
+ "PredictionServiceAsyncClient",
22
+ )
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/prediction_service/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (417 Bytes). View file
 
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/prediction_service/__pycache__/async_client.cpython-311.pyc ADDED
Binary file (23.4 kB). View file
 
.venv/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/prediction_service/__pycache__/client.cpython-311.pyc ADDED
Binary file (39.9 kB). View file