-
Notifications
You must be signed in to change notification settings - Fork 449
Expand file tree
/
Copy path__init__.py
More file actions
1200 lines (1001 loc) · 40.3 KB
/
__init__.py
File metadata and controls
1200 lines (1001 loc) · 40.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import abc
import datetime
import pathlib
import logging
import re
from typing import Any, Callable, Dict, Optional, Type, TypeVar, Tuple, List
import uuid
from google.protobuf import timestamp_pb2
from google.api_core import client_options
from google.api_core import gapic_v1
from google.auth import credentials as auth_credentials
from google.cloud import storage
from google.cloud.aiplatform import compat
from google.cloud.aiplatform.constants import base as constants
from google.cloud.aiplatform import initializer
from google.cloud.aiplatform.compat.services import (
dataset_service_client_v1beta1,
deployment_resource_pool_service_client_v1beta1,
endpoint_service_client_v1beta1,
example_store_service_client_v1beta1,
extension_execution_service_client_v1beta1,
extension_registry_service_client_v1beta1,
feature_online_store_admin_service_client_v1beta1,
feature_online_store_service_client_v1beta1,
feature_registry_service_client_v1beta1,
featurestore_online_serving_service_client_v1beta1,
featurestore_service_client_v1beta1,
gen_ai_cache_service_client_v1beta1,
index_service_client_v1beta1,
index_endpoint_service_client_v1beta1,
job_service_client_v1beta1,
match_service_client_v1beta1,
metadata_service_client_v1beta1,
model_service_client_v1beta1,
model_monitoring_service_client_v1beta1,
pipeline_service_client_v1beta1,
prediction_service_client_v1beta1,
prediction_service_async_client_v1beta1,
schedule_service_client_v1beta1,
tensorboard_service_client_v1beta1,
vizier_service_client_v1beta1,
model_garden_service_client_v1beta1,
persistent_resource_service_client_v1beta1,
reasoning_engine_service_client_v1beta1,
reasoning_engine_execution_service_client_v1beta1,
vertex_rag_data_service_async_client_v1beta1,
vertex_rag_data_service_client_v1beta1,
vertex_rag_service_client_v1beta1,
)
from google.cloud.aiplatform.compat.services import (
dataset_service_client_v1,
deployment_resource_pool_service_client_v1,
endpoint_service_client_v1,
feature_online_store_admin_service_client_v1,
feature_online_store_service_client_v1,
feature_registry_service_client_v1,
featurestore_online_serving_service_client_v1,
featurestore_service_client_v1,
gen_ai_cache_service_client_v1,
index_service_client_v1,
index_endpoint_service_client_v1,
job_service_client_v1,
metadata_service_client_v1,
model_garden_service_client_v1,
model_service_client_v1,
pipeline_service_client_v1,
prediction_service_client_v1,
prediction_service_async_client_v1,
reasoning_engine_service_client_v1,
reasoning_engine_execution_service_client_v1,
reasoning_engine_execution_async_client_v1,
schedule_service_client_v1,
tensorboard_service_client_v1,
vizier_service_client_v1,
persistent_resource_service_client_v1,
vertex_rag_data_service_async_client_v1,
vertex_rag_data_service_client_v1,
vertex_rag_service_client_v1,
)
from google.cloud.aiplatform.compat.types import (
accelerator_type as gca_accelerator_type,
reservation_affinity_v1 as gca_reservation_affinity_v1,
)
VertexAiServiceClient = TypeVar(
"VertexAiServiceClient",
# v1beta1
dataset_service_client_v1beta1.DatasetServiceClient,
deployment_resource_pool_service_client_v1beta1.DeploymentResourcePoolServiceClient,
endpoint_service_client_v1beta1.EndpointServiceClient,
feature_online_store_admin_service_client_v1beta1.FeatureOnlineStoreAdminServiceClient,
feature_online_store_service_client_v1beta1.FeatureOnlineStoreServiceClient,
feature_registry_service_client_v1beta1.FeatureRegistryServiceClient,
featurestore_online_serving_service_client_v1beta1.FeaturestoreOnlineServingServiceClient,
featurestore_service_client_v1beta1.FeaturestoreServiceClient,
index_service_client_v1beta1.IndexServiceClient,
index_endpoint_service_client_v1beta1.IndexEndpointServiceClient,
model_service_client_v1beta1.ModelServiceClient,
model_monitoring_service_client_v1beta1.ModelMonitoringServiceClient,
prediction_service_client_v1beta1.PredictionServiceClient,
prediction_service_async_client_v1beta1.PredictionServiceAsyncClient,
pipeline_service_client_v1beta1.PipelineServiceClient,
job_service_client_v1beta1.JobServiceClient,
match_service_client_v1beta1.MatchServiceClient,
metadata_service_client_v1beta1.MetadataServiceClient,
schedule_service_client_v1beta1.ScheduleServiceClient,
tensorboard_service_client_v1beta1.TensorboardServiceClient,
vizier_service_client_v1beta1.VizierServiceClient,
# v1
dataset_service_client_v1.DatasetServiceClient,
endpoint_service_client_v1.EndpointServiceClient,
feature_online_store_admin_service_client_v1.FeatureOnlineStoreAdminServiceClient,
feature_online_store_service_client_v1.FeatureOnlineStoreServiceClient,
feature_registry_service_client_v1.FeatureRegistryServiceClient,
featurestore_online_serving_service_client_v1.FeaturestoreOnlineServingServiceClient,
featurestore_service_client_v1.FeaturestoreServiceClient,
metadata_service_client_v1.MetadataServiceClient,
model_service_client_v1.ModelServiceClient,
prediction_service_client_v1.PredictionServiceClient,
prediction_service_async_client_v1.PredictionServiceAsyncClient,
pipeline_service_client_v1.PipelineServiceClient,
job_service_client_v1.JobServiceClient,
schedule_service_client_v1.ScheduleServiceClient,
tensorboard_service_client_v1.TensorboardServiceClient,
vizier_service_client_v1.VizierServiceClient,
vertex_rag_service_client_v1.VertexRagServiceClient,
vertex_rag_data_service_async_client_v1.VertexRagDataServiceAsyncClient,
vertex_rag_data_service_client_v1.VertexRagDataServiceClient,
)
RESOURCE_ID_PATTERN = re.compile(r"^[\w-]+$")
def validate_id(resource_id: str):
"""Validate resource ID.
Args:
resource_id (str): Resource id.
Raises:
ValueError: If resource id is not a valid format.
"""
if not RESOURCE_ID_PATTERN.match(resource_id):
raise ValueError(f"Resource {resource_id} is not a valid resource id.")
def full_resource_name(
resource_name: str,
resource_noun: str,
parse_resource_name_method: Callable[[str], Dict[str, str]],
format_resource_name_method: Callable[..., str],
parent_resource_name_fields: Optional[Dict[str, str]] = None,
project: Optional[str] = None,
location: Optional[str] = None,
resource_id_validator: Optional[Callable[[str], None]] = None,
) -> str:
"""Returns fully qualified resource name.
Args:
resource_name (str):
Required. A fully-qualified Vertex AI resource name or
resource ID.
resource_noun (str):
Required. A resource noun to validate the resource name against.
For example, you would pass "datasets" to validate
"projects/123/locations/us-central1/datasets/456".
parse_resource_name_method (Callable[[str], Dict[str,str]]):
Required. Method that parses a resource name into its segment parts.
These are generally included with GAPIC clients.
format_resource_name_method (Callable[..., str]):
Required. Method that takes segment parts of resource names and returns
the formated resource name. These are generally included with GAPIC clients.
parent_resource_name_fields (Dict[str, str]):
Optional. Dictionary of segment parts where key is the resource noun and
values are the resource ids.
For example:
{
"metadataStores": "123"
}
project (str):
Optional. project to retrieve resource_noun from. If not set, project
set in aiplatform.init will be used.
location (str):
Optional. location to retrieve resource_noun from. If not set, location
set in aiplatform.init will be used.
resource_id_validator (Callable[str, None]):
Optional. Function that validates the resource ID. Overrides the default validator, validate_id.
Should take a resource ID as string and raise ValueError if invalid.
Returns:
resource_name (str):
A fully-qualified Vertex AI resource name.
"""
# Fully qualified resource name, e.g., "projects/.../locations/.../datasets/12345" or
# "projects/.../locations/.../metadataStores/.../contexts/12345"
fields = parse_resource_name_method(resource_name)
if fields:
return resource_name
resource_id_validator = resource_id_validator or validate_id
user_project = project or initializer.global_config.project
user_location = location or initializer.global_config.location
validate_region(user_location)
resource_id_validator(resource_name)
format_args = {
"location": user_location,
"project": user_project,
convert_camel_case_resource_noun_to_snake_case(resource_noun): resource_name,
}
if parent_resource_name_fields:
format_args.update(
{
convert_camel_case_resource_noun_to_snake_case(key): value
for key, value in parent_resource_name_fields.items()
}
)
return format_resource_name_method(**format_args)
# Resource nouns that are not plural in their resource names.
# Userd below to avoid conversion from plural to singular.
_SINGULAR_RESOURCE_NOUNS = {"time_series"}
_SINGULAR_RESOURCE_NOUNS_MAP = {"indexes": "index"}
def convert_camel_case_resource_noun_to_snake_case(resource_noun: str) -> str:
"""Converts camel case to snake case to map resource name parts to GAPIC parameter names.
Args:
resource_noun (str): The resource noun in camel case to covert.
Returns:
Singular snake case resource noun.
"""
snake_case = re.sub("([A-Z]+)", r"_\1", resource_noun).lower()
# plural to singular
if snake_case in _SINGULAR_RESOURCE_NOUNS or not snake_case.endswith("s"):
return snake_case
elif snake_case in _SINGULAR_RESOURCE_NOUNS_MAP:
return _SINGULAR_RESOURCE_NOUNS_MAP[snake_case]
else:
return snake_case[:-1]
def validate_display_name(display_name: str):
"""Verify display name is at most 128 chars.
Args:
display_name: display name to verify
Raises:
ValueError: display name is longer than 128 characters
"""
if len(display_name) > 128:
raise ValueError("Display name needs to be less than 128 characters.")
def validate_labels(labels: Dict[str, str]):
"""Validate labels.
Args:
labels: labels to verify
Raises:
ValueError: if labels is not a mapping of string key value pairs.
"""
for k, v in labels.items():
if not isinstance(k, str) or not isinstance(v, str):
raise ValueError(
"Expect labels to be a mapping of string key value pairs. "
'Got "{}".'.format(labels)
)
def validate_region(
region: str,
api_endpoint: Optional[str] = None,
universe_domain: Optional[str] = None,
) -> bool:
"""Validates region against supported regions.
Args:
region: region to validate
api_endpoint: Optional API endpoint.
universe_domain: Optional universe domain.
Returns:
bool: True if no errors raised
Raises:
ValueError: If region is not in supported regions.
"""
if not region:
raise ValueError(
f"Please provide a region, select from {constants.SUPPORTED_REGIONS}"
)
region = region.lower()
if region not in constants.SUPPORTED_REGIONS:
if not (
api_endpoint
or universe_domain
or initializer.global_config.api_endpoint
or initializer.global_config.universe_domain
):
raise ValueError(
"Unsupported region for Vertex AI, select from"
f" {constants.SUPPORTED_REGIONS}"
)
return True
def validate_accelerator_type(accelerator_type: str) -> bool:
"""Validates user provided accelerator_type string for training and
prediction.
Args:
accelerator_type (str):
Represents a hardware accelerator type.
Returns:
bool: True if valid accelerator_type
Raises:
ValueError if accelerator type is invalid.
"""
if accelerator_type not in gca_accelerator_type.AcceleratorType._member_names_:
raise ValueError(
f"Given accelerator_type `{accelerator_type}` invalid. "
f"Choose one of {gca_accelerator_type.AcceleratorType._member_names_}"
)
return True
def extract_bucket_and_prefix_from_gcs_path(gcs_path: str) -> Tuple[str, Optional[str]]:
"""Given a complete GCS path, return the bucket name and prefix as a tuple.
Example Usage:
bucket, prefix = extract_bucket_and_prefix_from_gcs_path(
"gs://example-bucket/path/to/folder"
)
# bucket = "example-bucket"
# prefix = "path/to/folder"
Args:
gcs_path (str):
Required. A full path to a Google Cloud Storage folder or resource.
Can optionally include "gs://" prefix or end in a trailing slash "/".
Returns:
Tuple[str, Optional[str]]
A (bucket, prefix) pair from provided GCS path. If a prefix is not
present, a None will be returned in its place.
"""
if gcs_path.startswith("gs://"):
gcs_path = gcs_path[5:]
if gcs_path.endswith("/"):
gcs_path = gcs_path[:-1]
gcs_parts = gcs_path.split("/", 1)
gcs_bucket = gcs_parts[0]
gcs_blob_prefix = None if len(gcs_parts) == 1 else gcs_parts[1]
return (gcs_bucket, gcs_blob_prefix)
def extract_project_and_location_from_parent(
parent: str,
) -> Dict[str, str]:
"""Given a complete parent resource name, return the project and location as a dict.
Example Usage:
parent_resources = extract_project_and_location_from_parent(
"projects/123/locations/us-central1/datasets/456"
)
parent_resources["project"] = "123"
parent_resources["location"] = "us-central1"
Args:
parent (str):
Required. A complete parent resource name.
Returns:
Dict[str, str]
A project, location dict from provided parent resource name.
"""
parent_resources = re.match(
r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)(/|$)", parent
)
return parent_resources.groupdict() if parent_resources else {}
def get_reservation_affinity(
reservation_affinity_type: str,
reservation_affinity_key: Optional[str] = None,
reservation_affinity_values: Optional[List[str]] = None,
) -> gca_reservation_affinity_v1.ReservationAffinity:
"""Given reservation affinity type and/or key, values, return a ReservationAffinity object.
Args:
reservation_affinity_type (str):
Required. The type of reservation affinity.
One of NO_RESERVATION, ANY_RESERVATION, SPECIFIC_RESERVATION,
SPECIFIC_THEN_ANY_RESERVATION, SPECIFIC_THEN_NO_RESERVATION
reservation_affinity_key (str):
Optional. Corresponds to the label key of a reservation resource.
To target a SPECIFIC_RESERVATION by name, use `compute.googleapis.com/reservation-name` as the key
and specify the name of your reservation as its value.
reservation_affinity_values (List[str]):
Optional. Corresponds to the label values of a reservation resource.
This must be the full resource name of the reservation.
Format: 'projects/{project_id_or_number}/zones/{zone}/reservations/{reservation_name}'
Returns:
gca_reservation_affinity_v1.ReservationAffinity
Raises:
ValueError:
If reservation_affinity_key and reservation_affinity_values are not
specified when reservation_affinity_type is SPECIFIC_RESERVATION.
"""
if reservation_affinity_type == "SPECIFIC_RESERVATION":
if not reservation_affinity_key or not reservation_affinity_values:
raise ValueError(
"reservation_affinity_key and reservation_affinity_values must be "
"specified when reservation_affinity_type is SPECIFIC_RESERVATION."
)
return gca_reservation_affinity_v1.ReservationAffinity(
reservation_affinity_type=reservation_affinity_type,
key=reservation_affinity_key,
values=reservation_affinity_values,
)
else:
return gca_reservation_affinity_v1.ReservationAffinity(
reservation_affinity_type=reservation_affinity_type,
)
class ClientWithOverride:
class WrappedClient:
"""Wrapper class for client that creates client at API invocation
time."""
def __init__(
self,
client_class: Type[VertexAiServiceClient],
client_options: client_options.ClientOptions,
client_info: gapic_v1.client_info.ClientInfo,
credentials: Optional[auth_credentials.Credentials] = None,
transport: Optional[str] = None,
):
"""Stores parameters needed to instantiate client.
Args:
client_class (VertexAiServiceClient):
Required. Class of the client to use.
client_options (client_options.ClientOptions):
Required. Client options to pass to client.
client_info (gapic_v1.client_info.ClientInfo):
Required. Client info to pass to client.
credentials (auth_credentials.credentials):
Optional. Client credentials to pass to client.
transport (str):
Optional. Transport type to pass to client.
NOTE: "rest" transport functionality is currently in a
beta state (preview).
"""
self._client_class = client_class
self._credentials = credentials
self._client_options = client_options
self._client_info = client_info
self._api_transport = transport
def __getattr__(self, name: str) -> Any:
"""Instantiates client and returns attribute of the client."""
kwargs = dict(
credentials=self._credentials,
client_options=self._client_options,
client_info=self._client_info,
)
if self._api_transport is not None:
kwargs["transport"] = self._api_transport
temporary_client = self._client_class(**kwargs)
return getattr(temporary_client, name)
@property
@abc.abstractmethod
def _is_temporary(self) -> bool:
pass
@property
@classmethod
@abc.abstractmethod
def _default_version(self) -> str:
pass
@property
@classmethod
@abc.abstractmethod
def _version_map(self) -> Tuple:
pass
@property
def api_endpoint(self) -> str:
"""Default API endpoint used by this client."""
client = self._clients[self._default_version]
if self._is_temporary:
return client._client_options.api_endpoint
else:
return client._transport._host.split(":")[0]
def __init__(
self,
client_options: client_options.ClientOptions,
client_info: gapic_v1.client_info.ClientInfo,
credentials: Optional[auth_credentials.Credentials] = None,
transport: Optional[str] = None,
):
"""Stores parameters needed to instantiate client.
Args:
client_options (client_options.ClientOptions):
Required. Client options to pass to client.
client_info (gapic_v1.client_info.ClientInfo):
Required. Client info to pass to client.
credentials (auth_credentials.credentials):
Optional. Client credentials to pass to client.
transport (str):
Optional. Transport type to pass to client.
NOTE: "rest" transport functionality is currently in a
beta state (preview).
"""
kwargs = dict(
credentials=credentials,
client_options=client_options,
client_info=client_info,
)
if transport is not None:
kwargs["transport"] = transport
self._clients = {
version: (
self.WrappedClient(
client_class=client_class,
client_options=client_options,
client_info=client_info,
credentials=credentials,
transport=transport,
)
if self._is_temporary
else client_class(**kwargs)
)
for version, client_class in self._version_map
}
def __getattr__(self, name: str) -> Any:
"""Instantiates client and returns attribute of the client."""
return getattr(self._clients[self._default_version], name)
def select_version(self, version: str) -> VertexAiServiceClient:
return self._clients[version]
@classmethod
def get_gapic_client_class(
cls, version: Optional[str] = None
) -> Type[VertexAiServiceClient]:
"""Gets the underyilng GAPIC client.
Used to access class and static methods without instantiating.
Args:
version (str):
Optional. Version of client to retreive otherwise the default version is returned.
Retuns:
Underlying GAPIC client for this wrapper and version.
"""
return dict(cls._version_map)[version or cls._default_version]
class DatasetClientWithOverride(ClientWithOverride):
_is_temporary = True
_default_version = compat.DEFAULT_VERSION
_version_map = (
(compat.V1, dataset_service_client_v1.DatasetServiceClient),
(compat.V1BETA1, dataset_service_client_v1beta1.DatasetServiceClient),
)
class DeploymentResourcePoolClientWithOverride(ClientWithOverride):
_is_temporary = True
_default_version = compat.DEFAULT_VERSION
_version_map = (
(
compat.V1BETA1,
deployment_resource_pool_service_client_v1beta1.DeploymentResourcePoolServiceClient,
),
(
compat.V1,
deployment_resource_pool_service_client_v1.DeploymentResourcePoolServiceClient,
),
)
class EndpointClientWithOverride(ClientWithOverride):
_is_temporary = True
_default_version = compat.DEFAULT_VERSION
_version_map = (
(compat.V1, endpoint_service_client_v1.EndpointServiceClient),
(compat.V1BETA1, endpoint_service_client_v1beta1.EndpointServiceClient),
)
class ExtensionExecutionClientWithOverride(ClientWithOverride):
_is_temporary = True
_default_version = compat.V1BETA1
_version_map = (
(
compat.V1BETA1,
extension_execution_service_client_v1beta1.ExtensionExecutionServiceClient,
),
)
class ExtensionRegistryClientWithOverride(ClientWithOverride):
_is_temporary = True
_default_version = compat.V1BETA1
_version_map = (
(
compat.V1BETA1,
extension_registry_service_client_v1beta1.ExtensionRegistryServiceClient,
),
)
class IndexClientWithOverride(ClientWithOverride):
_is_temporary = True
_default_version = compat.DEFAULT_VERSION
_version_map = (
(compat.V1, index_service_client_v1.IndexServiceClient),
(compat.V1BETA1, index_service_client_v1beta1.IndexServiceClient),
)
class IndexEndpointClientWithOverride(ClientWithOverride):
_is_temporary = True
_default_version = compat.DEFAULT_VERSION
_version_map = (
(compat.V1, index_endpoint_service_client_v1.IndexEndpointServiceClient),
(
compat.V1BETA1,
index_endpoint_service_client_v1beta1.IndexEndpointServiceClient,
),
)
class FeatureOnlineStoreAdminClientWithOverride(ClientWithOverride):
_is_temporary = True
_default_version = compat.DEFAULT_VERSION
_version_map = (
(
compat.V1,
feature_online_store_admin_service_client_v1.FeatureOnlineStoreAdminServiceClient,
),
(
compat.V1BETA1,
feature_online_store_admin_service_client_v1beta1.FeatureOnlineStoreAdminServiceClient,
),
)
class FeatureOnlineStoreClientWithOverride(ClientWithOverride):
_is_temporary = True
_default_version = compat.DEFAULT_VERSION
_version_map = (
(
compat.V1,
feature_online_store_service_client_v1.FeatureOnlineStoreServiceClient,
),
(
compat.V1BETA1,
feature_online_store_service_client_v1beta1.FeatureOnlineStoreServiceClient,
),
)
class FeatureRegistryClientWithOverride(ClientWithOverride):
"""Adds function override for client classes to support new Feature Store.
`feature_path()` and `parse_feature_path()` are overriden here to compensate
for the auto-generated GAPIC class which only supports Feature Store
Legacy's feature paths.
"""
@staticmethod
def feature_path(
project: str,
location: str,
feature_group: str,
feature: str,
) -> str:
return "projects/{project}/locations/{location}/featureGroups/{feature_group}/features/{feature}".format(
project=project,
location=location,
feature_group=feature_group,
feature=feature,
)
@staticmethod
def parse_feature_path(path: str) -> Dict[str, str]:
"""Parses a feature path into its component segments."""
m = re.match(
r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/featureGroups/(?P<feature_group>.+?)/features/(?P<feature>.+?)$",
path,
)
return m.groupdict() if m else {}
class FeatureRegistryServiceClientV1(
feature_registry_service_client_v1.FeatureRegistryServiceClient
):
@staticmethod
def feature_path(project: str, location: str, feature_group: str, feature: str):
return FeatureRegistryClientWithOverride.feature_path(
project, location, feature_group, feature
)
@staticmethod
def parse_feature_path(path: str) -> Dict[str, str]:
return FeatureRegistryClientWithOverride.parse_feature_path(path)
class FeatureRegistryServiceClientV1Beta1(
feature_registry_service_client_v1beta1.FeatureRegistryServiceClient
):
@staticmethod
def feature_path(project: str, location: str, feature_group: str, feature: str):
return FeatureRegistryClientWithOverride.feature_path(
project, location, feature_group, feature
)
@staticmethod
def parse_feature_path(path: str) -> Dict[str, str]:
return FeatureRegistryClientWithOverride.parse_feature_path(path)
_is_temporary = True
_default_version = compat.DEFAULT_VERSION
_version_map = (
(
compat.V1,
FeatureRegistryServiceClientV1,
),
(
compat.V1BETA1,
FeatureRegistryServiceClientV1Beta1,
),
)
class FeatureRegistryClientV1Beta1WithOverride(FeatureRegistryClientWithOverride):
"""Adds function override for v1beta1 client classes to support new Feature Store."""
_default_version = compat.V1BETA1
class FeaturestoreClientWithOverride(ClientWithOverride):
_is_temporary = True
_default_version = compat.DEFAULT_VERSION
_version_map = (
(compat.V1, featurestore_service_client_v1.FeaturestoreServiceClient),
(compat.V1BETA1, featurestore_service_client_v1beta1.FeaturestoreServiceClient),
)
class FeaturestoreOnlineServingClientWithOverride(ClientWithOverride):
_is_temporary = False
_default_version = compat.DEFAULT_VERSION
_version_map = (
(
compat.V1,
featurestore_online_serving_service_client_v1.FeaturestoreOnlineServingServiceClient,
),
(
compat.V1BETA1,
featurestore_online_serving_service_client_v1beta1.FeaturestoreOnlineServingServiceClient,
),
)
class GenAiCacheServiceClientWithOverride(ClientWithOverride):
_is_temporary = True
_default_version = compat.DEFAULT_VERSION
_version_map = (
(
compat.V1,
gen_ai_cache_service_client_v1.GenAiCacheServiceClient,
),
(
compat.V1BETA1,
gen_ai_cache_service_client_v1beta1.GenAiCacheServiceClient,
),
)
class JobClientWithOverride(ClientWithOverride):
_is_temporary = True
_default_version = compat.DEFAULT_VERSION
_version_map = (
(compat.V1, job_service_client_v1.JobServiceClient),
(compat.V1BETA1, job_service_client_v1beta1.JobServiceClient),
)
class ModelClientWithOverride(ClientWithOverride):
_is_temporary = True
_default_version = compat.DEFAULT_VERSION
_version_map = (
(compat.V1, model_service_client_v1.ModelServiceClient),
(compat.V1BETA1, model_service_client_v1beta1.ModelServiceClient),
)
class PipelineClientWithOverride(ClientWithOverride):
_is_temporary = True
_default_version = compat.DEFAULT_VERSION
_version_map = (
(compat.V1, pipeline_service_client_v1.PipelineServiceClient),
(compat.V1BETA1, pipeline_service_client_v1beta1.PipelineServiceClient),
)
class PipelineJobClientWithOverride(ClientWithOverride):
_is_temporary = True
_default_version = compat.DEFAULT_VERSION
_version_map = (
(compat.V1, pipeline_service_client_v1.PipelineServiceClient),
(compat.V1BETA1, pipeline_service_client_v1beta1.PipelineServiceClient),
)
class ScheduleClientWithOverride(ClientWithOverride):
_is_temporary = True
_default_version = compat.DEFAULT_VERSION
_version_map = (
(compat.V1, schedule_service_client_v1.ScheduleServiceClient),
(compat.V1BETA1, schedule_service_client_v1beta1.ScheduleServiceClient),
)
class PredictionClientWithOverride(ClientWithOverride):
_is_temporary = False
_default_version = compat.DEFAULT_VERSION
_version_map = (
(compat.V1, prediction_service_client_v1.PredictionServiceClient),
(compat.V1BETA1, prediction_service_client_v1beta1.PredictionServiceClient),
)
class PredictionAsyncClientWithOverride(ClientWithOverride):
_is_temporary = False
_default_version = compat.DEFAULT_VERSION
_version_map = (
(compat.V1, prediction_service_async_client_v1.PredictionServiceAsyncClient),
(
compat.V1BETA1,
prediction_service_async_client_v1beta1.PredictionServiceAsyncClient,
),
)
class MatchClientWithOverride(ClientWithOverride):
_is_temporary = False
_default_version = compat.V1BETA1
_version_map = ((compat.V1BETA1, match_service_client_v1beta1.MatchServiceClient),)
class MetadataClientWithOverride(ClientWithOverride):
_is_temporary = True
_default_version = compat.DEFAULT_VERSION
_version_map = (
(compat.V1, metadata_service_client_v1.MetadataServiceClient),
(compat.V1BETA1, metadata_service_client_v1beta1.MetadataServiceClient),
)
class ModelMonitoringClientWithOverride(ClientWithOverride):
_is_temporary = True
_default_version = compat.V1BETA1
_version_map = (
(
compat.V1BETA1,
model_monitoring_service_client_v1beta1.ModelMonitoringServiceClient,
),
)
class TensorboardClientWithOverride(ClientWithOverride):
_is_temporary = False
_default_version = compat.DEFAULT_VERSION
_version_map = (
(compat.V1, tensorboard_service_client_v1.TensorboardServiceClient),
(compat.V1BETA1, tensorboard_service_client_v1beta1.TensorboardServiceClient),
)
class VizierClientWithOverride(ClientWithOverride):
_is_temporary = True
_default_version = compat.DEFAULT_VERSION
_version_map = (
(compat.V1, vizier_service_client_v1.VizierServiceClient),
(compat.V1BETA1, vizier_service_client_v1beta1.VizierServiceClient),
)
class ModelGardenClientWithOverride(ClientWithOverride):
_is_temporary = True
_default_version = compat.DEFAULT_VERSION
_version_map = (
(compat.V1, model_garden_service_client_v1.ModelGardenServiceClient),
(compat.V1BETA1, model_garden_service_client_v1beta1.ModelGardenServiceClient),
)
class PersistentResourceClientWithOverride(ClientWithOverride):
_is_temporary = True
_default_version = compat.DEFAULT_VERSION
_version_map = (
(
compat.V1,
persistent_resource_service_client_v1.PersistentResourceServiceClient,
),
(
compat.V1BETA1,
persistent_resource_service_client_v1beta1.PersistentResourceServiceClient,
),
)
class ExampleStoreClientWithOverride(ClientWithOverride):
_is_temporary = True
_default_version = compat.V1BETA1
_version_map = (
(
compat.V1BETA1,
example_store_service_client_v1beta1.ExampleStoreServiceClient,
),
)
class ReasoningEngineClientWithOverride(ClientWithOverride):
_is_temporary = True
_default_version = compat.V1BETA1
_version_map = (
(
compat.V1BETA1,
reasoning_engine_service_client_v1beta1.ReasoningEngineServiceClient,
),
)
class ReasoningEngineExecutionClientWithOverride(ClientWithOverride):
_is_temporary = True
_default_version = compat.V1BETA1
_version_map = (
(
compat.V1BETA1,
reasoning_engine_execution_service_client_v1beta1.ReasoningEngineExecutionServiceClient,