Skip to content

Commit d7d5fdd

Browse files
authored
feat!: move to microgen (#61)
See UPGRADING.md
1 parent b2209c9 commit d7d5fdd

File tree

87 files changed

+331
-336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+331
-336
lines changed

automl/beta/batch_predict.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,27 @@ def batch_predict(
2727
prediction_client = automl.PredictionServiceClient()
2828

2929
# Get the full path of the model.
30-
model_full_id = prediction_client.model_path(
30+
model_full_id = automl.AutoMlClient.model_path(
3131
project_id, "us-central1", model_id
3232
)
3333

34-
gcs_source = automl.types.GcsSource(input_uris=[input_uri])
34+
gcs_source = automl.GcsSource(input_uris=[input_uri])
3535

36-
input_config = automl.types.BatchPredictInputConfig(gcs_source=gcs_source)
37-
gcs_destination = automl.types.GcsDestination(output_uri_prefix=output_uri)
38-
output_config = automl.types.BatchPredictOutputConfig(
36+
input_config = automl.BatchPredictInputConfig(gcs_source=gcs_source)
37+
gcs_destination = automl.GcsDestination(output_uri_prefix=output_uri)
38+
output_config = automl.BatchPredictOutputConfig(
3939
gcs_destination=gcs_destination
4040
)
4141
params = {}
4242

43+
request = automl.BatchPredictRequest(
44+
name=model_full_id,
45+
input_config=input_config,
46+
output_config=output_config,
47+
params=params
48+
)
4349
response = prediction_client.batch_predict(
44-
model_full_id, input_config, output_config, params=params
50+
request=request
4551
)
4652

4753
print("Waiting for operation to complete...")

automl/beta/cancel_operation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def sample_cancel_operation(project, operation_id):
3131

3232
client = automl_v1beta1.AutoMlClient()
3333

34-
operations_client = client.transport._operations_client
34+
operations_client = client._transport.operations_client
3535

3636
# project = '[Google Cloud Project ID]'
3737
# operation_id = '[Operation ID]'

automl/beta/delete_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def delete_dataset(project_id="YOUR_PROJECT_ID", dataset_id="YOUR_DATASET_ID"):
2424
dataset_full_id = client.dataset_path(
2525
project_id, "us-central1", dataset_id
2626
)
27-
response = client.delete_dataset(dataset_full_id)
27+
response = client.delete_dataset(name=dataset_full_id)
2828

2929
print("Dataset deleted. {}".format(response.result()))
3030
# [END automl_delete_dataset_beta]

automl/beta/delete_dataset_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
@pytest.fixture(scope="function")
2828
def dataset_id():
2929
client = automl.AutoMlClient()
30-
project_location = client.location_path(PROJECT_ID, "us-central1")
30+
project_location = f"projects/{PROJECT_ID}/locations/us-central1"
3131
display_name = "test_{}".format(uuid.uuid4()).replace("-", "")[:32]
32-
metadata = automl.types.TextExtractionDatasetMetadata()
33-
dataset = automl.types.Dataset(
32+
metadata = automl.TextExtractionDatasetMetadata()
33+
dataset = automl.Dataset(
3434
display_name=display_name, text_extraction_dataset_metadata=metadata
3535
)
36-
response = client.create_dataset(project_location, dataset)
36+
response = client.create_dataset(parent=project_location, dataset=dataset)
3737
dataset_id = response.name.split("/")[-1]
3838

3939
yield dataset_id

automl/beta/delete_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def delete_model(project_id, model_id):
2525
client = automl.AutoMlClient()
2626
# Get the full path of the model.
2727
model_full_id = client.model_path(project_id, "us-central1", model_id)
28-
response = client.delete_model(model_full_id)
28+
response = client.delete_model(name=model_full_id)
2929

3030
print("Model deleted. {}".format(response.result()))
3131
# [END automl_delete_model_beta]

automl/beta/get_model.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ def get_model(project_id, model_id):
2525
client = automl.AutoMlClient()
2626
# Get the full path of the model.
2727
model_full_id = client.model_path(project_id, "us-central1", model_id)
28-
model = client.get_model(model_full_id)
28+
model = client.get_model(name=model_full_id)
2929

3030
# Retrieve deployment state.
31-
if model.deployment_state == automl.enums.Model.DeploymentState.DEPLOYED:
31+
if model.deployment_state == automl.Model.DeploymentState.DEPLOYED:
3232
deployment_state = "deployed"
3333
else:
3434
deployment_state = "undeployed"
@@ -37,8 +37,6 @@ def get_model(project_id, model_id):
3737
print("Model name: {}".format(model.name))
3838
print("Model id: {}".format(model.name.split("/")[-1]))
3939
print("Model display name: {}".format(model.display_name))
40-
print("Model create time:")
41-
print("\tseconds: {}".format(model.create_time.seconds))
42-
print("\tnanos: {}".format(model.create_time.nanos))
40+
print("Model create time: {}".format(model.create_time))
4341
print("Model deployment state: {}".format(deployment_state))
4442
# [END automl_get_model_beta]

automl/beta/get_model_evaluation.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,15 @@ def get_model_evaluation(project_id, model_id, model_evaluation_id):
2626

2727
client = automl.AutoMlClient()
2828
# Get the full path of the model evaluation.
29-
model_evaluation_full_id = client.model_evaluation_path(
30-
project_id, "us-central1", model_id, model_evaluation_id
31-
)
29+
model_path = client.model_path(project_id, "us-central1", model_id)
30+
model_evaluation_full_id = f"{model_path}/modelEvaluations/{model_evaluation_id}"
3231

3332
# Get complete detail of the model evaluation.
34-
response = client.get_model_evaluation(model_evaluation_full_id)
33+
response = client.get_model_evaluation(name=model_evaluation_full_id)
3534

3635
print("Model evaluation name: {}".format(response.name))
3736
print("Model annotation spec id: {}".format(response.annotation_spec_id))
38-
print("Create Time:")
39-
print("\tseconds: {}".format(response.create_time.seconds))
40-
print("\tnanos: {}".format(response.create_time.nanos / 1e9))
37+
print("Create Time: {}".format(response.create_time))
4138
print(
4239
"Evaluation example count: {}".format(response.evaluated_example_count)
4340
)

automl/beta/get_model_evaluation_test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@
2727
def model_evaluation_id():
2828
client = automl.AutoMlClient()
2929
model_full_id = client.model_path(PROJECT_ID, "us-central1", MODEL_ID)
30-
generator = client.list_model_evaluations(model_full_id, "").pages
31-
page = next(generator)
32-
evaluation = page.next()
30+
request = automl.ListModelEvaluationsRequest(
31+
parent=model_full_id,
32+
filter=""
33+
)
34+
evaluations = client.list_model_evaluations(request=request)
35+
evaluation = next(iter(evaluations))
3336
model_evaluation_id = evaluation.name.split(
3437
"{}/modelEvaluations/".format(MODEL_ID)
3538
)[1].split("\n")[0]

automl/beta/get_operation_status.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def get_operation_status(
2424
client = automl.AutoMlClient()
2525

2626
# Get the latest state of a long-running operation.
27-
response = client.transport._operations_client.get_operation(
27+
response = client._transport.operations_client.get_operation(
2828
operation_full_id
2929
)
3030

automl/beta/get_operation_status_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
@pytest.fixture(scope="function")
2626
def operation_id():
2727
client = automl.AutoMlClient()
28-
project_location = client.location_path(PROJECT_ID, "us-central1")
29-
generator = client.transport._operations_client.list_operations(
28+
project_location = f"projects/{PROJECT_ID}/locations/us-central1"
29+
generator = client._transport.operations_client.list_operations(
3030
project_location, filter_=""
3131
).pages
3232
page = next(generator)

0 commit comments

Comments
 (0)