diff --git a/sdk/documenttranslation/azure-ai-documenttranslation/azure/ai/documenttranslation/__init__.py b/sdk/documenttranslation/azure-ai-documenttranslation/azure/ai/documenttranslation/__init__.py index 0469a9ddeb5e..6aa71f6e8164 100644 --- a/sdk/documenttranslation/azure-ai-documenttranslation/azure/ai/documenttranslation/__init__.py +++ b/sdk/documenttranslation/azure-ai-documenttranslation/azure/ai/documenttranslation/__init__.py @@ -26,7 +26,7 @@ __all__ = [ "DocumentTranslationClient", "DocumentTranslationVersion", - "BatchTranslationInput", + "BatchDocumentInput", "TranslationGlossary", "StorageInputType", "FileFormat", diff --git a/sdk/documenttranslation/azure-ai-documenttranslation/azure/ai/documenttranslation/_models.py b/sdk/documenttranslation/azure-ai-documenttranslation/azure/ai/documenttranslation/_models.py index 9557d78eb13f..e5928093c103 100644 --- a/sdk/documenttranslation/azure-ai-documenttranslation/azure/ai/documenttranslation/_models.py +++ b/sdk/documenttranslation/azure-ai-documenttranslation/azure/ai/documenttranslation/_models.py @@ -61,7 +61,7 @@ def __init__( self.storage_source = kwargs.get("storage_source", None) -class BatchTranslationInput(object): +class BatchDocumentInput(object): """Definition for the input batch translation request. :param source_url: Required. Location of the folder / container or single file with your diff --git a/sdk/documenttranslation/azure-ai-documenttranslation/samples/sample_azure_storage.py b/sdk/documenttranslation/azure-ai-documenttranslation/samples/sample_azure_storage.py index 65886cb83258..6501fa7b4d06 100644 --- a/sdk/documenttranslation/azure-ai-documenttranslation/samples/sample_azure_storage.py +++ b/sdk/documenttranslation/azure-ai-documenttranslation/samples/sample_azure_storage.py @@ -10,7 +10,7 @@ def batch_translation_with_storage(): from azure.core.credentials import AzureKeyCredential from azure.ai.documenttranslation import ( DocumentTranslationClient, - BatchTranslationInput, + BatchDocumentInput, StorageTarget ) from azure.storage.blob import ContainerClient, generate_container_sas, ContainerSasPermissions @@ -26,7 +26,7 @@ def batch_translation_with_storage(): target_storage_container_name = os.environ["AZURE_STORAGE_TARGET_CONTAINER_NAME"] target_storage_key = os.environ["AZURE_STORAGE_TARGET_KEY"] - batch_client = DocumentTranslationClient( + translation_client = DocumentTranslationClient( endpoint, AzureKeyCredential(key) ) @@ -57,7 +57,7 @@ def batch_translation_with_storage(): target_container_url = target_storage_endpoint + "/" + target_storage_container_name + "?" + target_container_sas batch = [ - BatchTranslationInput( + BatchDocumentInput( source_url=source_container_url, source_language="en", targets=[ @@ -70,18 +70,18 @@ def batch_translation_with_storage(): ) ] - batch_detail = batch_client.create_batch(batch) - batch_result = batch_client.wait_until_done(batch_detail.id) + job_detail = translation_client.create_translation_job(batch) + job_result = translation_client.wait_until_done(job_detail.id) - if batch_result.status == "Succeeded": + if job_result.status == "Succeeded": print("We translated our documents!") - if batch_result.documents_failed_count > 0: - check_documents(batch_client, batch_result.id) + if job_result.documents_failed_count > 0: + check_documents(translation_client, job_result.id) - if batch_result.status in ["Failed", "ValidationFailed"]: - if batch_result.error: - print("Batch failed: {}: {}".format(batch_result.error.code, batch_result.error.message)) - check_documents(batch_client, batch_result.id) + if job_result.status in ["Failed", "ValidationFailed"]: + if job_result.error: + print("Translation job failed: {}: {}".format(job_result.error.code, job_result.error.message)) + check_documents(translation_client, job_result.id) exit(1) container_client = ContainerClient( @@ -97,11 +97,11 @@ def batch_translation_with_storage(): my_blob.write(download_stream.readall()) -def check_documents(client, batch_id): +def check_documents(client, job_id): from azure.core.exceptions import ResourceNotFoundError try: - doc_statuses = client.list_documents_statuses(batch_id) # type: ItemPaged[DocumentStatusDetail] + doc_statuses = client.list_documents_statuses(job_id) # type: ItemPaged[DocumentStatusDetail] except ResourceNotFoundError as err: print("Failed to process any documents in source/target container.") raise err diff --git a/sdk/documenttranslation/azure-ai-documenttranslation/samples/sample_cancel_batch.py b/sdk/documenttranslation/azure-ai-documenttranslation/samples/sample_cancel_batch.py deleted file mode 100644 index cd97ebc878d3..000000000000 --- a/sdk/documenttranslation/azure-ai-documenttranslation/samples/sample_cancel_batch.py +++ /dev/null @@ -1,47 +0,0 @@ -# coding=utf-8 -# ------------------------------------ -# Copyright (c) Microsoft Corporation. -# Licensed under the MIT License. -# ------------------------------------ - - -def sample_cancel_batch(): - import os - from azure.core.credentials import AzureKeyCredential - from azure.ai.documenttranslation import ( - DocumentTranslationClient, - BatchTranslationInput, - StorageTarget - ) - - endpoint = os.environ["AZURE_DOCUMENT_TRANSLATION_ENDPOINT"] - key = os.environ["AZURE_DOCUMENT_TRANSLATION_KEY"] - source_container_url = os.environ["AZURE_SOURCE_CONTAINER_URL"] - target_container_url_es = os.environ["AZURE_TARGET_CONTAINER_URL_ES"] - - client = DocumentTranslationClient(endpoint, AzureKeyCredential(key)) - - batch = [ - BatchTranslationInput( - source_url=source_container_url, - source_language="en", - targets=[ - StorageTarget( - target_url=target_container_url_es, - language="es" - ) - ], - storage_type="file" - ) - ] - - batch_detail = client.create_batch(batch) # type: BatchStatusDetail - - print("Batch status: {}".format(batch_detail.status)) - print("Number of translations on documents: {}".format(batch_detail.documents_total_count)) - - client.cancel_batch(batch_detail.id) - detail = client.get_batch_status(batch_detail.id) # type: BatchStatusDetail - - if detail.status in ["Cancelled", "Cancelling"]: - print("We cancelled batch with ID: {}".format(detail.id)) diff --git a/sdk/documenttranslation/azure-ai-documenttranslation/samples/sample_check_statuses.py b/sdk/documenttranslation/azure-ai-documenttranslation/samples/sample_check_statuses.py index c3d97b209953..4d47f3ca8821 100644 --- a/sdk/documenttranslation/azure-ai-documenttranslation/samples/sample_check_statuses.py +++ b/sdk/documenttranslation/azure-ai-documenttranslation/samples/sample_check_statuses.py @@ -11,7 +11,7 @@ def sample_batch_translation(): from azure.core.credentials import AzureKeyCredential from azure.ai.documenttranslation import ( DocumentTranslationClient, - BatchTranslationInput, + BatchDocumentInput, StorageTarget ) @@ -24,7 +24,7 @@ def sample_batch_translation(): client = DocumentTranslationClient(endpoint, AzureKeyCredential(key)) batch = [ - BatchTranslationInput( + BatchDocumentInput( source_url=source_container_url, source_language="en", targets=[ @@ -42,32 +42,32 @@ def sample_batch_translation(): ) ] - batch_detail = client.create_batch(batch) + job_detail = client.create_translation_job(batch) while True: - batch_detail = client.get_batch_status(batch_detail.id) # type: BatchStatusDetail - if batch_detail.status in ["NotStarted", "Running"]: - time.sleep(5) + job_detail = client.get_job_status(job_detail.id) # type: JobStatusDetail + if job_detail.status in ["NotStarted", "Running"]: + time.sleep(10) continue - if batch_detail.status in ["Failed", "ValidationFailed"]: - if batch_detail.error: - print("Batch failed: {}: {}".format(batch_detail.error.code, batch_detail.error.message)) - check_documents(client, batch_detail.id) + if job_detail.status in ["Failed", "ValidationFailed"]: + if job_detail.error: + print("Translation job failed: {}: {}".format(job_detail.error.code, job_detail.error.message)) + check_documents(client, job_detail.id) exit(1) - if batch_detail.status == "Succeeded": + if job_detail.status == "Succeeded": print("We translated our documents!") - if batch_detail.documents_failed_count > 0: - check_documents(client, batch_detail.id) + if job_detail.documents_failed_count > 0: + check_documents(client, job_detail.id) break -def check_documents(client, batch_id): +def check_documents(client, job_id): from azure.core.exceptions import ResourceNotFoundError try: - doc_statuses = client.list_documents_statuses(batch_id) # type: ItemPaged[DocumentStatusDetail] + doc_statuses = client.list_documents_statuses(job_id) # type: ItemPaged[DocumentStatusDetail] except ResourceNotFoundError as err: print("Failed to process any documents in source/target container.") raise err diff --git a/sdk/documenttranslation/azure-ai-documenttranslation/samples/sample_list_batches.py b/sdk/documenttranslation/azure-ai-documenttranslation/samples/sample_list_batches.py index 0abb8a57a468..cc2495de8e9e 100644 --- a/sdk/documenttranslation/azure-ai-documenttranslation/samples/sample_list_batches.py +++ b/sdk/documenttranslation/azure-ai-documenttranslation/samples/sample_list_batches.py @@ -5,7 +5,7 @@ # ------------------------------------ -def sample_list_all_batches(): +def sample_list_all_jobs(): import os from azure.core.credentials import AzureKeyCredential from azure.ai.documenttranslation import ( @@ -16,19 +16,18 @@ def sample_list_all_batches(): key = os.environ["AZURE_DOCUMENT_TRANSLATION_KEY"] client = DocumentTranslationClient(endpoint, AzureKeyCredential(key)) - batches = client.list_batches_statuses() + jobs = client.list_submitted_jobs() - print("Batches summary") - for batch in batches: - print("Batch ID: {}".format(batch.id)) - print("Batch status: {}".format(batch.status)) - print("Batch created on: {}".format(batch.created_on)) - print("Batch last updated on: {}".format(batch.last_updated_on)) - print("Batch number of translations on documents: {}".format(batch.documents_total_count)) + for job in jobs: + print("Job ID: {}".format(job.id)) + print("Job status: {}".format(job.status)) + print("Job created on: {}".format(job.created_on)) + print("Job last updated on: {}".format(job.last_updated_on)) + print("Total number of translations on documents: {}".format(job.documents_total_count)) print("Of total documents...") - print("{} failed".format(batch.documents_failed_count)) - print("{} succeeded".format(batch.documents_succeeded_count)) - print("{} in progress".format(batch.documents_in_progress_count)) - print("{} not yet started".format(batch.documents_not_yet_started_count)) - print("{} cancelled".format(batch.documents_cancelled_count)) + print("{} failed".format(job.documents_failed_count)) + print("{} succeeded".format(job.documents_succeeded_count)) + print("{} in progress".format(job.documents_in_progress_count)) + print("{} not yet started".format(job.documents_not_yet_started_count)) + print("{} cancelled".format(job.documents_cancelled_count))