Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions google/genai/chats.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ def _validate_content(content: Content) -> bool:
for part in content.parts:
if part == Part():
return False
if part.text is not None and part.text == "":
return False
return True


Expand Down
17 changes: 9 additions & 8 deletions google/genai/tests/chats/test_get_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def mock_api_client(vertexai=False):


@pytest.fixture
def mock_generate_content_invalid_content():
def mock_generate_content_with_empty_text_part():
with mock.patch.object(
models.Models, 'generate_content'
) as mock_generate_content:
Expand Down Expand Up @@ -84,7 +84,7 @@ def mock_generate_content_empty_content():


@pytest.fixture
def mock_generate_content_stream_invalid_content():
def mock_generate_content_stream_with_empty_text_part():
with mock.patch.object(
models.Models, 'generate_content_stream'
) as mock_generate_content:
Expand All @@ -95,7 +95,8 @@ def mock_generate_content_stream_invalid_content():
content=types.Content(
role='model',
parts=[types.Part(text='')],
)
),
finish_reason=types.FinishReason.STOP,
)
]
)
Expand Down Expand Up @@ -481,7 +482,7 @@ def test_history_with_invalid_turns():
assert chat.get_history(curated=True) == curated_history


def test_chat_with_invalid_content(mock_generate_content_invalid_content):
def test_chat_with_empty_text_part(mock_generate_content_with_empty_text_part):
models_module = models.Models(mock_api_client)
chats_module = chats.Chats(modules=models_module)
chat = chats_module.create(model='gemini-2.5-flash')
Expand All @@ -496,7 +497,7 @@ def test_chat_with_invalid_content(mock_generate_content_invalid_content):
),
]
assert chat.get_history() == expected_comprehensive_history
assert not chat.get_history(curated=True)
assert chat.get_history(curated=True) == expected_comprehensive_history


def test_chat_with_empty_content(mock_generate_content_empty_content):
Expand All @@ -517,8 +518,8 @@ def test_chat_with_empty_content(mock_generate_content_empty_content):
assert not chat.get_history(curated=True)


def test_chat_stream_with_invalid_content(
mock_generate_content_stream_invalid_content,
def test_chat_stream_with_empty_text_part(
mock_generate_content_stream_with_empty_text_part,
):
models_module = models.Models(mock_api_client)
chats_module = chats.Chats(modules=models_module)
Expand All @@ -536,7 +537,7 @@ def test_chat_stream_with_invalid_content(
),
]
assert chat.get_history() == expected_comprehensive_history
assert not chat.get_history(curated=True)
assert chat.get_history(curated=True) == expected_comprehensive_history


def test_chat_stream_with_empty_content(
Expand Down
2 changes: 1 addition & 1 deletion google/genai/tests/chats/test_validate_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_validate_response_part_with_empty_text():
]
)

assert not _validate_response(response)
assert _validate_response(response)


def test_validate_response_part_with_text():
Expand Down