|
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 |
|
68 | 69 | class ChatCompletionFileUrlObject(TypedDict, total=False): |
@@ -256,7 +257,7 @@ def _content_to_message_param( |
256 | 257 | elif part.thought: |
257 | 258 | if ( |
258 | 259 | part.thought_signature |
259 | | - and part.thought_signature.decode("utf-8") == "redacted_thinking" |
| 260 | + and part.thought_signature.decode("utf-8") == _REDACTED_THINKING_SIGNATURE |
260 | 261 | ): |
261 | 262 | thinking_block = { |
262 | 263 | "type": "redacted_thinking", |
@@ -595,28 +596,28 @@ def _message_to_generate_content_response( |
595 | 596 |
|
596 | 597 | if message.get("thinking_blocks"): |
597 | 598 | for block in message.get("thinking_blocks"): |
| 599 | + block_type = block.get("type") |
| 600 | + signature = None |
| 601 | + thought = None |
598 | 602 | if block.get("type") == "thinking": |
599 | 603 | signature = block.get("signature") |
600 | 604 | thought = block.get("thinking") |
601 | | - part = types.Part( |
602 | | - thought=True, |
603 | | - thought_signature=signature.encode("utf-8") if signature else None, |
604 | | - text=thought, |
605 | | - ) |
606 | | - parts.append(part) |
607 | 605 | elif block.get("type") == "redacted_thinking": |
608 | 606 | # Part doesn't have redacted thinking type |
609 | 607 | # therefore use signature field to show redacted thinking |
610 | | - signature="redacted_thinking" |
| 608 | + signature=_REDACTED_THINKING_SIGNATURE |
611 | 609 | thought = block.get("data") |
612 | | - part = types.Part( |
613 | | - thought=True, |
614 | | - thought_signature=signature.encode("utf-8") if signature else None, |
615 | | - text=thought, |
616 | | - ) |
617 | | - parts.append(part) |
618 | 610 | else: |
619 | | - logging.warning(f'ignoring unsupported thinking block type {type(block)}') |
| 611 | + logging.warning(f'ignoring unsupported thinking block type {block.get("type")}') |
| 612 | + continue |
| 613 | + |
| 614 | + part = types.Part( |
| 615 | + thought=True, |
| 616 | + thought_signature=signature.encode("utf-8") if signature else None, |
| 617 | + text=thought, |
| 618 | + ) |
| 619 | + parts.append(part) |
| 620 | + |
620 | 621 |
|
621 | 622 | if message.get("tool_calls", None): |
622 | 623 | for tool_call in message.get("tool_calls"): |
|
0 commit comments