|
63 | 63 |
|
64 | 64 | _NEW_LINE = "\n" |
65 | 65 | _EXCLUDED_PART_FIELD = {"inline_data": {"data"}} |
| 66 | +_REDACTED_THINKING_SIGNATURE = "redacted_thinking" |
66 | 67 |
|
67 | 68 | # Mapping of LiteLLM finish_reason strings to FinishReason enum values |
68 | 69 | # Note: tool_calls/function_call map to STOP because: |
@@ -271,7 +272,7 @@ def _content_to_message_param( |
271 | 272 | elif part.thought: |
272 | 273 | if ( |
273 | 274 | part.thought_signature |
274 | | - and part.thought_signature.decode("utf-8") == "redacted_thinking" |
| 275 | + and part.thought_signature.decode("utf-8") == _REDACTED_THINKING_SIGNATURE |
275 | 276 | ): |
276 | 277 | thinking_block = { |
277 | 278 | "type": "redacted_thinking", |
@@ -623,28 +624,28 @@ def _message_to_generate_content_response( |
623 | 624 |
|
624 | 625 | if message.get("thinking_blocks"): |
625 | 626 | for block in message.get("thinking_blocks"): |
| 627 | + block_type = block.get("type") |
| 628 | + signature = None |
| 629 | + thought = None |
626 | 630 | if block.get("type") == "thinking": |
627 | 631 | signature = block.get("signature") |
628 | 632 | thought = block.get("thinking") |
629 | | - part = types.Part( |
630 | | - thought=True, |
631 | | - thought_signature=signature.encode("utf-8") if signature else None, |
632 | | - text=thought, |
633 | | - ) |
634 | | - parts.append(part) |
635 | 633 | elif block.get("type") == "redacted_thinking": |
636 | 634 | # Part doesn't have redacted thinking type |
637 | 635 | # therefore use signature field to show redacted thinking |
638 | | - signature="redacted_thinking" |
| 636 | + signature=_REDACTED_THINKING_SIGNATURE |
639 | 637 | thought = block.get("data") |
640 | | - part = types.Part( |
641 | | - thought=True, |
642 | | - thought_signature=signature.encode("utf-8") if signature else None, |
643 | | - text=thought, |
644 | | - ) |
645 | | - parts.append(part) |
646 | 638 | else: |
647 | | - logging.warning(f'ignoring unsupported thinking block type {type(block)}') |
| 639 | + logging.warning(f'ignoring unsupported thinking block type {block.get("type")}') |
| 640 | + continue |
| 641 | + |
| 642 | + part = types.Part( |
| 643 | + thought=True, |
| 644 | + thought_signature=signature.encode("utf-8") if signature else None, |
| 645 | + text=thought, |
| 646 | + ) |
| 647 | + parts.append(part) |
| 648 | + |
648 | 649 |
|
649 | 650 | if message.get("tool_calls", None): |
650 | 651 | for tool_call in message.get("tool_calls"): |
|
0 commit comments