@@ -164,7 +164,9 @@ def choice_to_event(choice, capture_content):
164164 if choice .message :
165165 message = {
166166 "role" : (
167- choice .message .role if choice .message and choice .message .role else None
167+ choice .message .role
168+ if choice .message and choice .message .role
169+ else None
168170 )
169171 }
170172 tool_calls = extract_tool_calls (choice .message , capture_content )
@@ -249,10 +251,14 @@ def get_llm_request_attributes(
249251 if operation_name == GenAIAttributes .GenAiOperationNameValues .CHAT .value :
250252 attributes .update (
251253 {
252- GenAIAttributes .GEN_AI_REQUEST_TEMPERATURE : kwargs .get ("temperature" ),
254+ GenAIAttributes .GEN_AI_REQUEST_TEMPERATURE : kwargs .get (
255+ "temperature"
256+ ),
253257 GenAIAttributes .GEN_AI_REQUEST_TOP_P : kwargs .get ("p" )
254258 or kwargs .get ("top_p" ),
255- GenAIAttributes .GEN_AI_REQUEST_MAX_TOKENS : kwargs .get ("max_tokens" ),
259+ GenAIAttributes .GEN_AI_REQUEST_MAX_TOKENS : kwargs .get (
260+ "max_tokens"
261+ ),
256262 GenAIAttributes .GEN_AI_REQUEST_PRESENCE_PENALTY : kwargs .get (
257263 "presence_penalty"
258264 ),
@@ -266,12 +272,16 @@ def get_llm_request_attributes(
266272 if (choice_count := kwargs .get ("n" )) is not None :
267273 # Only add non default, meaningful values
268274 if isinstance (choice_count , int ) and choice_count != 1 :
269- attributes [GenAIAttributes .GEN_AI_REQUEST_CHOICE_COUNT ] = choice_count
275+ attributes [GenAIAttributes .GEN_AI_REQUEST_CHOICE_COUNT ] = (
276+ choice_count
277+ )
270278
271279 if (stop_sequences := kwargs .get ("stop" )) is not None :
272280 if isinstance (stop_sequences , str ):
273281 stop_sequences = [stop_sequences ]
274- attributes [GenAIAttributes .GEN_AI_REQUEST_STOP_SEQUENCES ] = stop_sequences
282+ attributes [GenAIAttributes .GEN_AI_REQUEST_STOP_SEQUENCES ] = (
283+ stop_sequences
284+ )
275285
276286 request_response_format_attr_key = (
277287 GenAIAttributes .GEN_AI_OUTPUT_TYPE
@@ -317,7 +327,10 @@ def get_llm_request_attributes(
317327 )
318328
319329 # Add embeddings-specific attributes
320- elif operation_name == GenAIAttributes .GenAiOperationNameValues .EMBEDDINGS .value :
330+ elif (
331+ operation_name
332+ == GenAIAttributes .GenAiOperationNameValues .EMBEDDINGS .value
333+ ):
321334 # Add embedding dimensions if specified
322335 if (dimensions := kwargs .get ("dimensions" )) is not None :
323336 # TODO: move to GEN_AI_EMBEDDINGS_DIMENSION_COUNT when 1.39.0 is baseline
@@ -372,7 +385,9 @@ def create_chat_invocation(
372385 GenAIAttributes .GEN_AI_REQUEST_CHOICE_COUNT
373386 ] = choice_count
374387
375- if (response_format := get_value (kwargs .get ("response_format" ))) is not None :
388+ if (
389+ response_format := get_value (kwargs .get ("response_format" ))
390+ ) is not None :
376391 # response_format may be string, object with a string in the `type` key,
377392 # or a type (e.g. Pydantic model class used with parse())
378393 if isinstance (response_format , type ):
@@ -420,13 +435,16 @@ def get_value(v: Any):
420435def handle_span_exception (span , error : BaseException ):
421436 span .set_status (Status (StatusCode .ERROR , str (error )))
422437 if span .is_recording ():
423- span .set_attribute (ErrorAttributes .ERROR_TYPE , type (error ).__qualname__ )
438+ span .set_attribute (
439+ ErrorAttributes .ERROR_TYPE , type (error ).__qualname__
440+ )
424441 span .end ()
425442
426443
427444def _is_text_part (content : Any ) -> bool :
428445 return isinstance (content , str ) or (
429- isinstance (content , Iterable ) and all (isinstance (part , str ) for part in content )
446+ isinstance (content , Iterable )
447+ and all (isinstance (part , str ) for part in content )
430448 )
431449
432450
@@ -477,7 +495,9 @@ def extract_tool_calls_new(tool_calls) -> list[ToolCallRequest]:
477495 arguments = arguments_str
478496
479497 # TODO: support custom
480- parts .append (ToolCallRequest (id = call_id , name = func_name , arguments = arguments ))
498+ parts .append (
499+ ToolCallRequest (id = call_id , name = func_name , arguments = arguments )
500+ )
481501 return parts
482502
483503
0 commit comments