Skip to content

Commit f045daa

Browse files
committed
fix(gemini): skip empty text parts in thinking blocks extraction
Gemini models were returning a trailing '{"text": ""}' in reasoning_content because _extract_thinking_blocks_from_parts was including parts with empty text content. These empty text parts with thoughtSignature were being JSON-stringified and appended to reasoning_content in the streaming path.
1 parent 977cc8c commit f045daa

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,10 @@ def _extract_thinking_blocks_from_parts(
10871087
thinking_blocks: List[ChatCompletionThinkingBlock] = []
10881088
for part in parts:
10891089
if "thoughtSignature" in part:
1090+
# Skip parts with empty text content to avoid adding '{"text": ""}' to reasoning_content
1091+
text_content = part.get("text", "")
1092+
if not text_content:
1093+
continue
10901094
part_copy = part.copy()
10911095
part_copy.pop("thoughtSignature")
10921096
thinking_blocks.append(

0 commit comments

Comments
 (0)