@@ -125,7 +125,7 @@ def unwrap_openai_completion(completion: Any) -> Any:
125125 try :
126126 if completion is None :
127127 return None
128- if isinstance (completion , dict ):
128+ if isinstance (completion , Dict ):
129129 return completion
130130 if getattr (completion , "choices" , None ) is not None :
131131 return completion
@@ -146,15 +146,15 @@ def _shape_args_for_debug(arguments: Any) -> Dict[str, Any]:
146146 return {"args_type" : "None" , "args_str_len" : 0 }
147147 if isinstance (arguments , str ):
148148 return {"args_type" : "str" , "args_str_len" : len (arguments )}
149- if isinstance (arguments , (dict , list )):
149+ if isinstance (arguments , (Dict , list )):
150150 return {"args_type" : type (arguments ).__name__ ,
151151 "args_json_len" : len (json .dumps (arguments , default = str ))}
152152 return {"args_type" : type (arguments ).__name__ ,
153153 "args_repr_len" : len (repr (arguments ))}
154154
155155
156156def _first_tool_call_keys (tc : Any ) -> Any :
157- if isinstance (tc , dict ):
157+ if isinstance (tc , Dict ):
158158 return sorted (tc .keys ())
159159 out = []
160160 for k in ("function" , "name" , "args" , "id" , "type" , "arguments" ):
@@ -180,7 +180,7 @@ def tool_calls_to_parts(tool_calls: Any) -> List[Any]:
180180 parts : List [Any ] = []
181181 for i , tc in enumerate (tool_calls ):
182182 fn = getattr (tc , "function" , None )
183- if fn is None and isinstance (tc , dict ):
183+ if fn is None and isinstance (tc , Dict ):
184184 fn = tc .get ("function" )
185185 name = ""
186186 args : Any = "{}"
@@ -191,7 +191,7 @@ def tool_calls_to_parts(tool_calls: Any) -> List[Any]:
191191 # ``messages`` history). Never use ``getattr(fn, "arguments", "{}")`` for dicts:
192192 # ``getattr`` returns the default literal ``"{}"``, which is truthy and prevents
193193 # the ``or fn.get("arguments", ...)`` fallback from running — real arguments are lost.
194- if isinstance (fn , dict ):
194+ if isinstance (fn , Dict ):
195195 name = fn .get ("name" ) or ""
196196 raw_args = fn .get ("arguments" )
197197 else :
@@ -201,17 +201,17 @@ def tool_calls_to_parts(tool_calls: Any) -> List[Any]:
201201 else :
202202 branch = "top_level_lc"
203203 name = getattr (tc , "name" , "" ) or (
204- tc .get ("name" ) if isinstance (tc , dict ) else "" )
204+ tc .get ("name" ) if isinstance (tc , Dict ) else "" )
205205 # LangChain ``ToolCall`` / LC-like dicts: payload lives in top-level ``args``, not
206206 # OpenAI's nested ``function.arguments`` string.
207- if isinstance (tc , dict ):
207+ if isinstance (tc , Dict ):
208208 if tc .get ("args" ) is not None :
209209 args = tc ["args" ]
210210 else :
211211 lc_args = getattr (tc , "args" , None )
212212 if lc_args is not None :
213213 args = lc_args
214- tid = getattr (tc , "id" , None ) if not isinstance (tc , dict ) else tc .get (
214+ tid = getattr (tc , "id" , None ) if not isinstance (tc , Dict ) else tc .get (
215215 "id" )
216216 args_str = _sanitize_tool_call_arguments (args )
217217 if _debug_llm_tool_calls ():
@@ -220,7 +220,7 @@ def tool_calls_to_parts(tool_calls: Any) -> List[Any]:
220220 if fn is not None :
221221 raw_a = (
222222 fn .get ("arguments" , "__sentinel__" )
223- if isinstance (fn , dict )
223+ if isinstance (fn , Dict )
224224 else getattr (fn , "arguments" , "__sentinel__" )
225225 )
226226 nested_fn_diag = {
@@ -262,7 +262,7 @@ def _extract_tool_calls_from_message_obj(m: Any) -> Any:
262262 if tc is not None :
263263 return tc
264264 ak = getattr (m , "additional_kwargs" , None )
265- if isinstance (ak , dict ):
265+ if isinstance (ak , Dict ):
266266 return ak .get ("tool_calls" )
267267 return None
268268
@@ -307,7 +307,7 @@ def openai_chat_messages_to_input_messages(messages: Any) -> List[Any]:
307307 _debug_llm_tool_calls_log_exc ()
308308 out : List [Any ] = []
309309 for idx , m in enumerate (messages ):
310- if isinstance (m , dict ):
310+ if isinstance (m , Dict ):
311311 raw_role = m .get ("role" )
312312 content = m .get ("content" )
313313 tool_calls = m .get ("tool_calls" )
@@ -392,29 +392,29 @@ def openai_completion_to_output_messages(completion: Any) -> List[Any]:
392392
393393 # OpenAI-compatible SDKs sometimes return plain dicts (e.g. http clients or
394394 # wrappers). Handle both object- and dict-shaped responses.
395- if isinstance (completion , dict ):
395+ if isinstance (completion , Dict ):
396396 choices = completion .get ("choices" ) or []
397397 else :
398398 choices = getattr (completion , "choices" , None ) or []
399399 if not choices :
400400 return []
401401 result : List [Any ] = []
402402 for ch in choices :
403- if isinstance (ch , dict ):
403+ if isinstance (ch , Dict ):
404404 msg = ch .get ("message" )
405405 finish = ch .get ("finish_reason" ) or "stop"
406406 else :
407407 msg = getattr (ch , "message" , None )
408408 finish = getattr (ch , "finish_reason" , None ) or "stop"
409409
410- if isinstance (msg , dict ):
410+ if isinstance (msg , Dict ):
411411 role = msg .get ("role" ) or "assistant"
412412 else :
413413 role = getattr (msg , "role" ,
414414 "assistant" ) if msg is not None else "assistant"
415415 parts : List [Any ] = []
416416 if msg is not None :
417- if isinstance (msg , dict ):
417+ if isinstance (msg , Dict ):
418418 content = msg .get ("content" )
419419 else :
420420 content = getattr (msg , "content" , None )
@@ -423,7 +423,7 @@ def openai_completion_to_output_messages(completion: Any) -> List[Any]:
423423 Text (content = content if isinstance (content , str ) else str (
424424 content ))
425425 )
426- if isinstance (msg , dict ):
426+ if isinstance (msg , Dict ):
427427 tool_calls = msg .get ("tool_calls" )
428428 else :
429429 tool_calls = getattr (msg , "tool_calls" , None )
@@ -452,7 +452,7 @@ def dashscope_response_to_output_messages(response: Any) -> List[Any]:
452452 role = "assistant"
453453 parts : List [Any ] = []
454454 if msg is not None :
455- if isinstance (msg , dict ):
455+ if isinstance (msg , Dict ):
456456 role = msg .get ("role" ) or "assistant"
457457 content = msg .get ("content" )
458458 tool_calls = msg .get ("tool_calls" )
0 commit comments