Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DocumentIntelligenceClient raising a TypeError - begin_analyze_document() missing 'body' #2244

Open
1 of 4 tasks
O-EAI opened this issue Dec 19, 2024 · 3 comments
Open
1 of 4 tasks

Comments

@O-EAI
Copy link

O-EAI commented Dec 19, 2024

Please provide us with the following information:

This issue is for a: (mark with an x)

  • bug report -> please search issues before submitting
  • feature request
  • documentation issue or request
  • regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

  • Run the code provided in the pdfparser.py file that uses the DocumentIntelligenceClient with begin_analyze_document.
  • DocumentIntelligenceClientuse_content_understanding=False,
  • Ensure the input is valid and the required dependencies (Azure SDK, pymupdf, etc.) are installed.
  • Trigger the function that calls begin_analyze_document.

Log message

TypeError: DocumentIntelligenceClientOperationsMixin.begin_analyze_document() missing 1 required positional argument: 'body'

Expected/desired behavior

The begin_analyze_document method should successfully process the document without raising a TypeError.

Versions

  • Python: 3.11
  • azure-ai-documentintelligence==1.0.0

Useful details

The problem arises when calling the begin_analyze_document method on the DocumentIntelligenceClient. The error suggests that the required body argument is not being provided. Below is the relevant code snippet:

async with DocumentIntelligenceClient(
        endpoint=self.endpoint, credential=self.credential
    ) as document_intelligence_client:
        if self.use_content_understanding:
            if self.content_understanding_endpoint is None:
                raise ValueError("Content Understanding is enabled but no endpoint was provided")
            if isinstance(self.credential, AzureKeyCredential):
                raise ValueError(
                    "AzureKeyCredential is not supported for Content Understanding, use keyless auth instead"
                )
            cu_describer = ContentUnderstandingDescriber(self.content_understanding_endpoint, self.credential)
            content_bytes = content.read()
            poller = await document_intelligence_client.begin_analyze_document(
                model_id="prebuilt-layout",
                analyze_request=AnalyzeDocumentRequest(bytes_source=content_bytes),
                output=["figures"],
                features=["ocrHighResolution"],
                output_content_format="markdown",
            )
            doc_for_pymupdf = pymupdf.open(stream=io.BytesIO(content_bytes))
        else:
            poller = await document_intelligence_client.begin_analyze_document(
                model_id=self.model_id, analyze_request=content, content_type="application/octet-stream"
            )
        analyze_result: AnalyzeResult = await poller.result()
@hosimesi
Copy link

hosimesi commented Dec 20, 2024

I'm in the same situation. You could use this one.
I think it's because the documentation hasn't kept up with the latest updates.

async with DocumentIntelligenceClient(
        endpoint=self.endpoint, credential=self.credential
    ) as document_intelligence_client:
        if self.use_content_understanding:
            if self.content_understanding_endpoint is None:
                raise ValueError("Content Understanding is enabled but no endpoint was provided")
            if isinstance(self.credential, AzureKeyCredential):
                raise ValueError(
                    "AzureKeyCredential is not supported for Content Understanding, use keyless auth instead"
                )
            cu_describer = ContentUnderstandingDescriber(self.content_understanding_endpoint, self.credential)
            content_bytes = content.read()
            poller = await document_intelligence_client.begin_analyze_document(
                model_id="prebuilt-layout",
                body=AnalyzeDocumentRequest(bytes_source=content_bytes),  #  analyze_request -> body
                output=["figures"],
                features=["ocrHighResolution"],
                output_content_format="markdown",
            )
            doc_for_pymupdf = pymupdf.open(stream=io.BytesIO(content_bytes))
        else:
            poller = await document_intelligence_client.begin_analyze_document(
                model_id=self.model_id, analyze_request=content, content_type="application/octet-stream"
            )
        analyze_result: AnalyzeResult = await poller.result()

@o1100
Copy link

o1100 commented Dec 20, 2024

Yeah, I have this too. Will do a pull request this weekend, just waiting to run the required tests.

@ElisaPiccin
Copy link

I tried this solution and it worked for me: Azure/azure-sdk-for-python#38622
I also applied it to document_intelligence_client.begin_classify_document() for inference from a custom classification model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants