diff --git a/samples/beta/cancel_operation.py b/samples/beta/cancel_operation.py index a30fe2a4..5fa3e3c2 100644 --- a/samples/beta/cancel_operation.py +++ b/samples/beta/cancel_operation.py @@ -31,7 +31,7 @@ def sample_cancel_operation(project, operation_id): client = automl_v1beta1.AutoMlClient() - operations_client = client.transport._operations_client + operations_client = client._transport.operations_client # project = '[Google Cloud Project ID]' # operation_id = '[Operation ID]' diff --git a/samples/snippets/automl_translation_dataset.py b/samples/snippets/automl_translation_dataset.py index cf3e50ae..e1dd739a 100755 --- a/samples/snippets/automl_translation_dataset.py +++ b/samples/snippets/automl_translation_dataset.py @@ -40,7 +40,7 @@ def create_dataset(project_id, compute_region, dataset_name, source, target): client = automl.AutoMlClient() # A resource that represents Google Cloud Platform location. - project_location = client.location_path(project_id, compute_region) + project_location = f"projects/{project_id}/locations/{compute_region}" # Specify the source and target language. dataset_metadata = { @@ -54,7 +54,7 @@ def create_dataset(project_id, compute_region, dataset_name, source, target): } # Create a dataset with the dataset metadata in the region. - dataset = client.create_dataset(project_location, my_dataset) + dataset = client.create_dataset(parent=project_location, dataset=my_dataset) # Display the dataset information print("Dataset name: {}".format(dataset.name)) @@ -71,9 +71,7 @@ def create_dataset(project_id, compute_region, dataset_name, source, target): dataset.translation_dataset_metadata.target_language_code ) ) - print("Dataset create time:") - print("\tseconds: {}".format(dataset.create_time.seconds)) - print("\tnanos: {}".format(dataset.create_time.nanos)) + print("Dataset create time: {}".format(dataset.create_time)) # [END automl_translate_create_dataset] @@ -91,10 +89,11 @@ def list_datasets(project_id, compute_region, filter_): client = automl.AutoMlClient() # A resource that represents Google Cloud Platform location. - project_location = client.location_path(project_id, compute_region) + project_location = f"projects/{project_id}/locations/{compute_region}" # List all the datasets available in the region by applying filter. - response = client.list_datasets(project_location, filter_) + request = automl.ListDatasetsRequest(parent=project_location, filter=filter_) + response = client.list_datasets(request=request) print("List of datasets:") for dataset in response: @@ -113,9 +112,7 @@ def list_datasets(project_id, compute_region, filter_): dataset.translation_dataset_metadata.target_language_code ) ) - print("Dataset create time:") - print("\tseconds: {}".format(dataset.create_time.seconds)) - print("\tnanos: {}".format(dataset.create_time.nanos)) + print("Dataset create time: {}".format(dataset.create_time)) # [END automl_translate_list_datasets] @@ -138,7 +135,7 @@ def get_dataset(project_id, compute_region, dataset_id): ) # Get complete detail of the dataset. - dataset = client.get_dataset(dataset_full_id) + dataset = client.get_dataset(name=dataset_full_id) # Display the dataset information print("Dataset name: {}".format(dataset.name)) @@ -155,9 +152,7 @@ def get_dataset(project_id, compute_region, dataset_id): dataset.translation_dataset_metadata.target_language_code ) ) - print("Dataset create time:") - print("\tseconds: {}".format(dataset.create_time.seconds)) - print("\tnanos: {}".format(dataset.create_time.nanos)) + print("Dataset create time: {}".format(dataset.create_time)) # [END automl_translate_get_dataset] @@ -185,7 +180,7 @@ def import_data(project_id, compute_region, dataset_id, path): input_config = {"gcs_source": {"input_uris": input_uris}} # Import data from the input URI - response = client.import_data(dataset_full_id, input_config) + response = client.import_data(name=dataset_full_id, input_config=input_config) print("Processing import...") # synchronous check of operation status @@ -212,7 +207,7 @@ def delete_dataset(project_id, compute_region, dataset_id): ) # Delete a dataset. - response = client.delete_dataset(dataset_full_id) + response = client.delete_dataset(name=dataset_full_id) # synchronous check of operation status print("Dataset deleted. {}".format(response.result())) diff --git a/samples/snippets/automl_translation_model.py b/samples/snippets/automl_translation_model.py index 77a4ed73..4affdd40 100755 --- a/samples/snippets/automl_translation_model.py +++ b/samples/snippets/automl_translation_model.py @@ -49,7 +49,7 @@ def create_model(project_id, compute_region, dataset_id, model_name): } # Create a model with the model metadata in the region. - response = client.create_model(project_location, my_model) + response = client.create_model(parent=project_location, model=my_model) print("Training operation name: {}".format(response.operation.name)) print("Training started...") @@ -66,20 +66,20 @@ def list_models(project_id, compute_region, filter_): # filter_ = 'DATASET_ID_HERE' from google.cloud import automl_v1beta1 as automl - from google.cloud.automl_v1beta1 import enums client = automl.AutoMlClient() # A resource that represents Google Cloud Platform location. - project_location = client.location_path(project_id, compute_region) + project_location = f"projects/{project_id}/locations/{compute_region}" # List all the models available in the region by applying filter. - response = client.list_models(project_location, filter_) + request = automl.ListDatasetsRequest(parent=project_location, filter=filter_) + response = client.list_datasets(request=request) print("List of models:") for model in response: # Display the model information. - if model.deployment_state == enums.Model.DeploymentState.DEPLOYED: + if model.deployment_state == automl.Model.DeploymentState.DEPLOYED: deployment_state = "deployed" else: deployment_state = "undeployed" @@ -87,9 +87,7 @@ def list_models(project_id, compute_region, filter_): print("Model name: {}".format(model.name)) print("Model id: {}".format(model.name.split("/")[-1])) print("Model display name: {}".format(model.display_name)) - print("Model create time:") - print("\tseconds: {}".format(model.create_time.seconds)) - print("\tnanos: {}".format(model.create_time.nanos)) + print("Model create time: {}".format(model.create_time)) print("Model deployment state: {}".format(deployment_state)) # [END automl_translate_list_models] @@ -104,7 +102,6 @@ def get_model(project_id, compute_region, model_id): # model_id = 'MODEL_ID_HERE' from google.cloud import automl_v1beta1 as automl - from google.cloud.automl_v1beta1 import enums client = automl.AutoMlClient() @@ -112,10 +109,10 @@ def get_model(project_id, compute_region, model_id): model_full_id = client.model_path(project_id, compute_region, model_id) # Get complete detail of the model. - model = client.get_model(model_full_id) + model = client.get_model(name=model_full_id) # Retrieve deployment state. - if model.deployment_state == enums.Model.DeploymentState.DEPLOYED: + if model.deployment_state == automl.Model.DeploymentState.DEPLOYED: deployment_state = "deployed" else: deployment_state = "undeployed" @@ -124,9 +121,7 @@ def get_model(project_id, compute_region, model_id): print("Model name: {}".format(model.name)) print("Model id: {}".format(model.name.split("/")[-1])) print("Model display name: {}".format(model.display_name)) - print("Model create time:") - print("\tseconds: {}".format(model.create_time.seconds)) - print("\tnanos: {}".format(model.create_time.nanos)) + print("Model create time: {}".format(model.create_time)) print("Model deployment state: {}".format(deployment_state)) # [END automl_translate_get_model] @@ -149,7 +144,11 @@ def list_model_evaluations(project_id, compute_region, model_id, filter_): model_full_id = client.model_path(project_id, compute_region, model_id) print("List of model evaluations:") - for element in client.list_model_evaluations(model_full_id, filter_): + request = automl.ListModelEvaluationsRequest( + parent=model_full_id, + filter=filter_ + ) + for element in client.list_model_evaluations(request=request): print(element) # [END automl_translate_list_model_evaluations] @@ -176,7 +175,7 @@ def get_model_evaluation( ) # Get complete detail of the model evaluation. - response = client.get_model_evaluation(model_evaluation_full_id) + response = client.get_model_evaluation(name=model_evaluation_full_id) print(response) @@ -199,7 +198,7 @@ def delete_model(project_id, compute_region, model_id): model_full_id = client.model_path(project_id, compute_region, model_id) # Delete a model. - response = client.delete_model(model_full_id) + response = client.delete_model(name=model_full_id) # synchronous check of operation status. print("Model deleted. {}".format(response.result())) @@ -219,7 +218,7 @@ def get_operation_status(operation_full_id): client = automl.AutoMlClient() # Get the latest state of a long-running operation. - response = client.transport._operations_client.get_operation( + response = client._transport.operations_client.get_operation( operation_full_id ) diff --git a/samples/snippets/automl_translation_predict.py b/samples/snippets/automl_translation_predict.py index b15e0e30..70c14e36 100644 --- a/samples/snippets/automl_translation_predict.py +++ b/samples/snippets/automl_translation_predict.py @@ -56,7 +56,13 @@ def predict(project_id, compute_region, model_id, file_path): # params is additional domain-specific parameters. params = {} - response = prediction_client.predict(model_full_id, payload, params) + request = automl.PredictRequest( + name=model_full_id, + payload=payload, + params=params + ) + + response = prediction_client.predict(request=request) translated_content = response.payload[0].translation.translated_content print(u"Translated content: {}".format(translated_content.content)) diff --git a/samples/snippets/model_test.py b/samples/snippets/model_test.py index fd2fabc3..da5f806f 100644 --- a/samples/snippets/model_test.py +++ b/samples/snippets/model_test.py @@ -31,13 +31,13 @@ def test_model_create_status_delete(capsys): # create model client = automl.AutoMlClient() model_name = "test_" + datetime.datetime.now().strftime("%Y%m%d%H%M%S") - project_location = client.location_path(project_id, compute_region) + project_location = f"projects/{project_id}/locations/{compute_region}" my_model = { "display_name": model_name, "dataset_id": "3876092572857648864", "translation_model_metadata": {"base_model": ""}, } - response = client.create_model(project_location, my_model) + response = client.create_model(parent=project_location, model=my_model) operation_name = response.operation.name assert operation_name