Skip to content

Commit c7a5984

Browse files
committed
Fix mypy issues
1 parent 1c3ec18 commit c7a5984

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -443,14 +443,14 @@ def _translate_openai_content_to_anthropic(
443443
AnthropicResponseContentBlockThinking(
444444
type="thinking",
445445
thinking=thinking_block.get("thinking") or "",
446-
signature=thinking_block.get("signature") or "",
446+
signature=thinking_block.get("signature"),
447447
)
448448
)
449449
elif "data" in thinking_block:
450450
new_content.append(
451451
AnthropicResponseContentBlockRedactedThinking(
452452
type="redacted_thinking",
453-
data=thinking_block.get("data", ""),
453+
data=thinking_block.get("data") or "",
454454
)
455455
)
456456

@@ -525,16 +525,19 @@ def _translate_streaming_openai_chunk_to_anthropic_content_block(
525525
):
526526
thinking_blocks = choice.delta.thinking_blocks or []
527527
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 = str(thinking_block.get("thinking") or "")
531+
signature = str(thinking_block.get("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+
)
538541

539542

540543
return "text", TextBlock(type="text", text="")
@@ -564,8 +567,10 @@ def _translate_streaming_openai_chunk_to_anthropic(
564567
elif isinstance(choice, StreamingChoices) and hasattr(choice.delta, "thinking_blocks"):
565568
thinking_blocks = choice.delta.thinking_blocks or []
566569
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 += str(thinking_block.get("thinking") or "")
573+
reasoning_signature += str(thinking_block.get("signature") or "")
569574

570575
if reasoning_content and reasoning_signature:
571576
raise ValueError("Both `reasoning` and `signature` in a single streaming chunk isn't supported.")

0 commit comments

Comments
 (0)