@@ -443,14 +443,14 @@ def _translate_openai_content_to_anthropic(
443
443
AnthropicResponseContentBlockThinking (
444
444
type = "thinking" ,
445
445
thinking = thinking_block .get ("thinking" ) or "" ,
446
- signature = thinking_block .get ("signature" ) or "" ,
446
+ signature = thinking_block .get ("signature" ),
447
447
)
448
448
)
449
449
elif "data" in thinking_block :
450
450
new_content .append (
451
451
AnthropicResponseContentBlockRedactedThinking (
452
452
type = "redacted_thinking" ,
453
- data = thinking_block .get ("data" , "" ) ,
453
+ data = thinking_block .get ("data" ) or "" ,
454
454
)
455
455
)
456
456
@@ -525,16 +525,19 @@ def _translate_streaming_openai_chunk_to_anthropic_content_block(
525
525
):
526
526
thinking_blocks = choice .delta .thinking_blocks or []
527
527
if len (thinking_blocks ) > 0 :
528
- thinking = thinking_blocks [0 ].get ("thinking" ) or ""
529
- signature = thinking_blocks [0 ].get ("signature" ) or ""
530
-
531
- if thinking and signature :
532
- raise ValueError ("Both `thinking` and `signature` in a single streaming chunk isn't supported." )
533
- return "thinking" , ChatCompletionThinkingBlock (
534
- type = "thinking" ,
535
- thinking = thinking ,
536
- signature = signature
537
- )
528
+ thinking_block = thinking_blocks [0 ]
529
+ if thinking_block ["type" ] == "thinking" :
530
+ thinking = thinking_block ["thinking" ] or ""
531
+ signature = thinking_block ["signature" ] or ""
532
+
533
+ if thinking and signature :
534
+ raise ValueError ("Both `thinking` and `signature` in a single streaming chunk isn't supported." )
535
+
536
+ return "thinking" , ChatCompletionThinkingBlock (
537
+ type = "thinking" ,
538
+ thinking = thinking ,
539
+ signature = signature
540
+ )
538
541
539
542
540
543
return "text" , TextBlock (type = "text" , text = "" )
@@ -564,8 +567,10 @@ def _translate_streaming_openai_chunk_to_anthropic(
564
567
elif isinstance (choice , StreamingChoices ) and hasattr (choice .delta , "thinking_blocks" ):
565
568
thinking_blocks = choice .delta .thinking_blocks or []
566
569
if len (thinking_blocks ) > 0 :
567
- reasoning_content += thinking_blocks [0 ].get ("thinking" ) or ""
568
- reasoning_signature += thinking_blocks [0 ].get ("signature" ) or ""
570
+ for thinking_block in thinking_blocks :
571
+ if thinking_block ["type" ] == "thinking" :
572
+ reasoning_content += thinking_block ["thinking" ] or ""
573
+ reasoning_signature += thinking_block ["signature" ] or ""
569
574
570
575
if reasoning_content and reasoning_signature :
571
576
raise ValueError ("Both `reasoning` and `signature` in a single streaming chunk isn't supported." )
0 commit comments