Skip to content

Commit 935d86f

Browse files
authored
remove duplicate entries in contents list (#6)
1 parent 39e8a10 commit 935d86f

File tree

2 files changed

+8
-20
lines changed

2 files changed

+8
-20
lines changed

pydantic_ai_slim/pydantic_ai/models/google.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,6 @@ async def _map_messages(self, messages: list[ModelMessage]) -> tuple[ContentDict
415415
message_parts = [{'text': ''}]
416416
contents.append({'role': 'user', 'parts': message_parts})
417417
elif isinstance(m, ModelResponse):
418-
contents.append(_content_model_response(m))
419418
model_content = _content_model_response(m)
420419
# Skip model responses with empty parts (e.g., thinking-only responses)
421420
if model_content.get('parts'):

tests/models/test_google.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,25 +1416,14 @@ async def test_google_model_function_call_without_text(google_provider: GooglePr
14161416
messages = [model_response]
14171417
_, contents = await model._map_messages(list(messages)) # pyright: ignore[reportPrivateUsage]
14181418

1419-
# Due to the bug in the implementation, there are two content items:
1420-
# 1. The original (without added text)
1421-
# 2. The modified one (with added text)
1422-
assert len(contents) == 2
1423-
1424-
# The first content should be the unmodified original
1425-
original_content = contents[0]
1426-
assert isinstance(original_content, dict)
1427-
assert original_content.get('role') == 'model'
1428-
parts = original_content.get('parts', [])
1429-
assert isinstance(parts, list)
1430-
assert len(parts) == 1
1431-
assert 'function_call' in parts[0]
1432-
1433-
# The second content should have the added text
1434-
modified_content = contents[1]
1435-
assert isinstance(modified_content, dict)
1436-
assert modified_content.get('role') == 'model'
1437-
parts = modified_content.get('parts', [])
1419+
# Should have exactly one content item with the function call and added text
1420+
assert len(contents) == 1
1421+
1422+
# The content should have the added text along with the function call
1423+
content = contents[0]
1424+
assert isinstance(content, dict)
1425+
assert content.get('role') == 'model'
1426+
parts = content.get('parts', [])
14381427
assert isinstance(parts, list)
14391428
assert len(parts) == 2
14401429

0 commit comments

Comments
 (0)