@@ -467,7 +467,7 @@ def _parse_completion_response(response_body: dict[str, Any], model: str) -> lis
467467 # Process all content blocks and combine them into a single message
468468 text_content = []
469469 tool_calls = []
470- reasoning_contents = []
470+ reasoning_content = None
471471 for content_block in content_blocks :
472472 if "text" in content_block :
473473 text_content .append (content_block ["text" ])
@@ -482,12 +482,6 @@ def _parse_completion_response(response_body: dict[str, Any], model: str) -> lis
482482 tool_calls .append (tool_call )
483483 elif "reasoningContent" in content_block :
484484 reasoning_content = content_block ["reasoningContent" ]
485- # If reasoningText is present, replace it with reasoning_text
486- if "reasoningText" in reasoning_content :
487- reasoning_content ["reasoning_text" ] = reasoning_content .pop ("reasoningText" )
488- if "redactedContent" in reasoning_content :
489- reasoning_content ["redacted_content" ] = reasoning_content .pop ("redactedContent" )
490- reasoning_contents .append ({"reasoning_content" : reasoning_content })
491485 elif "citationsContent" in content_block :
492486 citations_content = content_block ["citationsContent" ]
493487 meta ["citations" ] = citations_content
@@ -497,12 +491,16 @@ def _parse_completion_response(response_body: dict[str, Any], model: str) -> lis
497491 if text .strip ():
498492 text_content .append (text )
499493
494+ reasoning_extra = {}
500495 reasoning_text = ""
501- for content in reasoning_contents :
502- if "reasoning_text" in content ["reasoning_content" ]:
503- reasoning_text += content ["reasoning_content" ]["reasoning_text" ]["text" ]
504- elif "redacted_content" in content ["reasoning_content" ]:
505- reasoning_text += "[REDACTED]"
496+ if reasoning_content :
497+ if "redacted_content" in reasoning_content :
498+ reasoning_text = "[REDACTED]"
499+ elif "reasoningText" in reasoning_content :
500+ reasoning_text = reasoning_content ["reasoningText" ].get ("text" , "" )
501+ signature = reasoning_content ["reasoningText" ].get ("signature" )
502+ if signature :
503+ reasoning_extra ["signature" ] = signature
506504
507505 # Create a single ChatMessage with combined text and tool calls
508506 replies .append (
@@ -511,9 +509,9 @@ def _parse_completion_response(response_body: dict[str, Any], model: str) -> lis
511509 tool_calls = tool_calls ,
512510 meta = meta ,
513511 reasoning = ReasoningContent (
514- reasoning_text = reasoning_text , extra = { "reasoning_contents" : reasoning_contents }
512+ reasoning_text = reasoning_text , extra = reasoning_extra
515513 )
516- if reasoning_contents
514+ if reasoning_text or reasoning_extra
517515 else None ,
518516 )
519517 )
0 commit comments