skip to Main Content

Using the code below I’m not able to call the latest api version "2024-02-29-preview" of the Azure AI Document Intelligence using prebuilt-layout. I’m in the correct region west europe where the version is available. The reason I want to use the newest version is as it supports figure extraction.

from azure.core.credentials import AzureKeyCredential
from azure.ai.formrecognizer import DocumentAnalysisClient

document_analysis_client = DocumentAnalysisClient(
    endpoint=endpoint, credential=AzureKeyCredential(key)
)


poller = document_analysis_client.begin_analyze_document_from_url('prebuilt-layout', formUrl, locale='de')
result = poller.result()
>>> print(result.api_version)
'2023-07-31'

I get the ‘2023-07-31’ version and the method documentation doesn’t indicate any keyword or parameter to be used to specifiy the version.
Just trying calling the method begin_analyze_document_from_url like

poller = document_analysis_client.begin_analyze_document_from_url('prebuilt-layout', formUrl, locale='de', api_version="2024-02-29-preview")

results in the Error:

Traceback (most recent call last):
  File "/snap/pycharm-professional/387/plugins/python/helpers-pro/pydevd_asyncio/pydevd_asyncio_utils.py", line 117, in _exec_async_code
    result = func()
             ^^^^^^
  File "<input>", line 1, in <module>
...
azure.core.exceptions.ResourceNotFoundError: (404) Resource not found
Code: 404
Message: Resource not found

I know that the fact the parameter is not implemented is causing the error, but where is the package implementing the functionality to specifically call the right API version. Can anybody help with that?

2

Answers


  1. Chosen as BEST ANSWER

    So it seems the DocumentAnalysisClient currently doesn't support preview API versions which is fine. Using REST works, starting with the examples in the documentation


  2. According to this doc the Document Intelligence 2024-02-29-preview REST API is now available. This preview API introduces new and updated capabilities:

    • Public preview version 2024-02-29-preview is currently available only in the following Azure regions:

      • East US
      • West US2
      • West Europe

    Install the library using pip

    pip install azure-ai-documentintelligence==1.0.0b2
    pip install azure-ai-formrecognizer
    
    • Get started with Azure AI Document Intelligence latest preview version (2024-02-29-preview) reference doc
    
    from azure.core.credentials import AzureKeyCredential
    from azure.ai.formrecognizer import DocumentAnalysisClient
    from azure.core.exceptions import HttpResponseError
    
    # Replace these values with your actual endpoint and key
    endpoint = "<your-endpoint>"
    key = "<your-key>"
    
    # Sample document URL
    formUrl = "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/sample-layout.pdf"
    
    try:
        # Create Document Analysis client
        document_analysis_client = DocumentAnalysisClient(
            endpoint=endpoint, credential=AzureKeyCredential(key)
        )
    
        # Analyze the document layout
        poller = document_analysis_client.begin_analyze_document_from_url('prebuilt-layout', formUrl, locale='de')
        results = poller.result()
    
        # Process the analysis results
        print("Document analysis results:")
        print(results)
    
    except HttpResponseError as e:
        print("HTTP Response Error:", e.response.status_code, e.message)
    
    except Exception as ex:
        print("An unexpected error occurred:", ex)
    
    

    Output:

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search