@@ -74,21 +74,16 @@ def traced_method(
7474 if hasattr (result , "data" ) and len (result .data ) > 0
7575 else None
7676 )
77- if data is not None :
78- response = [
79- {
80- "role" : "assistant" ,
81- "content" : {
82- "url" : data .url if hasattr (data , "url" ) else "" ,
83- "revised_prompt" : (
84- data .revised_prompt
85- if hasattr (data , "revised_prompt" )
86- else ""
87- ),
88- },
89- }
90- ]
91- set_event_completion (span , response )
77+ response = [
78+ {
79+ "role" : "assistant" ,
80+ "content" : {
81+ "url" : getattr (data , "url" , "" ),
82+ "revised_prompt" : getattr (data , "revised_prompt" , "" ),
83+ },
84+ }
85+ ]
86+ set_event_completion (span , response )
9287
9388 span .set_status (StatusCode .OK )
9489 return result
@@ -140,21 +135,16 @@ async def traced_method(
140135 if hasattr (result , "data" ) and len (result .data ) > 0
141136 else None
142137 )
143- if data is not None :
144- response = [
145- {
146- "role" : "assistant" ,
147- "content" : {
148- "url" : data .url if hasattr (data , "url" ) else "" ,
149- "revised_prompt" : (
150- data .revised_prompt
151- if hasattr (data , "revised_prompt" )
152- else ""
153- ),
154- },
155- }
156- ]
157- set_event_completion (span , response )
138+ response = [
139+ {
140+ "role" : "assistant" ,
141+ "content" : {
142+ "url" : getattr (data , "url" , "" ),
143+ "revised_prompt" : getattr (data , "revised_prompt" , "" ),
144+ },
145+ }
146+ ]
147+ set_event_completion (span , response )
158148
159149 span .set_status (StatusCode .OK )
160150 return result
@@ -257,21 +247,13 @@ def traced_method(
257247 tool_calls = []
258248 for tool_call in tools :
259249 tool_call_dict = {
260- "id" : tool_call . id if hasattr (tool_call , "id" ) else "" ,
261- "type" : tool_call . type if hasattr (tool_call , "type" ) else "" ,
250+ "id" : getattr (tool_call , "id" , "" ) ,
251+ "type" : getattr (tool_call , "type" , "" ) ,
262252 }
263253 if hasattr (tool_call , "function" ):
264254 tool_call_dict ["function" ] = {
265- "name" : (
266- tool_call .function .name
267- if hasattr (tool_call .function , "name" )
268- else ""
269- ),
270- "arguments" : (
271- tool_call .function .arguments
272- if hasattr (tool_call .function , "arguments" )
273- else ""
274- ),
255+ "name" : getattr (tool_call .function , "name" , "" ),
256+ "arguments" : getattr (tool_call .function , "arguments" , "" ),
275257 }
276258 tool_calls .append (tool_call_dict )
277259 llm_prompts .append (tool_calls )
@@ -353,21 +335,13 @@ async def traced_method(
353335 tool_calls = []
354336 for tool_call in tools :
355337 tool_call_dict = {
356- "id" : tool_call . id if hasattr (tool_call , "id" ) else "" ,
357- "type" : tool_call . type if hasattr (tool_call , "type" ) else "" ,
338+ "id" : getattr (tool_call , "id" , "" ) ,
339+ "type" : getattr (tool_call , "type" , "" ) ,
358340 }
359341 if hasattr (tool_call , "function" ):
360342 tool_call_dict ["function" ] = {
361- "name" : (
362- tool_call .function .name
363- if hasattr (tool_call .function , "name" )
364- else ""
365- ),
366- "arguments" : (
367- tool_call .function .arguments
368- if hasattr (tool_call .function , "arguments" )
369- else ""
370- ),
343+ "name" : getattr (tool_call .function , "name" , "" ),
344+ "arguments" : getattr (tool_call .function , "arguments" , "" ),
371345 }
372346 tool_calls .append (json .dumps (tool_call_dict ))
373347 llm_prompts .append (tool_calls )
0 commit comments