Skip to content

Commit 0e94323

Browse files
committed
implement gemini code review suggestions
1 parent 56178ea commit 0e94323

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/google/adk/models/lite_llm.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363

6464
_NEW_LINE = "\n"
6565
_EXCLUDED_PART_FIELD = {"inline_data": {"data"}}
66+
_REDACTED_THINKING_SIGNATURE = "redacted_thinking"
6667

6768
# Mapping of LiteLLM finish_reason strings to FinishReason enum values
6869
# Note: tool_calls/function_call map to STOP because:
@@ -271,7 +272,7 @@ def _content_to_message_param(
271272
elif part.thought:
272273
if (
273274
part.thought_signature
274-
and part.thought_signature.decode("utf-8") == "redacted_thinking"
275+
and part.thought_signature.decode("utf-8") == _REDACTED_THINKING_SIGNATURE
275276
):
276277
thinking_block = {
277278
"type": "redacted_thinking",
@@ -623,28 +624,28 @@ def _message_to_generate_content_response(
623624

624625
if message.get("thinking_blocks"):
625626
for block in message.get("thinking_blocks"):
627+
block_type = block.get("type")
628+
signature = None
629+
thought = None
626630
if block.get("type") == "thinking":
627631
signature = block.get("signature")
628632
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)
635633
elif block.get("type") == "redacted_thinking":
636634
# Part doesn't have redacted thinking type
637635
# therefore use signature field to show redacted thinking
638-
signature="redacted_thinking"
636+
signature=_REDACTED_THINKING_SIGNATURE
639637
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)
646638
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+
648649

649650
if message.get("tool_calls", None):
650651
for tool_call in message.get("tool_calls"):

0 commit comments

Comments
 (0)