@@ -164,9 +164,7 @@ def choice_to_event(choice, capture_content):
164164 if choice .message :
165165 message = {
166166 "role" : (
167- choice .message .role
168- if choice .message and choice .message .role
169- else None
167+ choice .message .role if choice .message and choice .message .role else None
170168 )
171169 }
172170 tool_calls = extract_tool_calls (choice .message , capture_content )
@@ -251,14 +249,10 @@ def get_llm_request_attributes(
251249 if operation_name == GenAIAttributes .GenAiOperationNameValues .CHAT .value :
252250 attributes .update (
253251 {
254- GenAIAttributes .GEN_AI_REQUEST_TEMPERATURE : kwargs .get (
255- "temperature"
256- ),
252+ GenAIAttributes .GEN_AI_REQUEST_TEMPERATURE : kwargs .get ("temperature" ),
257253 GenAIAttributes .GEN_AI_REQUEST_TOP_P : kwargs .get ("p" )
258254 or kwargs .get ("top_p" ),
259- GenAIAttributes .GEN_AI_REQUEST_MAX_TOKENS : kwargs .get (
260- "max_tokens"
261- ),
255+ GenAIAttributes .GEN_AI_REQUEST_MAX_TOKENS : kwargs .get ("max_tokens" ),
262256 GenAIAttributes .GEN_AI_REQUEST_PRESENCE_PENALTY : kwargs .get (
263257 "presence_penalty"
264258 ),
@@ -272,16 +266,12 @@ def get_llm_request_attributes(
272266 if (choice_count := kwargs .get ("n" )) is not None :
273267 # Only add non default, meaningful values
274268 if isinstance (choice_count , int ) and choice_count != 1 :
275- attributes [GenAIAttributes .GEN_AI_REQUEST_CHOICE_COUNT ] = (
276- choice_count
277- )
269+ attributes [GenAIAttributes .GEN_AI_REQUEST_CHOICE_COUNT ] = choice_count
278270
279271 if (stop_sequences := kwargs .get ("stop" )) is not None :
280272 if isinstance (stop_sequences , str ):
281273 stop_sequences = [stop_sequences ]
282- attributes [GenAIAttributes .GEN_AI_REQUEST_STOP_SEQUENCES ] = (
283- stop_sequences
284- )
274+ attributes [GenAIAttributes .GEN_AI_REQUEST_STOP_SEQUENCES ] = stop_sequences
285275
286276 request_response_format_attr_key = (
287277 GenAIAttributes .GEN_AI_OUTPUT_TYPE
@@ -292,7 +282,7 @@ def get_llm_request_attributes(
292282 # response_format may be string, object with a string in the `type` key,
293283 # or a type (e.g. Pydantic model class used with parse())
294284 if isinstance (response_format , type ):
295- attributes [request_response_format_attr_key ] = "json_schema "
285+ attributes [request_response_format_attr_key ] = "json "
296286 elif isinstance (response_format , Mapping ):
297287 if (
298288 response_format_type := response_format .get ("type" )
@@ -320,10 +310,7 @@ def get_llm_request_attributes(
320310 )
321311
322312 # Add embeddings-specific attributes
323- elif (
324- operation_name
325- == GenAIAttributes .GenAiOperationNameValues .EMBEDDINGS .value
326- ):
313+ elif operation_name == GenAIAttributes .GenAiOperationNameValues .EMBEDDINGS .value :
327314 # Add embedding dimensions if specified
328315 if (dimensions := kwargs .get ("dimensions" )) is not None :
329316 # TODO: move to GEN_AI_EMBEDDINGS_DIMENSION_COUNT when 1.39.0 is baseline
@@ -378,13 +365,11 @@ def create_chat_invocation(
378365 GenAIAttributes .GEN_AI_REQUEST_CHOICE_COUNT
379366 ] = choice_count
380367
381- if (
382- response_format := get_value (kwargs .get ("response_format" ))
383- ) is not None :
368+ if (response_format := get_value (kwargs .get ("response_format" ))) is not None :
384369 # response_format may be string, object with a string in the `type` key,
385370 # or a type (e.g. Pydantic model class used with parse())
386371 if isinstance (response_format , type ):
387- attributes [GenAIAttributes .GEN_AI_OUTPUT_TYPE ] = "json_schema "
372+ invocation . attributes [GenAIAttributes .GEN_AI_OUTPUT_TYPE ] = "json "
388373 elif isinstance (response_format , Mapping ):
389374 if (
390375 response_format_type := get_value (response_format .get ("type" ))
@@ -426,16 +411,13 @@ def get_value(v: Any):
426411def handle_span_exception (span , error : BaseException ):
427412 span .set_status (Status (StatusCode .ERROR , str (error )))
428413 if span .is_recording ():
429- span .set_attribute (
430- ErrorAttributes .ERROR_TYPE , type (error ).__qualname__
431- )
414+ span .set_attribute (ErrorAttributes .ERROR_TYPE , type (error ).__qualname__ )
432415 span .end ()
433416
434417
435418def _is_text_part (content : Any ) -> bool :
436419 return isinstance (content , str ) or (
437- isinstance (content , Iterable )
438- and all (isinstance (part , str ) for part in content )
420+ isinstance (content , Iterable ) and all (isinstance (part , str ) for part in content )
439421 )
440422
441423
@@ -486,9 +468,7 @@ def extract_tool_calls_new(tool_calls) -> list[ToolCallRequest]:
486468 arguments = arguments_str
487469
488470 # TODO: support custom
489- parts .append (
490- ToolCallRequest (id = call_id , name = func_name , arguments = arguments )
491- )
471+ parts .append (ToolCallRequest (id = call_id , name = func_name , arguments = arguments ))
492472 return parts
493473
494474
0 commit comments