Skip to content

Commit c32de5a

Browse files
committed
implement gemini code review suggestions
1 parent 0ccb0a0 commit c32de5a

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

6869
class ChatCompletionFileUrlObject(TypedDict, total=False):
@@ -256,7 +257,7 @@ def _content_to_message_param(
256257
elif part.thought:
257258
if (
258259
part.thought_signature
259-
and part.thought_signature.decode("utf-8") == "redacted_thinking"
260+
and part.thought_signature.decode("utf-8") == _REDACTED_THINKING_SIGNATURE
260261
):
261262
thinking_block = {
262263
"type": "redacted_thinking",
@@ -595,28 +596,28 @@ def _message_to_generate_content_response(
595596

596597
if message.get("thinking_blocks"):
597598
for block in message.get("thinking_blocks"):
599+
block_type = block.get("type")
600+
signature = None
601+
thought = None
598602
if block.get("type") == "thinking":
599603
signature = block.get("signature")
600604
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)
607605
elif block.get("type") == "redacted_thinking":
608606
# Part doesn't have redacted thinking type
609607
# therefore use signature field to show redacted thinking
610-
signature="redacted_thinking"
608+
signature=_REDACTED_THINKING_SIGNATURE
611609
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)
618610
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+
620621

621622
if message.get("tool_calls", None):
622623
for tool_call in message.get("tool_calls"):

0 commit comments

Comments
 (0)