mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
Merge pull request #17403 from BerriAI/litellm_streaming_gemini_3_fix
Fix gemini 3 last chunk thinking block
This commit is contained in:
commit
fcc2855baa
2 changed files with 25 additions and 0 deletions
|
|
@ -1091,6 +1091,11 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig):
|
|||
if "thoughtSignature" in part:
|
||||
part_copy = part.copy()
|
||||
part_copy.pop("thoughtSignature")
|
||||
|
||||
text_content = part_copy.get("text")
|
||||
if isinstance(text_content, str) and text_content.strip() == "":
|
||||
continue
|
||||
|
||||
thinking_blocks.append(
|
||||
ChatCompletionThinkingBlock(
|
||||
type="thinking",
|
||||
|
|
|
|||
20
tests/local_testing/test_gemini_reasoning_content.py
Normal file
20
tests/local_testing/test_gemini_reasoning_content.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import json
|
||||
from litellm.llms.vertex_ai.gemini.vertex_and_google_ai_studio_gemini import VertexGeminiConfig
|
||||
|
||||
|
||||
def test_empty_part_does_not_create_thinking_block():
|
||||
parts = [{"text": "", "thoughtSignature": "sig-1"}]
|
||||
config = VertexGeminiConfig()
|
||||
thinking_blocks = config._extract_thinking_blocks_from_parts(parts)
|
||||
assert thinking_blocks == []
|
||||
|
||||
|
||||
def test_non_empty_part_creates_thinking_block():
|
||||
parts = [{"text": "Some thinking", "thoughtSignature": "sig-2"}]
|
||||
config = VertexGeminiConfig()
|
||||
thinking_blocks = config._extract_thinking_blocks_from_parts(parts)
|
||||
assert len(thinking_blocks) == 1
|
||||
block = thinking_blocks[0]
|
||||
# thinking should be valid JSON containing the text
|
||||
parsed = json.loads(block["thinking"]) if isinstance(block["thinking"], str) else None
|
||||
assert parsed is not None and parsed.get("text") == "Some thinking"
|
||||
Loading…
Add table
Reference in a new issue