Skip to content

Commit 723d47c

Browse files
author
Yalin Li
authored
[DI] Patch default polling interval (#33463)
1 parent 0e7973d commit 723d47c

File tree

10 files changed

+214
-9
lines changed

10 files changed

+214
-9
lines changed

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

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

1111
### Other Changes
1212

13+
- Changed the default polling interval from 30s to 5s.
14+
1315
## 1.0.0b1 (2023-11-17)
1416

1517
This is the first preview of the `azure-ai-documentintelligence` package, targeting API version `2023-10-31-preview` of the Document Intelligence service(formerly known as Form Recognizer).

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_f46d5cfe2d"
5+
"Tag": "python/documentintelligence/azure-ai-documentintelligence_3a7d15d3b0"
66
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131

3232
class DocumentIntelligenceAdministrationClientOperationsMixin(GeneratedDIAdminClientOps): # pylint: disable=name-too-long
33-
__doc__ = GeneratedDIAdminClientOps.__doc__
3433

3534
@distributed_trace
3635
def begin_build_classifier(

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

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,82 @@
66
77
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
88
"""
9-
from typing import List
9+
from typing import Any, List, Union
1010

11-
__all__: List[str] = [] # Add all objects you want publicly available to users at this package level
11+
from azure.core.credentials import AzureKeyCredential, TokenCredential
12+
13+
from ._client import(
14+
DocumentIntelligenceClient as DIClientGenerated,
15+
DocumentIntelligenceAdministrationClient as DIAClientGenerated,
16+
)
17+
18+
19+
class DocumentIntelligenceClient(DIClientGenerated): # pylint: disable=client-accepts-api-version-keyword
20+
"""DocumentIntelligenceClient.
21+
22+
:param endpoint: The Document Intelligence service endpoint. Required.
23+
:type endpoint: str
24+
:param credential: Credential needed for the client to connect to Azure. Is either a
25+
AzureKeyCredential type or a TokenCredential type. Required.
26+
:type credential: ~azure.core.credentials.AzureKeyCredential or
27+
~azure.core.credentials.TokenCredential
28+
:keyword api_version: The API version to use for this operation. Default value is
29+
"2023-10-31-preview". Note that overriding this default value may result in unsupported
30+
behavior.
31+
:paramtype api_version: str
32+
"""
33+
34+
def __init__(
35+
self,
36+
endpoint: str,
37+
credential: Union[AzureKeyCredential, TokenCredential],
38+
**kwargs: Any,
39+
) -> None:
40+
# The default polling interval should be 5 seconds.
41+
polling_interval = kwargs.pop("polling_interval", 5)
42+
super().__init__(
43+
endpoint=endpoint,
44+
credential=credential,
45+
polling_interval=polling_interval,
46+
**kwargs,
47+
)
48+
49+
50+
class DocumentIntelligenceAdministrationClient(DIAClientGenerated): # pylint: disable=client-accepts-api-version-keyword
51+
"""DocumentIntelligenceAdministrationClient.
52+
53+
:param endpoint: The Document Intelligence service endpoint. Required.
54+
:type endpoint: str
55+
:param credential: Credential needed for the client to connect to Azure. Is either a
56+
AzureKeyCredential type or a TokenCredential type. Required.
57+
:type credential: ~azure.core.credentials.AzureKeyCredential or
58+
~azure.core.credentials.TokenCredential
59+
:keyword api_version: The API version to use for this operation. Default value is
60+
"2023-10-31-preview". Note that overriding this default value may result in unsupported
61+
behavior.
62+
:paramtype api_version: str
63+
"""
64+
65+
def __init__(
66+
self,
67+
endpoint: str,
68+
credential: Union[AzureKeyCredential, TokenCredential],
69+
**kwargs: Any,
70+
) -> None:
71+
# The default polling interval should be 5 seconds.
72+
polling_interval = kwargs.pop("polling_interval", 5)
73+
super().__init__(
74+
endpoint=endpoint,
75+
credential=credential,
76+
polling_interval=polling_interval,
77+
**kwargs,
78+
)
79+
80+
81+
__all__: List[str] = [
82+
"DocumentIntelligenceClient",
83+
"DocumentIntelligenceAdministrationClient",
84+
] # Add all objects you want publicly available to users at this package level
1285

1386

1487
def patch_sdk():

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131

3232
class DocumentIntelligenceAdministrationClientOperationsMixin(GeneratedDIAdminClientOps): # pylint: disable=name-too-long
33-
__doc__ = GeneratedDIAdminClientOps.__doc__
3433

3534
@distributed_trace_async
3635
async def begin_build_classifier(

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

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,83 @@
66
77
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
88
"""
9-
from typing import List
9+
from typing import Any, List, Union
1010

11-
__all__: List[str] = [] # Add all objects you want publicly available to users at this package level
11+
from azure.core.credentials import AzureKeyCredential
12+
from azure.core.credentials_async import AsyncTokenCredential
13+
14+
from ._client import(
15+
DocumentIntelligenceClient as DIClientGenerated,
16+
DocumentIntelligenceAdministrationClient as DIAClientGenerated,
17+
)
18+
19+
20+
class DocumentIntelligenceClient(DIClientGenerated): # pylint: disable=client-accepts-api-version-keyword
21+
"""DocumentIntelligenceClient.
22+
23+
:param endpoint: The Document Intelligence service endpoint. Required.
24+
:type endpoint: str
25+
:param credential: Credential needed for the client to connect to Azure. Is either a
26+
AzureKeyCredential type or a TokenCredential type. Required.
27+
:type credential: ~azure.core.credentials.AzureKeyCredential or
28+
~azure.core.credentials_async.AsyncTokenCredential
29+
:keyword api_version: The API version to use for this operation. Default value is
30+
"2023-10-31-preview". Note that overriding this default value may result in unsupported
31+
behavior.
32+
:paramtype api_version: str
33+
"""
34+
35+
def __init__(
36+
self,
37+
endpoint: str,
38+
credential: Union[AzureKeyCredential, AsyncTokenCredential],
39+
**kwargs: Any,
40+
) -> None:
41+
# The default polling interval should be 5 seconds.
42+
polling_interval = kwargs.pop("polling_interval", 5)
43+
super().__init__(
44+
endpoint=endpoint,
45+
credential=credential,
46+
polling_interval=polling_interval,
47+
**kwargs,
48+
)
49+
50+
51+
class DocumentIntelligenceAdministrationClient(DIAClientGenerated): # pylint: disable=client-accepts-api-version-keyword
52+
"""DocumentIntelligenceAdministrationClient.
53+
54+
:param endpoint: The Document Intelligence service endpoint. Required.
55+
:type endpoint: str
56+
:param credential: Credential needed for the client to connect to Azure. Is either a
57+
AzureKeyCredential type or a TokenCredential type. Required.
58+
:type credential: ~azure.core.credentials.AzureKeyCredential or
59+
~azure.core.credentials_async.AsyncTokenCredential
60+
:keyword api_version: The API version to use for this operation. Default value is
61+
"2023-10-31-preview". Note that overriding this default value may result in unsupported
62+
behavior.
63+
:paramtype api_version: str
64+
"""
65+
66+
def __init__(
67+
self,
68+
endpoint: str,
69+
credential: Union[AzureKeyCredential, AsyncTokenCredential],
70+
**kwargs: Any,
71+
) -> None:
72+
# The default polling interval should be 5 seconds.
73+
polling_interval = kwargs.pop("polling_interval", 5)
74+
super().__init__(
75+
endpoint=endpoint,
76+
credential=credential,
77+
polling_interval=polling_interval,
78+
**kwargs,
79+
)
80+
81+
82+
__all__: List[str] = [
83+
"DocumentIntelligenceClient",
84+
"DocumentIntelligenceAdministrationClient",
85+
] # Add all objects you want publicly available to users at this package level
1286

1387

1488
def patch_sdk():

sdk/documentintelligence/azure-ai-documentintelligence/samples/aio/sample_analyze_documents_output_in_markdown_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async def analyze_documents_output_in_markdown():
4343
)
4444
result = await poller.result()
4545

46-
print(f"Here's the full content in format{result.content_format}:\n")
46+
print(f"Here's the full content in format {result.content_format}:\n")
4747
print(result.content)
4848
# [END analyze_documents_output_in_markdown]
4949

sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_analyze_documents_output_in_markdown.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def analyze_documents_output_in_markdown():
4141
)
4242
result = poller.result()
4343

