Skip to content

Commit 1d7a1ff

Browse files
Merge branch 'main' into xlsx_parse_merged_cells
2 parents ccf78f0 + 83ce26d commit 1d7a1ff

2 files changed

Lines changed: 42 additions & 7 deletions

File tree

packages/markitdown/src/markitdown/converters/_doc_intel_converter.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def __init__(
134134
self,
135135
*,
136136
endpoint: str,
137-
api_version: str = "2024-07-31-preview",
137+
api_version: str | None = None,
138138
credential: AzureKeyCredential | TokenCredential | None = None,
139139
file_types: List[DocumentIntelligenceFileType] = [
140140
DocumentIntelligenceFileType.DOCX,
@@ -152,7 +152,7 @@ def __init__(
152152
153153
Args:
154154
endpoint (str): The endpoint for the Document Intelligence service.
155-
api_version (str): The API version to use. Defaults to "2024-07-31-preview".
155+
api_version (str | None): The API version to use. Defaults to None.
156156
credential (AzureKeyCredential | TokenCredential | None): The credential to use for authentication.
157157
file_types (List[DocumentIntelligenceFileType]): The file types to accept. Defaults to all supported file types.
158158
"""
@@ -180,11 +180,15 @@ def __init__(
180180

181181
self.endpoint = endpoint
182182
self.api_version = api_version
183-
self.doc_intel_client = DocumentIntelligenceClient(
184-
endpoint=self.endpoint,
185-
api_version=self.api_version,
186-
credential=credential,
187-
)
183+
184+
client_kwargs: dict[str, Any] = {
185+
"endpoint": self.endpoint,
186+
"credential": credential,
187+
}
188+
if self.api_version is not None:
189+
client_kwargs["api_version"] = self.api_version
190+
191+
self.doc_intel_client = DocumentIntelligenceClient(**client_kwargs)
188192

189193
def accepts(
190194
self,

packages/markitdown/tests/test_docintel_html.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,34 @@ def test_docintel_accepts_html_mimetype():
2424
assert conv.accepts(io.BytesIO(b""), stream_info)
2525
stream_info = StreamInfo(mimetype="application/xhtml+xml", extension=None)
2626
assert conv.accepts(io.BytesIO(b""), stream_info)
27+
28+
29+
def test_docintel_api_version_default_none():
30+
from unittest.mock import patch
31+
32+
with patch(
33+
"markitdown.converters._doc_intel_converter.DocumentIntelligenceClient"
34+
) as mock_client:
35+
conv = DocumentIntelligenceConverter(
36+
endpoint="https://example.cognitiveservices.azure.com/",
37+
)
38+
assert conv.api_version is None
39+
mock_client.assert_called_once()
40+
_, kwargs = mock_client.call_args
41+
assert "api_version" not in kwargs
42+
43+
44+
def test_docintel_api_version_custom():
45+
from unittest.mock import patch
46+
47+
with patch(
48+
"markitdown.converters._doc_intel_converter.DocumentIntelligenceClient"
49+
) as mock_client:
50+
conv = DocumentIntelligenceConverter(
51+
endpoint="https://example.cognitiveservices.azure.com/",
52+
api_version="2024-07-31-preview",
53+
)
54+
assert conv.api_version == "2024-07-31-preview"
55+
mock_client.assert_called_once()
56+
_, kwargs = mock_client.call_args
57+
assert kwargs.get("api_version") == "2024-07-31-preview"

0 commit comments

Comments
 (0)