@@ -72,16 +72,19 @@ def __init__(
7272 credentials : Optional [auth_credentials .Credentials ] = None ,
7373 client_options : Optional [Union [client_options_lib .ClientOptions , dict ]] = None ,
7474 ):
75- # *ServiceClient related initializations
76- self .dataset_service_client = dataset_service .DatasetServiceClient (
77- credentials = credentials , client_options = client_options
78- )
79- self .job_service_client = job_service .JobServiceClient (
80- credentials = credentials , client_options = client_options
81- )
82- self .model_service_client = model_service .ModelServiceClient (
83- credentials = credentials , client_options = client_options
84- )
75+ # A dictionary mapping service names to their client classes.
76+ service_clients_config = {
77+ "dataset" : dataset_service .DatasetServiceClient ,
78+ "job" : job_service .JobServiceClient ,
79+ "model" : model_service .ModelServiceClient ,
80+ }
81+
82+ # Dynamically initialize service clients.
83+ for service_name , client_class in service_clients_config .items ():
84+ client_instance = client_class (
85+ credentials = credentials , client_options = client_options
86+ )
87+ setattr (self , f"{ service_name } _service_client" , client_instance )
8588
8689 def get_dataset (
8790 self ,
@@ -167,4 +170,3 @@ def list_models(
167170 """
168171 kwargs = _drop_self_key (locals ())
169172 return self .model_service_client .list_models (** kwargs )
170-
0 commit comments