44-
print(f"Here's the full content in format{result.content_format}:\n")
44+
print(f"Here's the full content in format {result.content_format}:\n")
4545
print(result.content)
4646
# [END analyze_documents_output_in_markdown]
4747

sdk/documentintelligence/azure-ai-documentintelligence/tests/test_dac_analyze_layout.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pytest
88
import functools
99
from devtools_testutils import recorded_by_proxy
10+
from azure.core.credentials import AzureKeyCredential
1011
from azure.ai.documentintelligence import DocumentIntelligenceClient
1112
from azure.ai.documentintelligence.models import DocumentAnalysisFeature, AnalyzeDocumentRequest
1213
from testcase import DocumentIntelligenceTest
@@ -141,3 +142,31 @@ def test_layout_url_barcode(self, client):
141142
assert layout.pages[0].barcodes[0].kind == "Code39"
142143
assert layout.pages[0].barcodes[0].polygon
143144
assert layout.pages[0].barcodes[0].confidence > 0.8
145+
146+
147+
@skip_flaky_test
148+
@DocumentIntelligencePreparer()
149+
@recorded_by_proxy
150+
def test_polling_interval(self, documentintelligence_endpoint, documentintelligence_api_key, **kwargs):
151+
client = DocumentIntelligenceClient(
152+
documentintelligence_endpoint, AzureKeyCredential(documentintelligence_api_key)
153+
)
154+
assert client._config.polling_interval == 5
155+
156+
client = DocumentIntelligenceClient(
157+
documentintelligence_endpoint, AzureKeyCredential(documentintelligence_api_key), polling_interval=7
158+
)
159+
assert client._config.polling_interval == 7
160+
poller = client.begin_analyze_document(
161+
"prebuilt-receipt",
162+
AnalyzeDocumentRequest(url_source=self.receipt_url_jpg),
163+
polling_interval=6
164+
)
165+
poller.wait()
166+
assert poller._polling_method._timeout == 6
167+
poller2 = client.begin_analyze_document(
168+
"prebuilt-receipt",
169+
AnalyzeDocumentRequest(url_source=self.receipt_url_jpg),
170+
)
171+
poller2.wait()
172+
assert poller2._polling_method._timeout == 7 # goes back to client default

