From 2bcc83cc3d162b96c1703afe70cbb6254f4e2df9 Mon Sep 17 00:00:00 2001 From: Yalin Li Date: Tue, 5 Dec 2023 14:15:41 -0800 Subject: [PATCH] [DI] Add SDK versions and API versions relationship in README.md (#33351) --- .../CHANGELOG.md | 2 +- .../MIGRATION_GUIDE.md | 2 +- .../azure-ai-documentintelligence/README.md | 234 +++++++++++------- .../sample_analyze_addon_barcodes_async.py | 6 +- .../aio/sample_analyze_addon_fonts_async.py | 6 +- .../sample_analyze_addon_formulas_async.py | 6 +- .../aio/sample_analyze_addon_highres_async.py | 6 +- .../sample_analyze_addon_languages_async.py | 6 +- ...sample_analyze_addon_query_fields_async.py | 6 +- .../sample_analyze_custom_documents_async.py | 10 +- ...lyze_documents_output_in_markdown_async.py | 6 +- .../sample_analyze_general_documents_async.py | 6 +- ...sample_analyze_identity_documents_async.py | 6 +- .../aio/sample_analyze_invoices_async.py | 6 +- .../aio/sample_analyze_layout_async.py | 6 +- .../samples/aio/sample_analyze_read_async.py | 6 +- .../aio/sample_analyze_receipts_async.py | 6 +- .../sample_analyze_receipts_from_url_async.py | 8 +- .../aio/sample_analyze_tax_us_w2_async.py | 6 +- .../aio/sample_classify_document_async.py | 12 +- .../samples/aio/sample_compose_model_async.py | 14 +- .../samples/aio/sample_copy_model_to_async.py | 6 +- .../aio/sample_manage_classifiers_async.py | 14 +- .../samples/aio/sample_manage_models_async.py | 24 +- .../samples/sample_analyze_addon_barcodes.py | 4 +- .../samples/sample_analyze_addon_fonts.py | 4 +- .../samples/sample_analyze_addon_formulas.py | 4 +- .../samples/sample_analyze_addon_highres.py | 4 +- .../samples/sample_analyze_addon_languages.py | 4 +- .../sample_analyze_addon_query_fields.py | 4 +- .../sample_analyze_custom_documents.py | 8 +- ...le_analyze_documents_output_in_markdown.py | 4 +- .../sample_analyze_general_documents.py | 4 +- .../sample_analyze_identity_documents.py | 4 +- .../samples/sample_analyze_invoices.py | 4 +- .../samples/sample_analyze_layout.py | 4 +- .../samples/sample_analyze_read.py | 4 +- .../samples/sample_analyze_receipts.py | 4 +- .../sample_analyze_receipts_from_url.py | 6 +- .../samples/sample_analyze_tax_us_w2.py | 4 +- .../samples/sample_classify_document.py | 8 +- .../samples/sample_compose_model.py | 12 +- .../samples/sample_copy_model_to.py | 4 +- .../samples/sample_manage_classifiers.py | 12 +- .../samples/sample_manage_models.py | 22 +- 45 files changed, 291 insertions(+), 247 deletions(-) diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/CHANGELOG.md b/sdk/documentintelligence/azure-ai-documentintelligence/CHANGELOG.md index 7041e5488cc1..4e236cebcb0e 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/CHANGELOG.md +++ b/sdk/documentintelligence/azure-ai-documentintelligence/CHANGELOG.md @@ -23,4 +23,4 @@ This is the first preview of the `azure-ai-documentintelligence` package, target - Changed some currency-related fields in `prebuilt-receipt` model. - Retired model `prebuilt-businessCard` and `prebuilt-document`. `prebuilt-document` model is essentially `prebuilt-layout` with `features="keyValuePairs"` specified. _(This is only supported as an optional feature for "prebuilt-layout" and "prebuilt-invoice".)_ -If you were using the old `azure-ai-formrecognizer` package, please refer [MIGRATION.MD](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/documentintelligence/azure-ai-documentintelligence/MIGRATION_GUIDE.md) for more details. +If you were using the old `azure-ai-formrecognizer` package, please refer [MIGRATION_GUIDE.MD](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/documentintelligence/azure-ai-documentintelligence/MIGRATION_GUIDE.md) for more details. diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/MIGRATION_GUIDE.md b/sdk/documentintelligence/azure-ai-documentintelligence/MIGRATION_GUIDE.md index bbd5c33e1acd..28e6ec0b77ca 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/MIGRATION_GUIDE.md +++ b/sdk/documentintelligence/azure-ai-documentintelligence/MIGRATION_GUIDE.md @@ -90,7 +90,7 @@ Each page is treated as a separate document. Each empty page is kept as its own ### Clients names updates -|SDK version|Supported API version of service| +|SDK version|Supported API service version| |-|-| |1.0.0b1|2023-10-31-preview| |3.3.X(azure-ai-formrecognizer latest GA release)|2.0, 2.1, 2022-08-31, 2023-07-31 (default)| diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/README.md b/sdk/documentintelligence/azure-ai-documentintelligence/README.md index 2114f585c7ff..499dd3ba564c 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/README.md +++ b/sdk/documentintelligence/azure-ai-documentintelligence/README.md @@ -1,5 +1,5 @@ - # Azure AI Document Intelligence client library for Python + Azure AI Document Intelligence ([previously known as Form Recognizer][service-rename]) is a cloud service that uses machine learning to analyze text and structured data from your documents. It includes the following main features: - Layout - Extract content and structure (ex. words, selection marks, tables) from documents. @@ -10,6 +10,9 @@ Azure AI Document Intelligence ([previously known as Form Recognizer][service-re - Classifiers - Build custom classification models that combine layout and language features to accurately detect and identify documents you process within your application. - Add-on capabilities - Extract barcodes/QR codes, formulas, font/style, etc. or enable high resolution mode for large documents with optional parameters. +[Source code][python-di-src] +| [Package (PyPI)][python-di-pypi] +| [Samples][python-di-samples] ## Getting started @@ -19,6 +22,13 @@ Azure AI Document Intelligence ([previously known as Form Recognizer][service-re python -m pip install azure-ai-documentintelligence ``` +This table shows the relationship between SDK versions and supported API service versions: +|SDK version|Supported API service version +|-|- +|1.0.0b1 | 2023-10-31-preview + +Older API versions are supported in `azure-ai-formrecognizer`, please see the [Migration Guide][migration-guide] for detailed instructions on how to update application. + #### Prequisites - Python 3.7 or later is required to use this package. @@ -101,7 +111,7 @@ from azure.ai.documentintelligence import DocumentIntelligenceClient endpoint = "https://.cognitiveservices.azure.com/" credential = AzureKeyCredential("") -document_analysis_client = DocumentIntelligenceClient(endpoint, credential) +document_intelligence_client = DocumentIntelligenceClient(endpoint, credential) ``` #### Create the client with an Azure Active Directory credential @@ -131,7 +141,7 @@ from azure.identity import DefaultAzureCredential endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] credential = DefaultAzureCredential() -document_analysis_client = DocumentIntelligenceClient(endpoint, credential) +document_intelligence_client = DocumentIntelligenceClient(endpoint, credential) ``` ## Key concepts @@ -188,6 +198,8 @@ The following section provides several code snippets covering some of the most c Extract text, selection marks, text styles, and table structures, along with their bounding region coordinates, from documents. + + ```python from azure.core.credentials import AzureKeyCredential from azure.ai.documentintelligence import DocumentIntelligenceClient @@ -195,90 +207,52 @@ from azure.ai.documentintelligence import DocumentIntelligenceClient endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] -document_intelligence_client = DocumentIntelligenceClient( - endpoint=endpoint, credential=AzureKeyCredential(key) -) +document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) with open(path_to_sample_documents, "rb") as f: poller = document_intelligence_client.begin_analyze_document( "prebuilt-layout", analyze_request=f, content_type="application/octet-stream" ) result = poller.result() -for idx, style in enumerate(result.styles): - print( - "Document contains {} content".format( - "handwritten" if style.is_handwritten else "no handwritten" - ) - ) +if any([style.is_handwritten for style in result.styles]): + print("Document contains handwritten content") +else: + print("Document does not contain handwritten content") for page in result.pages: - print("----Analyzing layout from page #{}----".format(page.page_number)) - print( - "Page has width: {} and height: {}, measured with unit: {}".format( - page.width, page.height, page.unit - ) - ) + print(f"----Analyzing layout from page #{page.page_number}----") + print(f"Page has width: {page.width} and height: {page.height}, measured with unit: {page.unit}") for line_idx, line in enumerate(page.lines): - words = line.get_words() + words = get_words(page, line) print( - "...Line # {} has word count {} and text '{}' within bounding polygon '{}'".format( - line_idx, - len(words), - line.content, - line.polygon, - ) + f"...Line # {line_idx} has word count {len(words)} and text '{line.content}' " + f"within bounding polygon '{line.polygon}'" ) for word in words: - print( - "......Word '{}' has a confidence of {}".format( - word.content, word.confidence - ) - ) + print(f"......Word '{word.content}' has a confidence of {word.confidence}") for selection_mark in page.selection_marks: print( - "...Selection mark is '{}' within bounding polygon '{}' and has a confidence of {}".format( - selection_mark.state, - selection_mark.polygon, - selection_mark.confidence, - ) + f"Selection mark is '{selection_mark.state}' within bounding polygon " + f"'{selection_mark.polygon}' and has a confidence of {selection_mark.confidence}" ) for table_idx, table in enumerate(result.tables): - print( - "Table # {} has {} rows and {} columns".format( - table_idx, table.row_count, table.column_count - ) - ) + print(f"Table # {table_idx} has {table.row_count} rows and " f"{table.column_count} columns") for region in table.bounding_regions: - print( - "Table # {} location on page: {} is {}".format( - table_idx, - region.page_number, - region.polygon, - ) - ) + print(f"Table # {table_idx} location on page: {region.page_number} is {region.polygon}") for cell in table.cells: - print( - "...Cell[{}][{}] has content '{}'".format( - cell.row_index, - cell.column_index, - cell.content, - ) - ) + print(f"...Cell[{cell.row_index}][{cell.column_index}] has text '{cell.content}'") for region in cell.bounding_regions: - print( - "...content on page {} is within bounding polygon '{}'".format( - region.page_number, - region.polygon, - ) - ) + print(f"...content on page {region.page_number} is within bounding polygon '{region.polygon}'") print("----------------------------------------") ``` + + ### Using Prebuilt Models Extract fields from select document types such as receipts, invoices, business cards, identity documents, and U.S. W-2 tax documents using prebuilt models provided by the Document Intelligence service. @@ -294,9 +268,9 @@ from azure.ai.documentintelligence import DocumentIntelligenceClient endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] -document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) +document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) with open(path_to_sample_documents, "rb") as f: - poller = document_analysis_client.begin_analyze_document( + poller = document_intelligence_client.begin_analyze_document( "prebuilt-receipt", analyze_request=f, locale="en-US", content_type="application/octet-stream" ) receipts = poller.result() @@ -364,6 +338,7 @@ More details on setting up a container and required file structure can be found ```python +# Let's build a model to use for this sample import uuid from azure.ai.documentintelligence import DocumentIntelligenceAdministrationClient from azure.ai.documentintelligence.models import ( @@ -377,10 +352,10 @@ endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] container_sas_url = os.environ["DOCUMENTINTELLIGENCE_STORAGE_CONTAINER_SAS_URL"] -document_model_admin_client = DocumentIntelligenceAdministrationClient( +document_intelligence_admin_client = DocumentIntelligenceAdministrationClient( endpoint, AzureKeyCredential(key) ) -poller = document_model_admin_client.begin_build_document_model( +poller = document_intelligence_admin_client.begin_build_document_model( BuildDocumentModelRequest( model_id=str(uuid.uuid4()), build_mode=DocumentBuildMode.TEMPLATE, @@ -423,11 +398,11 @@ endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] model_id = os.getenv("CUSTOM_BUILT_MODEL_ID", custom_model_id) -document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) +document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) # Make sure your document's type is included in the list of document types the custom model can analyze with open(path_to_sample_documents, "rb") as f: - poller = document_analysis_client.begin_analyze_document( + poller = document_intelligence_client.begin_analyze_document( model_id=model_id, analyze_request=f, content_type="application/octet-stream" ) result = poller.result() @@ -470,6 +445,8 @@ print("-----------------------------------") Additionally, a document URL can also be used to analyze documents using the `begin_analyze_document` method. + + ```python from azure.core.credentials import AzureKeyCredential from azure.ai.documentintelligence import DocumentIntelligenceClient @@ -478,54 +455,123 @@ from azure.ai.documentintelligence.models import AnalyzeDocumentRequest endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] -document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) -url = "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/main/sdk/documentintelligence/azure-ai-documentintelligence/tests/sample_forms/receipt/contoso-receipt.png" -poller = document_analysis_client.begin_analyze_document("prebuilt-receipt", AnalyzeDocumentRequest(url_source=url)) +document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) +url = "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/main/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_forms/receipt/contoso-receipt.png" +poller = document_intelligence_client.begin_analyze_document("prebuilt-receipt", AnalyzeDocumentRequest(url_source=url)) receipts = poller.result() ``` + + ### Manage Your Models Manage the custom models attached to your account. + + ```python +# Let's build a model to use for this sample +import uuid from azure.ai.documentintelligence import DocumentIntelligenceAdministrationClient +from azure.ai.documentintelligence.models import ( + DocumentBuildMode, + BuildDocumentModelRequest, + AzureBlobContentSource, +) from azure.core.credentials import AzureKeyCredential -from azure.core.exceptions import ResourceNotFoundError -endpoint = "https://.cognitiveservices.azure.com/" -credential = AzureKeyCredential("") +endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] +key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] +container_sas_url = os.environ["DOCUMENTINTELLIGENCE_STORAGE_CONTAINER_SAS_URL"] -document_model_admin_client = DocumentIntelligenceAdministrationClient(endpoint, credential) +document_intelligence_admin_client = DocumentIntelligenceAdministrationClient( + endpoint, AzureKeyCredential(key) +) +poller = document_intelligence_admin_client.begin_build_document_model( + BuildDocumentModelRequest( + model_id=str(uuid.uuid4()), + build_mode=DocumentBuildMode.TEMPLATE, + azure_blob_source=AzureBlobContentSource(container_url=container_sas_url), + description="my model description", + ) +) +model = poller.result() -account_details = document_model_admin_client.get_resource_info() -print("Our account has {} custom models, and we can have at most {} custom models".format( - account_details.custom_document_models.count, account_details.custom_document_models.limit -)) +print(f"Model ID: {model.model_id}") +print(f"Description: {model.description}") +print(f"Model created on: {model.created_date_time}") +print(f"Model expires on: {model.expiration_date_time}") +print("Doc types the model can recognize:") +for name, doc_type in model.doc_types.items(): + print( + f"Doc Type: '{name}' built with '{doc_type.build_mode}' mode which has the following fields:" + ) + for field_name, field in doc_type.field_schema.items(): + print( + f"Field: '{field_name}' has type '{field['type']}' and confidence score " + f"{doc_type.field_confidence[field_name]}" + ) +``` -# Here we get a paged list of all of our models -models = document_model_admin_client.list_models() -print("We have models with the following ids: {}".format( - ", ".join([m.model_id for m in models]) -)) + -# Replace with the custom model ID from the "Build a model" sample -model_id = "" + -custom_model = document_model_admin_client.get_model(model_id=model_id) -print("Model ID: {}".format(custom_model.model_id)) -print("Description: {}".format(custom_model.description)) -print("Model created on: {}\n".format(custom_model.created_on)) +```python +account_details = document_intelligence_admin_client.get_resource_info() +print( + f"Our resource has {account_details.custom_document_models.count} custom models, " + f"and we can have at most {account_details.custom_document_models.limit} custom models" +) +neural_models = account_details.custom_neural_document_model_builds +print( + f"The quota limit for custom neural document models is {neural_models.quota} and the resource has" + f"used {neural_models.used}. The resource quota will reset on {neural_models.quota_reset_date_time}" +) +``` + + + + + +```python +# Next, we get a paged list of all of our custom models +models = document_intelligence_admin_client.list_models() + +print("We have the following 'ready' models with IDs and descriptions:") +for model in models: + print(f"{model.model_id} | {model.description}") +``` + + + + +```python +my_model = document_intelligence_admin_client.get_model(model_id=model.model_id) +print(f"\nModel ID: {my_model.model_id}") +print(f"Description: {my_model.description}") +print(f"Model created on: {my_model.created_date_time}") +print(f"Model expires on: {my_model.expiration_date_time}") +``` + + + + + +```python # Finally, we will delete this model by ID -document_model_admin_client.delete_model(model_id=custom_model.model_id) +document_intelligence_admin_client.delete_model(model_id=my_model.model_id) +from azure.core.exceptions import ResourceNotFoundError try: - document_model_admin_client.get_model(model_id=custom_model.model_id) + document_intelligence_admin_client.get_model(model_id=my_model.model_id) except ResourceNotFoundError: - print("Successfully deleted model with id {}".format(custom_model.model_id)) + print(f"Successfully deleted model with ID {my_model.model_id}") ``` + + ### Add-on Capabilities Document Intelligence supports more sophisticated analysis capabilities. These optional features can be enabled and disabled depending on the scenario of the document extraction. @@ -595,7 +641,6 @@ additional questions or comments. [code_of_conduct]: https://opensource.microsoft.com/codeofconduct/ [default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#defaultazurecredential -[pip]: https://pypi.org/project/pip/ [azure_sub]: https://azure.microsoft.com/free/ [python-di-product-docs]: https://learn.microsoft.com/azure/applied-ai-services/form-recognizer/overview?view=form-recog-3.0.0 [azure_portal]: https://ms.portal.azure.com/ @@ -608,7 +653,6 @@ additional questions or comments. [di-build-training-set]: https://aka.ms/azsdk/documentintelligence/buildtrainingset [di-models]: https://aka.ms/azsdk/documentintelligence/models [di-errors]: https://aka.ms/azsdk/documentintelligence/errors - [azure_core_ref_docs]: https://aka.ms/azsdk/python/core/docs [azure_core_exceptions]: https://aka.ms/azsdk/python/core/docs#module-azure.core.exceptions [python_logging]: https://docs.python.org/3/library/logging.html @@ -619,12 +663,12 @@ additional questions or comments. [custom_subdomain]: https://docs.microsoft.com/azure/cognitive-services/authentication#create-a-resource-with-a-custom-subdomain [azure_identity]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity [sdk_logging_docs]: https://docs.microsoft.com/azure/developer/python/sdk/azure-sdk-logging +[migration-guide]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/documentintelligence/azure-ai-documentintelligence/MIGRATION_GUIDE.md [sample_readme]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/documentintelligence/azure-ai-documentintelligence/samples -[changelog]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/documentintelligence/azure-ai-documentintelligence/CHANGELOG.md [addon_barcodes_sample]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_barcodes.py [addon_fonts_sample]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_fonts.py [addon_formulas_sample]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_formulas.py [addon_highres_sample]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_highres.py [addon_languages_sample]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_languages.py -[query_fields_sample] https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_query_fields.py +[query_fields_sample]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_query_fields.py [service-rename]: https://techcommunity.microsoft.com/t5/azure-ai-services-blog/azure-form-recognizer-is-now-azure-ai-document-intelligence-with/ba-p/3875765 diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_addon_barcodes_async.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_addon_barcodes_async.py index 8f287cedd760..c5c7eb17b557 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_addon_barcodes_async.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_addon_barcodes_async.py @@ -60,12 +60,12 @@ async def analyze_barcodes(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) - async with document_analysis_client: + async with document_intelligence_client: # Specify which add-on capabilities to enable. with open(path_to_sample_documents, "rb") as f: - poller = await document_analysis_client.begin_analyze_document( + poller = await document_intelligence_client.begin_analyze_document( "prebuilt-layout", analyze_request=f, features=[DocumentAnalysisFeature.BARCODES], diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_addon_fonts_async.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_addon_fonts_async.py index d475e47f7346..005a1c649bcd 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_addon_fonts_async.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_addon_fonts_async.py @@ -68,11 +68,11 @@ async def analyze_fonts(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) - async with document_analysis_client: + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + async with document_intelligence_client: # Specify which add-on capabilities to enable. with open(path_to_sample_documents, "rb") as f: - poller = await document_analysis_client.begin_analyze_document( + poller = await document_intelligence_client.begin_analyze_document( "prebuilt-layout", analyze_request=f, features=[DocumentAnalysisFeature.STYLE_FONT], diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_addon_formulas_async.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_addon_formulas_async.py index 3c67e36027a5..4e98b20e1f8b 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_addon_formulas_async.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_addon_formulas_async.py @@ -60,12 +60,12 @@ async def analyze_formulas(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) - async with document_analysis_client: + async with document_intelligence_client: # Specify which add-on capabilities to enable with open(path_to_sample_documents, "rb") as f: - poller = await document_analysis_client.begin_analyze_document( + poller = await document_intelligence_client.begin_analyze_document( "prebuilt-layout", analyze_request=f, features=[DocumentAnalysisFeature.FORMULAS], diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_addon_highres_async.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_addon_highres_async.py index 405cabc209ff..ff9d5d9d3e3c 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_addon_highres_async.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_addon_highres_async.py @@ -75,12 +75,12 @@ async def analyze_with_highres(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) - async with document_analysis_client: + async with document_intelligence_client: # Specify which add-on capabilities to enable. with open(path_to_sample_documents, "rb") as f: - poller = await document_analysis_client.begin_analyze_document( + poller = await document_intelligence_client.begin_analyze_document( "prebuilt-layout", analyze_request=f, features=[DocumentAnalysisFeature.OCR_HIGH_RESOLUTION], diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_addon_languages_async.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_addon_languages_async.py index 737a3ec57d6f..cfe7c6c11e4e 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_addon_languages_async.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_addon_languages_async.py @@ -60,12 +60,12 @@ async def analyze_languages(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) - async with document_analysis_client: + async with document_intelligence_client: # Specify which add-on capabilities to enable. with open(path_to_sample_documents, "rb") as f: - poller = await document_analysis_client.begin_analyze_document( + poller = await document_intelligence_client.begin_analyze_document( "prebuilt-layout", analyze_request=f, features=[DocumentAnalysisFeature.LANGUAGES], diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_addon_query_fields_async.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_addon_query_fields_async.py index a247df5c8332..65f4fd9998ed 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_addon_query_fields_async.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_addon_query_fields_async.py @@ -53,11 +53,11 @@ async def analyze_query_fields(): key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] url = "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/main/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_forms/forms/Invoice_1.pdf" - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) - async with document_analysis_client: + async with document_intelligence_client: # Specify which add-on capabilities to enable. - poller = await document_analysis_client.begin_analyze_document( + poller = await document_intelligence_client.begin_analyze_document( "prebuilt-layout", AnalyzeDocumentRequest(url_source=url), features=[DocumentAnalysisFeature.QUERY_FIELDS], diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_custom_documents_async.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_custom_documents_async.py index 649a5febc707..8dd9b804c934 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_custom_documents_async.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_custom_documents_async.py @@ -43,11 +43,11 @@ async def analyze_custom_documents(custom_model_id): key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] model_id = os.getenv("CUSTOM_BUILT_MODEL_ID", custom_model_id) - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) # Make sure your document's type is included in the list of document types the custom model can analyze with open(path_to_sample_documents, "rb") as f: - poller = await document_analysis_client.begin_analyze_document( + poller = await document_intelligence_client.begin_analyze_document( model_id=model_id, analyze_request=f, content_type="application/octet-stream" ) result = await poller.result() @@ -112,11 +112,11 @@ async def main(): build_mode=DocumentBuildMode.TEMPLATE, azure_blob_source=AzureBlobContentSource(container_url=blob_container_sas_url), ) - document_model_admin_client = DocumentIntelligenceAdministrationClient( + document_intelligence_admin_client = DocumentIntelligenceAdministrationClient( endpoint=endpoint, credential=AzureKeyCredential(key) ) - async with document_model_admin_client: - poll = await document_model_admin_client.begin_build_document_model(request) + async with document_intelligence_admin_client: + poll = await document_intelligence_admin_client.begin_build_document_model(request) model = await poll.result() model_id = model.model_id await analyze_custom_documents(model_id) diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_documents_output_in_markdown_async.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_documents_output_in_markdown_async.py index 413c93659c5b..bf71a573342b 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_documents_output_in_markdown_async.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_documents_output_in_markdown_async.py @@ -34,9 +34,9 @@ async def analyze_documents_output_in_markdown(): key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] url = "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/main/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_forms/forms/Invoice_1.pdf" - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) - async with document_analysis_client: - poller = await document_analysis_client.begin_analyze_document( + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + async with document_intelligence_client: + poller = await document_intelligence_client.begin_analyze_document( "prebuilt-layout", AnalyzeDocumentRequest(url_source=url), output_content_format=ContentFormat.MARKDOWN, diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_general_documents_async.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_general_documents_async.py index 0a504b1080e9..211c57de9fc2 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_general_documents_async.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_general_documents_async.py @@ -58,12 +58,12 @@ async def analyze_general_documents(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient( + document_intelligence_client = DocumentIntelligenceClient( endpoint=endpoint, credential=AzureKeyCredential(key) ) - async with document_analysis_client: + async with document_intelligence_client: with open(path_to_sample_documents, "rb") as f: - poller = await document_analysis_client.begin_analyze_document( + poller = await document_intelligence_client.begin_analyze_document( "prebuilt-layout", analyze_request=f, features=[DocumentAnalysisFeature.KEY_VALUE_PAIRS], diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_identity_documents_async.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_identity_documents_async.py index 1576d5cf642f..fcdfccc3a693 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_identity_documents_async.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_identity_documents_async.py @@ -43,10 +43,10 @@ async def analyze_identity_documents(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) - async with document_analysis_client: + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + async with document_intelligence_client: with open(path_to_sample_documents, "rb") as f: - poller = await document_analysis_client.begin_analyze_document( + poller = await document_intelligence_client.begin_analyze_document( "prebuilt-idDocument", analyze_request=f, content_type="application/octet-stream" ) id_documents = await poller.result() diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_invoices_async.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_invoices_async.py index 903f6a0cd0e3..10b3b58022e6 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_invoices_async.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_invoices_async.py @@ -44,10 +44,10 @@ async def analyze_invoice(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) - async with document_analysis_client: + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + async with document_intelligence_client: with open(path_to_sample_documents, "rb") as f: - poller = await document_analysis_client.begin_analyze_document( + poller = await document_intelligence_client.begin_analyze_document( "prebuilt-invoice", analyze_request=f, locale="en-US", content_type="application/octet-stream" ) invoices = await poller.result() diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_layout_async.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_layout_async.py index c3b673c998f2..12e0c96f55d4 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_layout_async.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_layout_async.py @@ -61,10 +61,10 @@ async def analyze_layout(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) - async with document_analysis_client: + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + async with document_intelligence_client: with open(path_to_sample_documents, "rb") as f: - poller = await document_analysis_client.begin_analyze_document( + poller = await document_intelligence_client.begin_analyze_document( "prebuilt-layout", analyze_request=f, content_type="application/octet-stream" ) result = await poller.result() diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_read_async.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_read_async.py index 421747b3d56c..f469d8c2ab77 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_read_async.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_read_async.py @@ -57,10 +57,10 @@ async def analyze_read(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) - async with document_analysis_client: + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + async with document_intelligence_client: with open(path_to_sample_documents, "rb") as f: - poller = await document_analysis_client.begin_analyze_document( + poller = await document_intelligence_client.begin_analyze_document( "prebuilt-read", analyze_request=f, features=[DocumentAnalysisFeature.STYLE_FONT], diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_receipts_async.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_receipts_async.py index 31c6c389dedf..8ab921ce3b42 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_receipts_async.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_receipts_async.py @@ -49,10 +49,10 @@ async def analyze_receipts(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) - async with document_analysis_client: + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + async with document_intelligence_client: with open(path_to_sample_documents, "rb") as f: - poller = await document_analysis_client.begin_analyze_document( + poller = await document_intelligence_client.begin_analyze_document( "prebuilt-receipt", analyze_request=f, locale="en-US", content_type="application/octet-stream" ) receipts = await poller.result() diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_receipts_from_url_async.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_receipts_from_url_async.py index 27764cea51bb..fa8e1a9ca729 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_receipts_from_url_async.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_receipts_from_url_async.py @@ -41,13 +41,14 @@ async def analyze_receipts_from_url(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) url = "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/main/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_forms/receipt/contoso-receipt.png" - async with document_analysis_client: - poller = await document_analysis_client.begin_analyze_document( + async with document_intelligence_client: + poller = await document_intelligence_client.begin_analyze_document( "prebuilt-receipt", AnalyzeDocumentRequest(url_source=url) ) receipts = await poller.result() + # [END analyze_receipts_from_url] for idx, receipt in enumerate(receipts.documents): print(f"--------Analysis of receipt #{idx + 1}--------") @@ -96,7 +97,6 @@ async def analyze_receipts_from_url(): if total: print(f"Total: {format_price(total.get('valueCurrency'))} has confidence: {total.confidence}") print("--------------------------------------") - # [END analyze_receipts_from_url] async def main(): diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_tax_us_w2_async.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_tax_us_w2_async.py index 2f67d3d88f12..73fb465dbf65 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_tax_us_w2_async.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_tax_us_w2_async.py @@ -47,10 +47,10 @@ async def analyze_tax_us_w2(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) - async with document_analysis_client: + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + async with document_intelligence_client: with open(path_to_sample_documents, "rb") as f: - poller = await document_analysis_client.begin_analyze_document( + poller = await document_intelligence_client.begin_analyze_document( "prebuilt-tax.us.w2", analyze_request=f, locale="en-US", content_type="application/octet-stream" ) w2s = await poller.result() diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_classify_document_async.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_classify_document_async.py index 443f093ec5b1..5605de3bc629 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_classify_document_async.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_classify_document_async.py @@ -50,12 +50,12 @@ async def classify_document(classifier_id): key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] classifier_id = os.getenv("CLASSIFIER_ID", classifier_id) - document_analysis_client = DocumentIntelligenceClient( + document_intelligence_client = DocumentIntelligenceClient( endpoint=endpoint, credential=AzureKeyCredential(key) ) - async with document_analysis_client: + async with document_intelligence_client: with open(path_to_sample_documents, "rb") as f: - poller = await document_analysis_client.begin_classify_document( + poller = await document_intelligence_client.begin_classify_document( classifier_id, classify_request=f, content_type="application/octet-stream" ) result = await poller.result() @@ -85,11 +85,11 @@ async def main(): key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] blob_container_sas_url = os.environ["DOCUMENTINTELLIGENCE_TRAINING_DATA_CLASSIFIER_SAS_URL"] - document_model_admin_client = DocumentIntelligenceAdministrationClient( + document_intelligence_admin_client = DocumentIntelligenceAdministrationClient( endpoint=endpoint, credential=AzureKeyCredential(key) ) - async with document_model_admin_client: - poller = await document_model_admin_client.begin_build_classifier( + async with document_intelligence_admin_client: + poller = await document_intelligence_admin_client.begin_build_classifier( BuildDocumentClassifierRequest( classifier_id=str(uuid.uuid4()), doc_types={ diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_compose_model_async.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_compose_model_async.py index 816ac8c5001f..e3ca650607ce 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_compose_model_async.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_compose_model_async.py @@ -53,11 +53,11 @@ async def sample_compose_model(): key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] container_sas_url = os.environ["DOCUMENTINTELLIGENCE_STORAGE_CONTAINER_SAS_URL"] - document_model_admin_client = DocumentIntelligenceAdministrationClient( + document_intelligence_admin_client = DocumentIntelligenceAdministrationClient( endpoint=endpoint, credential=AzureKeyCredential(key) ) - async with document_model_admin_client: - supplies_poller = await document_model_admin_client.begin_build_document_model( + async with document_intelligence_admin_client: + supplies_poller = await document_intelligence_admin_client.begin_build_document_model( BuildDocumentModelRequest( model_id=str(uuid.uuid4()), build_mode=DocumentBuildMode.TEMPLATE, @@ -65,7 +65,7 @@ async def sample_compose_model(): description="Purchase order-Office Supplies", ) ) - equipment_poller = await document_model_admin_client.begin_build_document_model( + equipment_poller = await document_intelligence_admin_client.begin_build_document_model( BuildDocumentModelRequest( model_id=str(uuid.uuid4()), build_mode=DocumentBuildMode.TEMPLATE, @@ -73,7 +73,7 @@ async def sample_compose_model(): description="Purchase order-Office Equipment", ) ) - furniture_poller = await document_model_admin_client.begin_build_document_model( + furniture_poller = await document_intelligence_admin_client.begin_build_document_model( BuildDocumentModelRequest( model_id=str(uuid.uuid4()), build_mode=DocumentBuildMode.TEMPLATE, @@ -81,7 +81,7 @@ async def sample_compose_model(): description="Purchase order-Office Furniture", ) ) - cleaning_supplies_poller = await document_model_admin_client.begin_build_document_model( + cleaning_supplies_poller = await document_intelligence_admin_client.begin_build_document_model( BuildDocumentModelRequest( model_id=str(uuid.uuid4()), build_mode=DocumentBuildMode.TEMPLATE, @@ -94,7 +94,7 @@ async def sample_compose_model(): furniture_model = await furniture_poller.result() cleaning_supplies_model = await cleaning_supplies_poller.result() - poller = await document_model_admin_client.begin_compose_model( + poller = await document_intelligence_admin_client.begin_compose_model( ComposeDocumentModelRequest( model_id=str(uuid.uuid4()), component_models=[ diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_copy_model_to_async.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_copy_model_to_async.py index 2ed400795dd9..283222d7beb2 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_copy_model_to_async.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_copy_model_to_async.py @@ -105,11 +105,11 @@ async def main(): build_mode=DocumentBuildMode.TEMPLATE, azure_blob_source=AzureBlobContentSource(container_url=blob_container_sas_url), ) - document_model_admin_client = DocumentIntelligenceAdministrationClient( + document_intelligence_admin_client = DocumentIntelligenceAdministrationClient( endpoint=endpoint, credential=AzureKeyCredential(key) ) - async with document_model_admin_client: - poll = await document_model_admin_client.begin_build_document_model(request) + async with document_intelligence_admin_client: + poll = await document_intelligence_admin_client.begin_build_document_model(request) model = await poll.result() model_id = model.model_id await sample_copy_model_to(model_id) diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_manage_classifiers_async.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_manage_classifiers_async.py index 04dab3ebd316..bc80f528f479 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_manage_classifiers_async.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_manage_classifiers_async.py @@ -41,12 +41,12 @@ async def sample_manage_classifiers(): key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] container_sas_url = os.environ["DOCUMENTINTELLIGENCE_TRAINING_DATA_CLASSIFIER_SAS_URL"] - document_model_admin_client = DocumentIntelligenceAdministrationClient( + document_intelligence_admin_client = DocumentIntelligenceAdministrationClient( endpoint=endpoint, credential=AzureKeyCredential(key) ) - async with document_model_admin_client: + async with document_intelligence_admin_client: # build a document classifier - poller = await document_model_admin_client.begin_build_classifier( + poller = await document_intelligence_admin_client.begin_build_classifier( BuildDocumentClassifierRequest( classifier_id=str(uuid.uuid4()), doc_types={ @@ -76,7 +76,7 @@ async def sample_manage_classifiers(): # Next, we get a paged list of all of our document classifiers # [START list_classifiers] - classifiers = document_model_admin_client.list_classifiers() + classifiers = document_intelligence_admin_client.list_classifiers() print("We have the following 'ready' models with IDs and descriptions:") async for classifier in classifiers: @@ -84,7 +84,7 @@ async def sample_manage_classifiers(): # [END list_classifiers] # [START get_classifier] - my_classifier = await document_model_admin_client.get_classifier(classifier_id=classifier.classifier_id) + my_classifier = await document_intelligence_admin_client.get_classifier(classifier_id=classifier.classifier_id) print(f"\nClassifier ID: {my_classifier.classifier_id}") print(f"Description: {my_classifier.description}") print(f"Classifier created on: {my_classifier.created_date_time}") @@ -93,12 +93,12 @@ async def sample_manage_classifiers(): # Finally, we will delete this classifier by ID # [START delete_classifier] - await document_model_admin_client.delete_classifier(classifier_id=my_classifier.classifier_id) + await document_intelligence_admin_client.delete_classifier(classifier_id=my_classifier.classifier_id) # [END delete_document_classifier] from azure.core.exceptions import ResourceNotFoundError try: - await document_model_admin_client.get_classifier(classifier_id=my_classifier.classifier_id) + await document_intelligence_admin_client.get_classifier(classifier_id=my_classifier.classifier_id) except ResourceNotFoundError: print(f"Successfully deleted classifier with ID {my_classifier.classifier_id}") diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_manage_models_async.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_manage_models_async.py index 3b4a499d6064..a12be2446e82 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_manage_models_async.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_manage_models_async.py @@ -27,8 +27,8 @@ async def sample_manage_models(): - # Let's build a model to use for this sample # [START build_model] + # Let's build a model to use for this sample import uuid from azure.ai.documentintelligence.aio import DocumentIntelligenceAdministrationClient from azure.ai.documentintelligence.models import ( @@ -42,11 +42,11 @@ async def sample_manage_models(): key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] container_sas_url = os.environ["DOCUMENTINTELLIGENCE_STORAGE_CONTAINER_SAS_URL"] - document_model_admin_client = DocumentIntelligenceAdministrationClient( + document_intelligence_admin_client = DocumentIntelligenceAdministrationClient( endpoint, AzureKeyCredential(key) ) - async with document_model_admin_client: - poller = await document_model_admin_client.begin_build_document_model( + async with document_intelligence_admin_client: + poller = await document_intelligence_admin_client.begin_build_document_model( BuildDocumentModelRequest( model_id=str(uuid.uuid4()), build_mode=DocumentBuildMode.TEMPLATE, @@ -73,7 +73,7 @@ async def sample_manage_models(): # [END build_model] # [START get_resource_info] - account_details = await document_model_admin_client.get_resource_info() + account_details = await document_intelligence_admin_client.get_resource_info() print( f"Our resource has {account_details.custom_document_models.count} custom models, " f"and we can have at most {account_details.custom_document_models.limit} custom models" @@ -85,9 +85,9 @@ async def sample_manage_models(): ) # [END get_resource_info] - # Next, we get a paged list of all of our custom models # [START list_models] - models = document_model_admin_client.list_models() + # Next, we get a paged list of all of our custom models + models = document_intelligence_admin_client.list_models() print("We have the following 'ready' models with IDs and descriptions:") async for model in models: @@ -95,23 +95,23 @@ async def sample_manage_models(): # [END list_models] # [START get_model] - my_model = await document_model_admin_client.get_model(model_id=model.model_id) + my_model = await document_intelligence_admin_client.get_model(model_id=model.model_id) print(f"\nModel ID: {my_model.model_id}") print(f"Description: {my_model.description}") print(f"Model created on: {my_model.created_date_time}") print(f"Model expires on: {my_model.expiration_date_time}") # [END get_model] - # Finally, we will delete this model by ID # [START delete_model] - await document_model_admin_client.delete_model(model_id=my_model.model_id) - # [END delete_document_model] + # Finally, we will delete this model by ID + await document_intelligence_admin_client.delete_model(model_id=my_model.model_id) from azure.core.exceptions import ResourceNotFoundError try: - await document_model_admin_client.get_model(model_id=my_model.model_id) + await document_intelligence_admin_client.get_model(model_id=my_model.model_id) except ResourceNotFoundError: print(f"Successfully deleted model with ID {my_model.model_id}") + # [END delete_model] async def main(): diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_barcodes.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_barcodes.py index f0e49d79ec67..20ceccf5984d 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_barcodes.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_barcodes.py @@ -58,11 +58,11 @@ def analyze_barcodes(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) # Specify which add-on capabilities to enable. with open(path_to_sample_documents, "rb") as f: - poller = document_analysis_client.begin_analyze_document( + poller = document_intelligence_client.begin_analyze_document( "prebuilt-layout", analyze_request=f, features=[DocumentAnalysisFeature.BARCODES], diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_fonts.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_fonts.py index d06f469f424e..b341f79e166e 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_fonts.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_fonts.py @@ -66,10 +66,10 @@ def analyze_fonts(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) # Specify which add-on capabilities to enable. with open(path_to_sample_documents, "rb") as f: - poller = document_analysis_client.begin_analyze_document( + poller = document_intelligence_client.begin_analyze_document( "prebuilt-layout", analyze_request=f, features=[DocumentAnalysisFeature.STYLE_FONT], diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_formulas.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_formulas.py index 1e568949ee96..ade803c9f838 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_formulas.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_formulas.py @@ -58,11 +58,11 @@ def analyze_formulas(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) # Specify which add-on capabilities to enable with open(path_to_sample_documents, "rb") as f: - poller = document_analysis_client.begin_analyze_document( + poller = document_intelligence_client.begin_analyze_document( "prebuilt-layout", analyze_request=f, features=[DocumentAnalysisFeature.FORMULAS], diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_highres.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_highres.py index ce1fe39f1f9a..bdc0509be6f9 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_highres.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_highres.py @@ -73,11 +73,11 @@ def analyze_with_highres(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) # Specify which add-on capabilities to enable. with open(path_to_sample_documents, "rb") as f: - poller = document_analysis_client.begin_analyze_document( + poller = document_intelligence_client.begin_analyze_document( "prebuilt-layout", analyze_request=f, features=[DocumentAnalysisFeature.OCR_HIGH_RESOLUTION], diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_languages.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_languages.py index 0400609da5de..bc0614f8d866 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_languages.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_languages.py @@ -58,11 +58,11 @@ def analyze_languages(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) # Specify which add-on capabilities to enable. with open(path_to_sample_documents, "rb") as f: - poller = document_analysis_client.begin_analyze_document( + poller = document_intelligence_client.begin_analyze_document( "prebuilt-layout", analyze_request=f, features=[DocumentAnalysisFeature.LANGUAGES], diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_query_fields.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_query_fields.py index a9b1ccdd04b8..6a9ead4379d5 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_query_fields.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_addon_query_fields.py @@ -52,10 +52,10 @@ def analyze_query_fields(): key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] url = "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/main/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_forms/forms/Invoice_1.pdf" - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) # Specify which add-on capabilities to enable. - poller = document_analysis_client.begin_analyze_document( + poller = document_intelligence_client.begin_analyze_document( "prebuilt-layout", AnalyzeDocumentRequest(url_source=url), features=[DocumentAnalysisFeature.QUERY_FIELDS], diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_custom_documents.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_custom_documents.py index da9ac3c8b5e6..7e2f2e246bf7 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_custom_documents.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_custom_documents.py @@ -42,11 +42,11 @@ def analyze_custom_documents(custom_model_id): key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] model_id = os.getenv("CUSTOM_BUILT_MODEL_ID", custom_model_id) - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) # Make sure your document's type is included in the list of document types the custom model can analyze with open(path_to_sample_documents, "rb") as f: - poller = document_analysis_client.begin_analyze_document( + poller = document_intelligence_client.begin_analyze_document( model_id=model_id, analyze_request=f, content_type="application/octet-stream" ) result = poller.result() @@ -109,7 +109,7 @@ def analyze_custom_documents(custom_model_id): if not endpoint or not key: raise ValueError("Please provide endpoint and API key to run the samples.") - document_model_admin_client = DocumentIntelligenceAdministrationClient( + document_intelligence_admin_client = DocumentIntelligenceAdministrationClient( endpoint=endpoint, credential=AzureKeyCredential(key) ) blob_container_sas_url = os.getenv("DOCUMENTINTELLIGENCE_STORAGE_CONTAINER_SAS_URL") @@ -119,7 +119,7 @@ def analyze_custom_documents(custom_model_id): build_mode=DocumentBuildMode.TEMPLATE, azure_blob_source=AzureBlobContentSource(container_url=blob_container_sas_url), ) - model = document_model_admin_client.begin_build_document_model(request).result() + model = document_intelligence_admin_client.begin_build_document_model(request).result() model_id = model.model_id analyze_custom_documents(model_id) except HttpResponseError as error: diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_documents_output_in_markdown.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_documents_output_in_markdown.py index 899ad277789e..92ad825bcf04 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_documents_output_in_markdown.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_documents_output_in_markdown.py @@ -33,8 +33,8 @@ def analyze_documents_output_in_markdown(): key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] url = "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/main/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_forms/forms/Invoice_1.pdf" - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) - poller = document_analysis_client.begin_analyze_document( + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + poller = document_intelligence_client.begin_analyze_document( "prebuilt-layout", AnalyzeDocumentRequest(url_source=url), output_content_format=ContentFormat.MARKDOWN, diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_general_documents.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_general_documents.py index 82d4a5860036..a4ae5b8944c5 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_general_documents.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_general_documents.py @@ -56,11 +56,11 @@ def analyze_general_documents(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient( + document_intelligence_client = DocumentIntelligenceClient( endpoint=endpoint, credential=AzureKeyCredential(key) ) with open(path_to_sample_documents, "rb") as f: - poller = document_analysis_client.begin_analyze_document( + poller = document_intelligence_client.begin_analyze_document( "prebuilt-layout", analyze_request=f, features=[DocumentAnalysisFeature.KEY_VALUE_PAIRS], diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_identity_documents.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_identity_documents.py index 290d3e13f7d1..92212f9789ad 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_identity_documents.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_identity_documents.py @@ -41,9 +41,9 @@ def analyze_identity_documents(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) with open(path_to_sample_documents, "rb") as f: - poller = document_analysis_client.begin_analyze_document( + poller = document_intelligence_client.begin_analyze_document( "prebuilt-idDocument", analyze_request=f, content_type="application/octet-stream" ) id_documents = poller.result() diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_invoices.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_invoices.py index c1532c6608d2..5d13638bc06f 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_invoices.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_invoices.py @@ -42,9 +42,9 @@ def analyze_invoice(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) with open(path_to_sample_documents, "rb") as f: - poller = document_analysis_client.begin_analyze_document( + poller = document_intelligence_client.begin_analyze_document( "prebuilt-invoice", analyze_request=f, locale="en-US", content_type="application/octet-stream" ) invoices = poller.result() diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_layout.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_layout.py index 07a4a348ff94..bb649a71d954 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_layout.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_layout.py @@ -59,9 +59,9 @@ def analyze_layout(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) with open(path_to_sample_documents, "rb") as f: - poller = document_analysis_client.begin_analyze_document( + poller = document_intelligence_client.begin_analyze_document( "prebuilt-layout", analyze_request=f, content_type="application/octet-stream" ) result = poller.result() diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_read.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_read.py index f47f1eb6a4c4..31ec3c3565c4 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_read.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_read.py @@ -55,9 +55,9 @@ def analyze_read(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) with open(path_to_sample_documents, "rb") as f: - poller = document_analysis_client.begin_analyze_document( + poller = document_intelligence_client.begin_analyze_document( "prebuilt-read", analyze_request=f, features=[DocumentAnalysisFeature.STYLE_FONT], diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_receipts.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_receipts.py index 94bc7332c143..17265c7da1e3 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_receipts.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_receipts.py @@ -47,9 +47,9 @@ def analyze_receipts(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) with open(path_to_sample_documents, "rb") as f: - poller = document_analysis_client.begin_analyze_document( + poller = document_intelligence_client.begin_analyze_document( "prebuilt-receipt", analyze_request=f, locale="en-US", content_type="application/octet-stream" ) receipts = poller.result() diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_receipts_from_url.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_receipts_from_url.py index fcb0a9dc3826..7ade14a678bc 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_receipts_from_url.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_receipts_from_url.py @@ -40,10 +40,11 @@ def analyze_receipts_from_url(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) url = "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/main/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_forms/receipt/contoso-receipt.png" - poller = document_analysis_client.begin_analyze_document("prebuilt-receipt", AnalyzeDocumentRequest(url_source=url)) + poller = document_intelligence_client.begin_analyze_document("prebuilt-receipt", AnalyzeDocumentRequest(url_source=url)) receipts = poller.result() + # [END analyze_receipts_from_url] for idx, receipt in enumerate(receipts.documents): print(f"--------Analysis of receipt #{idx + 1}--------") @@ -92,7 +93,6 @@ def analyze_receipts_from_url(): if total: print(f"Total: {format_price(total.get('valueCurrency'))} has confidence: {total.confidence}") print("--------------------------------------") - # [END analyze_receipts_from_url] if __name__ == "__main__": diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_tax_us_w2.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_tax_us_w2.py index 8aef15bf372d..3f50056f87f8 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_tax_us_w2.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_tax_us_w2.py @@ -45,9 +45,9 @@ def analyze_tax_us_w2(): endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] - document_analysis_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) + document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) with open(path_to_sample_documents, "rb") as f: - poller = document_analysis_client.begin_analyze_document( + poller = document_intelligence_client.begin_analyze_document( "prebuilt-tax.us.w2", analyze_request=f, locale="en-US", content_type="application/octet-stream" ) w2s = poller.result() diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_classify_document.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_classify_document.py index 0b12d2ad7692..ef5f8020c423 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_classify_document.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_classify_document.py @@ -48,11 +48,11 @@ def classify_document(classifier_id): key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] classifier_id = os.getenv("CLASSIFIER_ID", classifier_id) - document_analysis_client = DocumentIntelligenceClient( + document_intelligence_client = DocumentIntelligenceClient( endpoint=endpoint, credential=AzureKeyCredential(key) ) with open(path_to_sample_documents, "rb") as f: - poller = document_analysis_client.begin_classify_document( + poller = document_intelligence_client.begin_classify_document( classifier_id, classify_request=f, content_type="application/octet-stream" ) result = poller.result() @@ -87,11 +87,11 @@ def classify_document(classifier_id): key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] blob_container_sas_url = os.environ["DOCUMENTINTELLIGENCE_TRAINING_DATA_CLASSIFIER_SAS_URL"] - document_model_admin_client = DocumentIntelligenceAdministrationClient( + document_intelligence_admin_client = DocumentIntelligenceAdministrationClient( endpoint=endpoint, credential=AzureKeyCredential(key) ) - poller = document_model_admin_client.begin_build_classifier( + poller = document_intelligence_admin_client.begin_build_classifier( BuildDocumentClassifierRequest( classifier_id=str(uuid.uuid4()), doc_types={ diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_compose_model.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_compose_model.py index ed2e7abc6b17..0d2f2b5a5c7e 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_compose_model.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_compose_model.py @@ -52,10 +52,10 @@ def sample_compose_model(): key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] container_sas_url = os.environ["DOCUMENTINTELLIGENCE_STORAGE_CONTAINER_SAS_URL"] - document_model_admin_client = DocumentIntelligenceAdministrationClient( + document_intelligence_admin_client = DocumentIntelligenceAdministrationClient( endpoint=endpoint, credential=AzureKeyCredential(key) ) - supplies_poller = document_model_admin_client.begin_build_document_model( + supplies_poller = document_intelligence_admin_client.begin_build_document_model( BuildDocumentModelRequest( model_id=str(uuid.uuid4()), build_mode=DocumentBuildMode.TEMPLATE, @@ -63,7 +63,7 @@ def sample_compose_model(): description="Purchase order-Office Supplies", ) ) - equipment_poller = document_model_admin_client.begin_build_document_model( + equipment_poller = document_intelligence_admin_client.begin_build_document_model( BuildDocumentModelRequest( model_id=str(uuid.uuid4()), build_mode=DocumentBuildMode.TEMPLATE, @@ -71,7 +71,7 @@ def sample_compose_model(): description="Purchase order-Office Equipment", ) ) - furniture_poller = document_model_admin_client.begin_build_document_model( + furniture_poller = document_intelligence_admin_client.begin_build_document_model( BuildDocumentModelRequest( model_id=str(uuid.uuid4()), build_mode=DocumentBuildMode.TEMPLATE, @@ -79,7 +79,7 @@ def sample_compose_model(): description="Purchase order-Office Furniture", ) ) - cleaning_supplies_poller = document_model_admin_client.begin_build_document_model( + cleaning_supplies_poller = document_intelligence_admin_client.begin_build_document_model( BuildDocumentModelRequest( model_id=str(uuid.uuid4()), build_mode=DocumentBuildMode.TEMPLATE, @@ -92,7 +92,7 @@ def sample_compose_model(): furniture_model = furniture_poller.result() cleaning_supplies_model = cleaning_supplies_poller.result() - poller = document_model_admin_client.begin_compose_model( + poller = document_intelligence_admin_client.begin_compose_model( ComposeDocumentModelRequest( model_id=str(uuid.uuid4()), component_models=[ diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_copy_model_to.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_copy_model_to.py index b9e21fabd56f..55ab00eccae1 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_copy_model_to.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_copy_model_to.py @@ -100,7 +100,7 @@ def sample_copy_model_to(custom_model_id): if not endpoint or not key: raise ValueError("Please provide endpoint and API key to run the samples.") - document_model_admin_client = DocumentIntelligenceAdministrationClient( + document_intelligence_admin_client = DocumentIntelligenceAdministrationClient( endpoint=endpoint, credential=AzureKeyCredential(key) ) blob_container_sas_url = os.getenv("DOCUMENTINTELLIGENCE_STORAGE_CONTAINER_SAS_URL") @@ -110,7 +110,7 @@ def sample_copy_model_to(custom_model_id): build_mode=DocumentBuildMode.TEMPLATE, azure_blob_source=AzureBlobContentSource(container_url=blob_container_sas_url), ) - model = document_model_admin_client.begin_build_document_model(request).result() + model = document_intelligence_admin_client.begin_build_document_model(request).result() model_id = model.model_id sample_copy_model_to(model_id) except HttpResponseError as error: diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_manage_classifiers.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_manage_classifiers.py index 7ca291fa289a..c4535d4c5a68 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_manage_classifiers.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_manage_classifiers.py @@ -40,12 +40,12 @@ def sample_manage_classifiers(): key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] container_sas_url = os.environ["DOCUMENTINTELLIGENCE_TRAINING_DATA_CLASSIFIER_SAS_URL"] - document_model_admin_client = DocumentIntelligenceAdministrationClient( + document_intelligence_admin_client = DocumentIntelligenceAdministrationClient( endpoint=endpoint, credential=AzureKeyCredential(key) ) # build a document classifier - poller = document_model_admin_client.begin_build_classifier( + poller = document_intelligence_admin_client.begin_build_classifier( BuildDocumentClassifierRequest( classifier_id=str(uuid.uuid4()), doc_types={ @@ -75,7 +75,7 @@ def sample_manage_classifiers(): # Next, we get a paged list of all of our document classifiers # [START list_classifiers] - classifiers = document_model_admin_client.list_classifiers() + classifiers = document_intelligence_admin_client.list_classifiers() print("We have the following 'ready' models with IDs and descriptions:") for classifier in classifiers: @@ -83,7 +83,7 @@ def sample_manage_classifiers(): # [END list_classifiers] # [START get_classifier] - my_classifier = document_model_admin_client.get_classifier(classifier_id=classifier.classifier_id) + my_classifier = document_intelligence_admin_client.get_classifier(classifier_id=classifier.classifier_id) print(f"\nClassifier ID: {my_classifier.classifier_id}") print(f"Description: {my_classifier.description}") print(f"Classifier created on: {my_classifier.created_date_time}") @@ -92,12 +92,12 @@ def sample_manage_classifiers(): # Finally, we will delete this classifier by ID # [START delete_classifier] - document_model_admin_client.delete_classifier(classifier_id=my_classifier.classifier_id) + document_intelligence_admin_client.delete_classifier(classifier_id=my_classifier.classifier_id) # [END delete_document_classifier] from azure.core.exceptions import ResourceNotFoundError try: - document_model_admin_client.get_classifier(classifier_id=my_classifier.classifier_id) + document_intelligence_admin_client.get_classifier(classifier_id=my_classifier.classifier_id) except ResourceNotFoundError: print(f"Successfully deleted classifier with ID {my_classifier.classifier_id}") diff --git a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_manage_models.py b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_manage_models.py index 212ef7dd387b..9f7b01575209 100644 --- a/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_manage_models.py +++ b/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_manage_models.py @@ -26,8 +26,8 @@ def sample_manage_models(): - # Let's build a model to use for this sample # [START build_model] + # Let's build a model to use for this sample import uuid from azure.ai.documentintelligence import DocumentIntelligenceAdministrationClient from azure.ai.documentintelligence.models import ( @@ -41,10 +41,10 @@ def sample_manage_models(): key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] container_sas_url = os.environ["DOCUMENTINTELLIGENCE_STORAGE_CONTAINER_SAS_URL"] - document_model_admin_client = DocumentIntelligenceAdministrationClient( + document_intelligence_admin_client = DocumentIntelligenceAdministrationClient( endpoint, AzureKeyCredential(key) ) - poller = document_model_admin_client.begin_build_document_model( + poller = document_intelligence_admin_client.begin_build_document_model( BuildDocumentModelRequest( model_id=str(uuid.uuid4()), build_mode=DocumentBuildMode.TEMPLATE, @@ -71,7 +71,7 @@ def sample_manage_models(): # [END build_model] # [START get_resource_info] - account_details = document_model_admin_client.get_resource_info() + account_details = document_intelligence_admin_client.get_resource_info() print( f"Our resource has {account_details.custom_document_models.count} custom models, " f"and we can have at most {account_details.custom_document_models.limit} custom models" @@ -83,9 +83,9 @@ def sample_manage_models(): ) # [END get_resource_info] - # Next, we get a paged list of all of our custom models # [START list_models] - models = document_model_admin_client.list_models() + # Next, we get a paged list of all of our custom models + models = document_intelligence_admin_client.list_models() print("We have the following 'ready' models with IDs and descriptions:") for model in models: @@ -93,23 +93,23 @@ def sample_manage_models(): # [END list_models] # [START get_model] - my_model = document_model_admin_client.get_model(model_id=model.model_id) + my_model = document_intelligence_admin_client.get_model(model_id=model.model_id) print(f"\nModel ID: {my_model.model_id}") print(f"Description: {my_model.description}") print(f"Model created on: {my_model.created_date_time}") print(f"Model expires on: {my_model.expiration_date_time}") # [END get_model] - # Finally, we will delete this model by ID # [START delete_model] - document_model_admin_client.delete_model(model_id=my_model.model_id) - # [END delete_document_model] + # Finally, we will delete this model by ID + document_intelligence_admin_client.delete_model(model_id=my_model.model_id) from azure.core.exceptions import ResourceNotFoundError try: - document_model_admin_client.get_model(model_id=my_model.model_id) + document_intelligence_admin_client.get_model(model_id=my_model.model_id) except ResourceNotFoundError: print(f"Successfully deleted model with ID {my_model.model_id}") + # [END delete_model] if __name__ == "__main__":