@@ -87,7 +87,11 @@ def _extract_messages_v2(messages):
8787 text = content
8888 elif isinstance (content , list ):
8989 text = " " .join (
90- (item .get ("text" , "" ) if isinstance (item , dict ) else getattr (item , "text" , "" ))
90+ (
91+ item .get ("text" , "" )
92+ if isinstance (item , dict )
93+ else getattr (item , "text" , "" )
94+ )
9195 for item in content
9296 if (isinstance (item , dict ) and "text" in item ) or hasattr (item , "text" )
9397 )
@@ -125,9 +129,7 @@ def collect_v2_response_fields(span, res, include_pii):
125129 and res .message .content
126130 ):
127131 texts = [
128- item .text
129- for item in res .message .content
130- if hasattr (item , "text" )
132+ item .text for item in res .message .content if hasattr (item , "text" )
131133 ]
132134 if texts :
133135 set_data_normalized (span , SPANDATA .GEN_AI_RESPONSE_TEXT , texts )
@@ -189,9 +191,7 @@ def new_chat(*args, **kwargs):
189191 messages = _extract_messages_v2 (kwargs .get ("messages" , []))
190192 messages = normalize_message_roles (messages )
191193 scope = sentry_sdk .get_current_scope ()
192- messages_data = truncate_and_annotate_messages (
193- messages , span , scope
194- )
194+ messages_data = truncate_and_annotate_messages (messages , span , scope )
195195 if messages_data is not None :
196196 set_data_normalized (
197197 span ,
@@ -228,9 +228,7 @@ def new_iterator():
228228 msg = getattr (x .delta , "message" , None )
229229 if msg is not None :
230230 content = getattr (msg , "content" , None )
231- if content is not None and hasattr (
232- content , "text"
233- ):
231+ if content is not None and hasattr (content , "text" ):
234232 collected_text .append (content .text )
235233
236234 if isinstance (x , MessageEndV2ChatStreamResponse ):
0 commit comments