@@ -221,15 +221,15 @@ def _add_request_options_to_span(
221221 span .set_attribute (key , value )
222222
223223
224- def _get_gen_ai_request_attributes (config : Union [GenerateContentConfigOrDict , None ]) -> dict [str , Any ]:
224+ def _get_gen_ai_request_attributes (
225+ config : Union [GenerateContentConfigOrDict , None ],
226+ ) -> dict [str , Any ]:
225227 if not config :
226228 return {}
227229 attributes : dict [str , Any ] = {}
228230 config = _coerce_config_to_object (config )
229231 if config .seed :
230- attributes [gen_ai_attributes .GEN_AI_REQUEST_SEED ] = (
231- config .seed
232- )
232+ attributes [gen_ai_attributes .GEN_AI_REQUEST_SEED ] = config .seed
233233 if config .candidate_count :
234234 attributes [gen_ai_attributes .GEN_AI_REQUEST_CHOICE_COUNT ] = (
235235 config .candidate_count
@@ -400,7 +400,9 @@ def process_completion(
400400 config : Optional [GenerateContentConfigOrDict ] = None ,
401401 ):
402402 self ._update_response (response )
403- self ._maybe_log_completion_details (request , response .candidates or [], config )
403+ self ._maybe_log_completion_details (
404+ request , response .candidates or [], config
405+ )
404406
405407 def process_error (self , e : Exception ):
406408 self ._error_type = str (e .__class__ .__name__ )
@@ -499,9 +501,7 @@ def _maybe_log_completion_details(
499501 input_messages = to_input_messages (
500502 contents = transformers .t_contents (request )
501503 )
502- output_messages = to_output_messages (
503- candidates = candidates
504- )
504+ output_messages = to_output_messages (candidates = candidates )
505505
506506 span = trace .get_current_span ()
507507 event = Event (
@@ -515,12 +515,10 @@ def _maybe_log_completion_details(
515515 span = span ,
516516 log_record = event ,
517517 )
518- completion_details_attributes = (
519- _create_completion_details_attributes (
520- input_messages ,
521- output_messages ,
522- system_instructions ,
523- )
518+ completion_details_attributes = _create_completion_details_attributes (
519+ input_messages ,
520+ output_messages ,
521+ system_instructions ,
524522 )
525523 if self ._content_recording_enabled in [
526524 ContentCapturingMode .EVENT_ONLY ,
@@ -536,7 +534,12 @@ def _maybe_log_completion_details(
536534 ContentCapturingMode .SPAN_ONLY ,
537535 ContentCapturingMode .SPAN_AND_EVENT ,
538536 ]:
539- span .set_attributes ({k : gen_ai_json_dumps (v ) for k , v in completion_details_attributes .items ()})
537+ span .set_attributes (
538+ {
539+ k : gen_ai_json_dumps (v )
540+ for k , v in completion_details_attributes .items ()
541+ }
542+ )
540543 span .set_attributes (attributes )
541544
542545 def _maybe_log_system_instruction (
@@ -844,7 +847,9 @@ def instrumented_generate_content_stream(
844847 helper .process_error (error )
845848 raise
846849 finally :
847- helper ._maybe_log_completion_details (contents , candidates , config )
850+ helper ._maybe_log_completion_details (
851+ contents , candidates , config
852+ )
848853 helper .finalize_processing ()
849854
850855 return instrumented_generate_content_stream
@@ -982,7 +987,9 @@ async def _response_async_generator_wrapper():
982987 helper .process_error (error )
983988 raise
984989 finally :
985- helper ._maybe_log_completion_details (contents , candidates , config )
990+ helper ._maybe_log_completion_details (
991+ contents , candidates , config
992+ )
986993 helper .finalize_processing ()
987994
988995 return _response_async_generator_wrapper ()
0 commit comments