sdk/documentintelligence/azure-ai-documentintelligence/tests/test_dac_analyze_layout_async.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pytest
88
import functools
99
from devtools_testutils.aio import recorded_by_proxy_async
10+
from azure.core.credentials import AzureKeyCredential
1011
from azure.ai.documentintelligence.aio import DocumentIntelligenceClient
1112
from azure.ai.documentintelligence.models import DocumentAnalysisFeature, AnalyzeDocumentRequest
1213
from asynctestcase import AsyncDocumentIntelligenceTest
@@ -144,3 +145,31 @@ async def test_layout_url_barcodes(self, client):
144145
assert layout.pages[0].barcodes[0].kind == "Code39"
145146
assert layout.pages[0].barcodes[0].polygon
146147
assert layout.pages[0].barcodes[0].confidence > 0.8
148+
149+
@skip_flaky_test
150+
@DocumentIntelligencePreparer()
151+
@recorded_by_proxy_async
152+
async def test_polling_interval(self, documentintelligence_endpoint, documentintelligence_api_key, **kwargs):
153+
client = DocumentIntelligenceClient(
154+
documentintelligence_endpoint, AzureKeyCredential(documentintelligence_api_key)
155+
)
156+
assert client._config.polling_interval == 5
157+
158+
client = DocumentIntelligenceClient(
159+
documentintelligence_endpoint, AzureKeyCredential(documentintelligence_api_key), polling_interval=7
160+
)
161+
assert client._config.polling_interval == 7
162+
async with client:
163+
poller = await client.begin_analyze_document(
164+
"prebuilt-receipt",
165+
AnalyzeDocumentRequest(url_source=self.receipt_url_jpg),
166+
polling_interval=6
167+
)
168+
await poller.wait()
169+
assert poller._polling_method._timeout == 6
170+
poller2 = await client.begin_analyze_document(
171+
"prebuilt-receipt",
172+
AnalyzeDocumentRequest(url_source=self.receipt_url_jpg),
173+
)
174+
await poller2.wait()
175+
assert poller2._polling_method._timeout == 7 # goes back to client default

0 commit comments

Comments
 (0)