Skip to content

Commit 01a0d5a

Browse files
authored
Adopt pep585 (#2532)
1 parent d67f038 commit 01a0d5a

4 files changed

Lines changed: 22 additions & 22 deletions

File tree

integrations/aimlapi/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ disallow_incomplete_defs = true
7676

7777

7878
[tool.ruff]
79-
target-version = "py38"
79+
target-version = "py39"
8080
line-length = 120
8181

8282
[tool.ruff.lint]

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

Lines changed: 9 additions & 9 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, Dict, List, Optional
5+
from typing import Any, Optional
66

77
from haystack import component, default_to_dict, logging
88
from haystack.components.generators.chat import OpenAIChatGenerator
@@ -65,12 +65,12 @@ def __init__(
6565
model: str = "openai/gpt-5-chat-latest",
6666
streaming_callback: Optional[StreamingCallbackT] = None,
6767
api_base_url: Optional[str] = "https://api.aimlapi.com/v1",
68-
generation_kwargs: Optional[Dict[str, Any]] = None,
68+
generation_kwargs: Optional[dict[str, Any]] = None,
6969
tools: Optional[ToolsType] = None,
7070
timeout: Optional[float] = None,
71-
extra_headers: Optional[Dict[str, Any]] = None,
71+
extra_headers: Optional[dict[str, Any]] = None,
7272
max_retries: Optional[int] = None,
73-
http_client_kwargs: Optional[Dict[str, Any]] = None,
73+
http_client_kwargs: Optional[dict[str, Any]] = None,
7474
):
7575
"""
7676
Creates an instance of AIMLAPIChatGenerator. Unless specified otherwise,
@@ -128,7 +128,7 @@ def __init__(
128128
)
129129
self.extra_headers = extra_headers
130130

131-
def to_dict(self) -> Dict[str, Any]:
131+
def to_dict(self) -> dict[str, Any]:
132132
"""
133133
Serialize this component to a dictionary.
134134
@@ -154,18 +154,18 @@ def to_dict(self) -> Dict[str, Any]:
154154
def _prepare_api_call(
155155
self,
156156
*,
157-
messages: List[ChatMessage],
157+
messages: list[ChatMessage],
158158
streaming_callback: Optional[StreamingCallbackT] = None,
159-
generation_kwargs: Optional[Dict[str, Any]] = None,
159+
generation_kwargs: Optional[dict[str, Any]] = None,
160160
tools: Optional[ToolsType] = None,
161161
tools_strict: Optional[bool] = None,
162-
) -> Dict[str, Any]:
162+
) -> dict[str, Any]:
163163
# update generation kwargs by merging with the generation kwargs passed to the run method
164164
generation_kwargs = {**self.generation_kwargs, **(generation_kwargs or {})}
165165
extra_headers = {**AIMLAPI_HEADERS, **(self.extra_headers or {})}
166166

167167
# adapt ChatMessage(s) to the format expected by the OpenAI API (AIMLAPI uses the same format)
168-
aimlapi_formatted_messages: List[Dict[str, Any]] = [message.to_openai_dict_format() for message in messages]
168+
aimlapi_formatted_messages: list[dict[str, Any]] = [message.to_openai_dict_format() for message in messages]
169169

170170
tools_strict = tools_strict if tools_strict is not None else self.tools_strict
171171
flattened_tools = flatten_tools_or_toolsets(tools or self.tools)

integrations/amazon_sagemaker/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ module = [
8383
ignore_missing_imports = true
8484

8585
[tool.ruff]
86-
target-version = "py38"
86+
target-version = "py39"
8787
line-length = 120
8888

8989
[tool.ruff.lint]

integrations/amazon_sagemaker/src/haystack_integrations/components/generators/amazon_sagemaker/sagemaker.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from typing import Any, ClassVar, Dict, List, Optional, Union
2+
from typing import Any, ClassVar, Optional, Union
33

44
import boto3
55
import requests
@@ -56,8 +56,8 @@ def __init__(
5656
aws_session_token: Optional[Secret] = Secret.from_env_var(["AWS_SESSION_TOKEN"], strict=False), # noqa: B008
5757
aws_region_name: Optional[Secret] = Secret.from_env_var(["AWS_DEFAULT_REGION"], strict=False), # noqa: B008
5858
aws_profile_name: Optional[Secret] = Secret.from_env_var(["AWS_PROFILE"], strict=False), # noqa: B008
59-
aws_custom_attributes: Optional[Dict[str, Any]] = None,
60-
generation_kwargs: Optional[Dict[str, Any]] = None,
59+
aws_custom_attributes: Optional[dict[str, Any]] = None,
60+
generation_kwargs: Optional[dict[str, Any]] = None,
6161
):
6262
"""
6363
Instantiates the session with SageMaker.
@@ -114,15 +114,15 @@ def resolve_secret(secret: Optional[Secret]) -> Optional[str]:
114114
)
115115
raise AWSConfigurationError(msg) from e
116116

117-
def _get_telemetry_data(self) -> Dict[str, Any]:
117+
def _get_telemetry_data(self) -> dict[str, Any]:
118118
"""
119119
Returns data that is sent to Posthog for usage analytics.
120120
:returns: A dictionary with the following keys:
121121
- `model`: The name of the model.
122122
"""
123123
return {"model": self.model}
124124

125-
def to_dict(self) -> Dict[str, Any]:
125+
def to_dict(self) -> dict[str, Any]:
126126
"""
127127
Serializes the component to a dictionary.
128128
@@ -142,7 +142,7 @@ def to_dict(self) -> Dict[str, Any]:
142142
)
143143

144144
@classmethod
145-
def from_dict(cls, data: Dict[str, Any]) -> "SagemakerGenerator":
145+
def from_dict(cls, data: dict[str, Any]) -> "SagemakerGenerator":
146146
"""
147147
Deserializes the component from a dictionary.
148148
@@ -191,10 +191,10 @@ def _get_aws_session(
191191
msg = f"Failed to initialize the session with provided AWS credentials: {e}."
192192
raise AWSConfigurationError(msg) from e
193193

194-
@component.output_types(replies=List[str], meta=List[Dict[str, Any]])
194+
@component.output_types(replies=list[str], meta=list[dict[str, Any]])
195195
def run(
196-
self, prompt: str, generation_kwargs: Optional[Dict[str, Any]] = None
197-
) -> Dict[str, Union[List[str], List[Dict[str, Any]]]]:
196+
self, prompt: str, generation_kwargs: Optional[dict[str, Any]] = None
197+
) -> dict[str, Union[list[str], list[dict[str, Any]]]]:
198198
"""
199199
Invoke the text generation inference based on the provided prompt and generation parameters.
200200
@@ -222,10 +222,10 @@ def run(
222222
CustomAttributes=custom_attributes,
223223
)
224224
response_json = response.get("Body").read().decode("utf-8")
225-
output: Dict[str, Dict[str, Any]] = json.loads(response_json)
225+
output: dict[str, dict[str, Any]] = json.loads(response_json)
226226

227227
# The output might be either a list of dictionaries or a single dictionary
228-
list_output: List[Dict[str, Any]]
228+
list_output: list[dict[str, Any]]
229229
if output and isinstance(output, dict):
230230
list_output = [output]
231231
elif isinstance(output, list) and all(isinstance(o, dict) for o in output):

0 commit comments

Comments
 (0)