Skip to content

Commit 15d8d4e

Browse files
anakin87davidsbatista
authored andcommitted
chore!: mistral - drop Python 3.9 and use X|Y typing (#2716)
1 parent a9d9614 commit 15d8d4e

5 files changed

Lines changed: 42 additions & 48 deletions

File tree

integrations/mistral/pyproject.toml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,22 @@ name = "mistral-haystack"
77
dynamic = ["version"]
88
description = ''
99
readme = "README.md"
10-
requires-python = ">=3.9"
10+
requires-python = ">=3.10"
1111
license = "Apache-2.0"
1212
keywords = []
1313
authors = [{ name = "deepset GmbH", email = "info@deepset.ai" }]
1414
classifiers = [
1515
"License :: OSI Approved :: Apache Software License",
1616
"Development Status :: 4 - Beta",
1717
"Programming Language :: Python",
18-
"Programming Language :: Python :: 3.9",
1918
"Programming Language :: Python :: 3.10",
2019
"Programming Language :: Python :: 3.11",
2120
"Programming Language :: Python :: 3.12",
2221
"Programming Language :: Python :: 3.13",
2322
"Programming Language :: Python :: Implementation :: CPython",
2423
"Programming Language :: Python :: Implementation :: PyPy",
2524
]
26-
dependencies = ["haystack-ai>=2.19.0", "mistralai>=1.9.11"]
25+
dependencies = ["haystack-ai>=2.22.0", "mistralai>=1.9.11"]
2726

2827
[project.urls]
2928
Documentation = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/mistral#readme"
@@ -78,7 +77,6 @@ check_untyped_defs = true
7877
disallow_incomplete_defs = true
7978

8079
[tool.ruff]
81-
target-version = "py39"
8280
line-length = 120
8381

8482
[tool.ruff.lint]
@@ -125,10 +123,6 @@ ignore = [
125123
"B008",
126124
"S101",
127125
]
128-
unfixable = [
129-
# Don't touch unused imports
130-
"F401",
131-
]
132126

133127
[tool.ruff.lint.isort]
134128
known-first-party = ["haystack_integrations"]

integrations/mistral/src/haystack_integrations/components/converters/mistral/ocr_document_converter.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22
import re
33
from pathlib import Path
4-
from typing import Any, Optional, Union
4+
from typing import Any
55

66
from haystack import Document, component, default_from_dict, default_to_dict, logging
77
from haystack.components.converters.utils import (
@@ -103,9 +103,9 @@ def __init__(
103103
api_key: Secret = Secret.from_env_var("MISTRAL_API_KEY"),
104104
model: str = "mistral-ocr-2505",
105105
include_image_base64: bool = False,
106-
pages: Optional[list[int]] = None,
107-
image_limit: Optional[int] = None,
108-
image_min_size: Optional[int] = None,
106+
pages: list[int] | None = None,
107+
image_limit: int | None = None,
108+
image_min_size: int | None = None,
109109
cleanup_uploaded_files: bool = True,
110110
):
111111
"""
@@ -175,10 +175,10 @@ def from_dict(cls, data: dict[str, Any]) -> "MistralOCRDocumentConverter":
175175
@component.output_types(documents=list[Document], raw_mistral_response=list[dict[str, Any]])
176176
def run(
177177
self,
178-
sources: list[Union[str, Path, ByteStream, DocumentURLChunk, FileChunk, ImageURLChunk]],
179-
meta: Optional[Union[dict[str, Any], list[dict[str, Any]]]] = None,
180-
bbox_annotation_schema: Optional[type[BaseModel]] = None,
181-
document_annotation_schema: Optional[type[BaseModel]] = None,
178+
sources: list[str | Path | ByteStream | DocumentURLChunk | FileChunk | ImageURLChunk],
179+
meta: dict[str, Any] | list[dict[str, Any]] | None = None,
180+
bbox_annotation_schema: type[BaseModel] | None = None,
181+
document_annotation_schema: type[BaseModel] | None = None,
182182
) -> dict[str, Any]:
183183
"""
184184
Extract text from documents using Mistral OCR.
@@ -234,7 +234,7 @@ def run(
234234
raw_responses = []
235235
uploaded_file_ids = []
236236

237-
for source, user_metadata in zip(sources, meta_list):
237+
for source, user_metadata in zip(sources, meta_list, strict=True):
238238
document, raw_response, uploaded_file_id = self._process_single_source(
239239
source,
240240
user_metadata,
@@ -259,12 +259,12 @@ def run(
259259

260260
def _process_single_source(
261261
self,
262-
source: Union[str, Path, ByteStream, DocumentURLChunk, FileChunk, ImageURLChunk],
262+
source: str | Path | ByteStream | DocumentURLChunk | FileChunk | ImageURLChunk,
263263
user_metadata: dict[str, Any],
264-
bbox_annotation_format: Optional[Any],
265-
document_annotation_format: Optional[Any],
266-
document_annotation_schema: Optional[type[BaseModel]],
267-
) -> tuple[Optional[Document], Optional[dict[str, Any]], Optional[str]]:
264+
bbox_annotation_format: Any | None,
265+
document_annotation_format: Any | None,
266+
document_annotation_schema: type[BaseModel] | None,
267+
) -> tuple[Document | None, dict[str, Any] | None, str | None]:
268268
"""
269269
Process a single source and return the document, raw response, and file_id if uploaded.
270270
@@ -334,8 +334,8 @@ def _cleanup_uploaded_files(self, file_ids: list[str]) -> None:
334334

335335
def _convert_source_to_chunk(
336336
self,
337-
source: Union[str, Path, ByteStream, DocumentURLChunk, FileChunk, ImageURLChunk],
338-
) -> Union[DocumentURLChunk, FileChunk, ImageURLChunk]:
337+
source: str | Path | ByteStream | DocumentURLChunk | FileChunk | ImageURLChunk,
338+
) -> DocumentURLChunk | FileChunk | ImageURLChunk:
339339
"""
340340
Convert various source types to Mistral-compatible chunk format.
341341
@@ -371,7 +371,7 @@ def _process_ocr_response(
371371
self,
372372
ocr_response: OCRResponse,
373373
user_metadata: dict[str, Any],
374-
document_annotation_schema: Optional[type[BaseModel]],
374+
document_annotation_schema: type[BaseModel] | None,
375375
) -> Document:
376376
"""
377377
Convert an OCR response from Mistral API into a single Haystack Document.

integrations/mistral/src/haystack_integrations/components/embedders/mistral/document_embedder.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
22
#
33
# SPDX-License-Identifier: Apache-2.0
4-
from typing import Any, Optional
4+
from typing import Any
55

66
from haystack import component, default_to_dict
77
from haystack.components.embedders import OpenAIDocumentEmbedder
@@ -34,17 +34,17 @@ def __init__(
3434
self,
3535
api_key: Secret = Secret.from_env_var("MISTRAL_API_KEY"),
3636
model: str = "mistral-embed",
37-
api_base_url: Optional[str] = "https://api.mistral.ai/v1",
37+
api_base_url: str | None = "https://api.mistral.ai/v1",
3838
prefix: str = "",
3939
suffix: str = "",
4040
batch_size: int = 32,
4141
progress_bar: bool = True,
42-
meta_fields_to_embed: Optional[list[str]] = None,
42+
meta_fields_to_embed: list[str] | None = None,
4343
embedding_separator: str = "\n",
4444
*,
45-
timeout: Optional[float] = None,
46-
max_retries: Optional[int] = None,
47-
http_client_kwargs: Optional[dict[str, Any]] = None,
45+
timeout: float | None = None,
46+
max_retries: int | None = None,
47+
http_client_kwargs: dict[str, Any] | None = None,
4848
):
4949
"""
5050
Creates a MistralDocumentEmbedder component.

integrations/mistral/src/haystack_integrations/components/embedders/mistral/text_embedder.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
22
#
33
# SPDX-License-Identifier: Apache-2.0
4-
from typing import Any, Optional
4+
from typing import Any
55

66
from haystack import component, default_to_dict
77
from haystack.components.embedders import OpenAITextEmbedder
@@ -32,13 +32,13 @@ def __init__(
3232
self,
3333
api_key: Secret = Secret.from_env_var("MISTRAL_API_KEY"),
3434
model: str = "mistral-embed",
35-
api_base_url: Optional[str] = "https://api.mistral.ai/v1",
35+
api_base_url: str | None = "https://api.mistral.ai/v1",
3636
prefix: str = "",
3737
suffix: str = "",
3838
*,
39-
timeout: Optional[float] = None,
40-
max_retries: Optional[int] = None,
41-
http_client_kwargs: Optional[dict[str, Any]] = None,
39+
timeout: float | None = None,
40+
max_retries: int | None = None,
41+
http_client_kwargs: dict[str, Any] | None = None,
4242
):
4343
"""
4444
Creates an MistralTextEmbedder component.

integrations/mistral/src/haystack_integrations/components/generators/mistral/chat/chat_generator.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5-
from typing import Any, Optional
5+
from typing import Any
66

77
from haystack import component, default_to_dict, logging
88
from haystack.components.generators.chat import OpenAIChatGenerator
@@ -63,14 +63,14 @@ def __init__(
6363
self,
6464
api_key: Secret = Secret.from_env_var("MISTRAL_API_KEY"),
6565
model: str = "mistral-small-latest",
66-
streaming_callback: Optional[StreamingCallbackT] = None,
67-
api_base_url: Optional[str] = "https://api.mistral.ai/v1",
68-
generation_kwargs: Optional[dict[str, Any]] = None,
69-
tools: Optional[ToolsType] = None,
66+
streaming_callback: StreamingCallbackT | None = None,
67+
api_base_url: str | None = "https://api.mistral.ai/v1",
68+
generation_kwargs: dict[str, Any] | None = None,
69+
tools: ToolsType | None = None,
7070
*,
71-
timeout: Optional[float] = None,
72-
max_retries: Optional[int] = None,
73-
http_client_kwargs: Optional[dict[str, Any]] = None,
71+
timeout: float | None = None,
72+
max_retries: int | None = None,
73+
http_client_kwargs: dict[str, Any] | None = None,
7474
):
7575
"""
7676
Creates an instance of MistralChatGenerator. Unless specified otherwise in the `model`, this is for Mistral's
@@ -137,10 +137,10 @@ def _prepare_api_call(
137137
self,
138138
*,
139139
messages: list[ChatMessage],
140-
streaming_callback: Optional[StreamingCallbackT] = None,
141-
generation_kwargs: Optional[dict[str, Any]] = None,
142-
tools: Optional[ToolsType] = None,
143-
tools_strict: Optional[bool] = None,
140+
streaming_callback: StreamingCallbackT | None = None,
141+
generation_kwargs: dict[str, Any] | None = None,
142+
tools: ToolsType | None = None,
143+
tools_strict: bool | None = None,
144144
) -> dict[str, Any]:
145145
api_args = super(MistralChatGenerator, self)._prepare_api_call( # noqa: UP008
146146
messages=messages,

0 commit comments

Comments
 (0)