Skip to content

Commit 13e01ff

Browse files
[documentintelligence] Code fixes (Azure#38920)
* fix samples * fix content type * remove models patch * fix content type logic + update tests * update docs * pylint * support bufferedreader input --------- Co-authored-by: catalinaperalta <[email protected]>
1 parent da4f140 commit 13e01ff

File tree

15 files changed

+38
-69
lines changed

15 files changed

+38
-69
lines changed

sdk/documentintelligence/azure-ai-documentintelligence/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
### Other Changes
3636

37+
- Changed the default service API version to `2024-11-30`.
3738
- No need to pass `content-type` when analyze_request is a stream in `begin_analyze_document()` and `begin_classify_document()`.
3839

3940
## 1.0.0b4 (2024-09-05)

sdk/documentintelligence/azure-ai-documentintelligence/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ client = DocumentIntelligenceAdministrationClient(endpoint=endpoint, credential=
951951
# The `send_request` method can send custom HTTP requests that share the client's existing pipeline,
952952
# Now let's use the `send_request` method to make a resource details fetching request.
953953
# The URL of the request should be absolute, and append the API version used for the request.
954-
request = HttpRequest(method="GET", url=f"{endpoint}/documentintelligence/info?api-version=2024-07-31-preview")
954+
request = HttpRequest(method="GET", url=f"{endpoint}/documentintelligence/info?api-version=2024-11-30")
955955
response = client.send_request(request)
956956
response.raise_for_status()
957957
response_body = response.json()

sdk/documentintelligence/azure-ai-documentintelligence/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/documentintelligence/azure-ai-documentintelligence",
5-
"Tag": "python/documentintelligence/azure-ai-documentintelligence_faf458f6e7"
5+
"Tag": "python/documentintelligence/azure-ai-documentintelligence_bfcdb2d242"
66
}

sdk/documentintelligence/azure-ai-documentintelligence/azure/ai/documentintelligence/_operations/_patch.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ def begin_analyze_document(
449449
450450
:param model_id: Unique document model name. Required.
451451
:type model_id: str
452-
:param body: Analyze request parameters. Default value is None.
452+
:param body: Analyze request parameters. Required.
453453
:type body: JSON
454454
:keyword pages: 1-based page numbers to analyze. Ex. "1-3,5,7-9". Default value is None.
455455
:paramtype pages: str
@@ -501,7 +501,7 @@ def begin_analyze_document(
501501
502502
:param model_id: Unique document model name. Required.
503503
:type model_id: str
504-
:param body: Analyze request parameters. Default value is None.
504+
:param body: Analyze request parameters. Required.
505505
:type body: IO[bytes]
506506
:keyword pages: 1-based page numbers to analyze. Ex. "1-3,5,7-9". Default value is None.
507507
:paramtype pages: str
@@ -553,7 +553,7 @@ def begin_analyze_document(
553553
:param model_id: Unique document model name. Required.
554554
:type model_id: str
555555
:param body: Analyze request parameters. Is one of the following types:
556-
AnalyzeDocumentRequest, JSON, IO[bytes] Default value is None.
556+
AnalyzeDocumentRequest, JSON, IO[bytes] Required.
557557
:type body: ~azure.ai.documentintelligence.models.AnalyzeDocumentRequest or JSON or
558558
IO[bytes]
559559
:keyword pages: 1-based page numbers to analyze. Ex. "1-3,5,7-9". Default value is None.
@@ -585,15 +585,13 @@ def begin_analyze_document(
585585
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
586586
_params = kwargs.pop("params", {}) or {}
587587

588-
content_type: Optional[str] = kwargs.pop(
589-
"content_type", _headers.pop("content-type", "application/octet-stream")
590-
)
588+
content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("content-type", None))
591589
cls: ClsType[_models.AnalyzeResult] = kwargs.pop("cls", None)
592590
polling: Union[bool, PollingMethod] = kwargs.pop("polling", True)
593591
lro_delay = kwargs.pop("polling_interval", self._config.polling_interval)
594592
cont_token: Optional[str] = kwargs.pop("continuation_token", None)
595593
if cont_token is None:
596-
if isinstance(body, io.BytesIO):
594+
if isinstance(body, (bytes, io.BytesIO, io.BufferedReader)):
597595
content_type = "application/octet-stream"
598596
raw_result = self._analyze_document_initial(
599597
model_id=model_id,
@@ -683,10 +681,8 @@ def begin_classify_document(
683681
:raises ~azure.core.exceptions.HttpResponseError:
684682
"""
685683
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
686-
content_type: Optional[str] = kwargs.pop(
687-
"content_type", _headers.pop("content-type", "application/octet-stream")
688-
)
689-
if isinstance(body, io.BytesIO):
684+
content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("content-type", None))
685+
if isinstance(body, (bytes, io.BytesIO, io.BufferedReader)):
690686
content_type = "application/octet-stream"
691687
return super().begin_classify_document( # type: ignore[arg-type, misc]
692688
classifier_id=classifier_id,

sdk/documentintelligence/azure-ai-documentintelligence/azure/ai/documentintelligence/_patch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class DocumentIntelligenceClient(DIClientGenerated):
2525
:type credential: ~azure.core.credentials.AzureKeyCredential or
2626
~azure.core.credentials.TokenCredential
2727
:keyword api_version: The API version to use for this operation. Default value is
28-
"2024-07-31-preview". Note that overriding this default value may result in unsupported
28+
"2024-11-30". Note that overriding this default value may result in unsupported
2929
behavior.
3030
:paramtype api_version: str
3131
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
@@ -58,7 +58,7 @@ class DocumentIntelligenceAdministrationClient(DIAClientGenerated):
5858
:type credential: ~azure.core.credentials.AzureKeyCredential or
5959
~azure.core.credentials.TokenCredential
6060
:keyword api_version: The API version to use for this operation. Default value is
61-
"2024-07-31-preview". Note that overriding this default value may result in unsupported
61+
"2024-11-30". Note that overriding this default value may result in unsupported
6262
behavior.
6363
:paramtype api_version: str
6464
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no

sdk/documentintelligence/azure-ai-documentintelligence/azure/ai/documentintelligence/aio/_operations/_patch.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -566,15 +566,13 @@ async def begin_analyze_document( # type: ignore[override]
566566
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
567567
_params = kwargs.pop("params", {}) or {}
568568

569-
content_type: Optional[str] = kwargs.pop(
570-
"content_type", _headers.pop("content-type", "application/octet-stream")
571-
)
569+
content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("content-type", None))
572570
cls: ClsType[_models.AnalyzeResult] = kwargs.pop("cls", None)
573571
polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True)
574572
lro_delay = kwargs.pop("polling_interval", self._config.polling_interval)
575573
cont_token: Optional[str] = kwargs.pop("continuation_token", None)
576574
if cont_token is None:
577-
if isinstance(body, io.BytesIO):
575+
if isinstance(body, (bytes, io.BytesIO, io.BufferedReader)):
578576
content_type = "application/octet-stream"
579577
raw_result = await self._analyze_document_initial(
580578
model_id=model_id,
@@ -665,10 +663,8 @@ async def begin_classify_document( # type: ignore[override]
665663
:raises ~azure.core.exceptions.HttpResponseError:
666664
"""
667665
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
668-
content_type: Optional[str] = kwargs.pop(
669-
"content_type", _headers.pop("content-type", "application/octet-stream")
670-
)
671-
if isinstance(body, io.BytesIO):
666+
content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("content-type", None))
667+
if isinstance(body, (bytes, io.BytesIO, io.BufferedReader)):
672668
content_type = "application/octet-stream"
673669
return await super().begin_classify_document( # type: ignore[arg-type, misc]
674670
classifier_id=classifier_id,

sdk/documentintelligence/azure-ai-documentintelligence/azure/ai/documentintelligence/aio/_patch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class DocumentIntelligenceClient(DIClientGenerated):
2828
:type credential: ~azure.core.credentials.AzureKeyCredential or
2929
~azure.core.credentials_async.AsyncTokenCredential
3030
:keyword api_version: The API version to use for this operation. Default value is
31-
"2024-07-31-preview". Note that overriding this default value may result in unsupported
31+
"2024-11-30". Note that overriding this default value may result in unsupported
3232
behavior.
3333
:paramtype api_version: str
3434
"""
@@ -59,7 +59,7 @@ class DocumentIntelligenceAdministrationClient(DIAClientGenerated):
5959
:type credential: ~azure.core.credentials.AzureKeyCredential or
6060
~azure.core.credentials_async.AsyncTokenCredential
6161
:keyword api_version: The API version to use for this operation. Default value is
62-
"2024-07-31-preview". Note that overriding this default value may result in unsupported
62+
"2024-11-30". Note that overriding this default value may result in unsupported
6363
behavior.
6464
:paramtype api_version: str
6565
"""

sdk/documentintelligence/azure-ai-documentintelligence/azure/ai/documentintelligence/models/_patch.py

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,9 @@
66
77
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
88
"""
9-
from typing import List, Optional
10-
from ._models import (
11-
AnalyzeDocumentRequest as GeneratedAnalyzeDocumentRequest,
12-
ClassifyDocumentRequest as GeneratedClassifyDocumentRequest,
13-
)
14-
from .._model_base import rest_field
9+
from typing import List
1510

16-
17-
class AnalyzeDocumentRequest(GeneratedAnalyzeDocumentRequest):
18-
"""Document analysis parameters.
19-
20-
:ivar url_source: Document URL to analyze. Either url_source or bytes_source must be specified.
21-
:vartype url_source: str
22-
:ivar bytes_source: Document bytes to analyze. Either url_source or bytes_source must be specified.
23-
:vartype bytes_source: bytes
24-
"""
25-
26-
bytes_source: Optional[bytes] = rest_field(name="base64Source", format="base64")
27-
"""Document bytes to analyze. Either url_source or bytes_source must be specified."""
28-
29-
30-
class ClassifyDocumentRequest(GeneratedClassifyDocumentRequest):
31-
"""Document classification parameters.
32-
33-
:ivar url_source: Document URL to classify. Either url_source or bytes_source must be
34-
specified.
35-
:vartype url_source: str
36-
:ivar bytes_source: Document bytes to classify. Either url_source or bytes_source must be specified.
37-
:vartype bytes_source: bytes
38-
"""
39-
40-
bytes_source: Optional[bytes] = rest_field(name="base64Source", format="base64")
41-
"""Document bytes to classify. Either url_source or bytes_source must be specified."""
42-
43-
44-
__all__: List[str] = [
45-
"AnalyzeDocumentRequest",
46-
"ClassifyDocumentRequest",
47-
] # Add all objects you want publicly available to users at this package level
11+
__all__: List[str] = [] # Add all objects you want publicly available to users at this package level
4812

4913

5014
def patch_sdk():

sdk/documentintelligence/azure-ai-documentintelligence/samples/async_samples/sample_analyze_batch_documents_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ async def analyze_batch_docs():
5252

5353
endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"]
5454
key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"]
55-
result_container_sas_url = os.environ["RESULT_SAS_URL"]
56-
batch_training_data_container_sas_url = os.environ["TRAINING_DATA_SAS_URL"]
55+
result_container_sas_url = os.environ["RESULT_CONTAINER_SAS_URL"]
56+
batch_training_data_container_sas_url = os.environ["TRAINING_DATA_CONTAINER_SAS_URL"]
5757

5858
document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key))
5959

sdk/documentintelligence/azure-ai-documentintelligence/samples/async_samples/sample_analyze_receipts_async.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030

3131
def format_price(price_dict):
32+
if price_dict is None:
33+
return "N/A"
3234
return "".join([f"{p}" for p in price_dict.values()])
3335

3436

0 commit comments

Comments
 (0)