11import json
2- from typing import Any , ClassVar , Dict , List , Optional , Union
2+ from typing import Any , ClassVar , Optional , Union
33
44import boto3
55import 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