first vommit

This commit is contained in:
Till-Immer committed 2026-07-04 14:31:50 +02:00
commit a04e68bc95
4926 files changed
+764440

No files matched your search

@@ -0,0 +1,16 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
GEMINI_MODEL = 'gemini-3.1-pro-preview' # Gemini only
@@ -0,0 +1,14 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
@@ -0,0 +1,60 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests batches.create(), batches.delete()."""
from .... import types as genai_types
from ... import pytest_helper
from ... import shared
def create_delete(client, parameters):
batch_job = client.batches.create(
model=parameters.model,
src=parameters.src,
config=parameters.config,
)
# if pending then don't delete to avoid error
batch_job = client.batches.get(name=batch_job.name)
if batch_job.state != genai_types.JobState.JOB_STATE_PENDING:
client.batches.delete(name=batch_job.name)
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name="test_create_delete_mldev",
parameters=genai_types._CreateBatchJobParameters(
model=shared.GEMINI_MODEL,
src=[{
"contents": [{
"parts": [{"text": "Why is the sky blue?"}],
"role": "user",
}]
}],
),
exception_if_vertex=(
"not supported in Gemini Enterprise Agent Platform."
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method="create_delete",
test_table=test_table,
)
pytest_plugins = ("pytest_asyncio",)
@@ -0,0 +1,57 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests batches.create(), batches.get(), batches.cancel()."""
from .... import types as genai_types
from ... import pytest_helper
from ... import shared
def create_get_cancel(client, parameters):
batch_job = client.batches.create(
model=parameters.model,
src=parameters.src,
config=parameters.config,
)
batch_job = client.batches.get(name=batch_job.name)
client.batches.cancel(name=batch_job.name)
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name="test_create_get_cancel_mldev",
parameters=genai_types._CreateBatchJobParameters(
model=shared.GEMINI_MODEL,
src=[{
"contents": [{
"parts": [{"text": "Why is the sky blue?"}],
"role": "user",
}]
}],
),
exception_if_vertex="Exactly one of ",
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method="create_get_cancel",
test_table=test_table,
)
pytest_plugins = ("pytest_asyncio",)
@@ -0,0 +1,40 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests for batches.list()."""
from .... import types as genai_types
from ... import pytest_helper
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name='test_list_batch_jobs',
parameters=genai_types._ListBatchJobsParameters(
config=genai_types.ListBatchJobsConfig(
page_size=2,
),
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='batches.list',
test_table=test_table,
)
pytest_plugins = ('pytest_asyncio',)
@@ -0,0 +1,14 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
@@ -0,0 +1,68 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests for caches.create(), caches.get(), and caches.delete()."""
from .... import types as genai_types
from ... import pytest_helper
from ... import shared
def create_get_delete(client, parameters):
if client.vertexai:
cache = client.caches.create(
model=parameters.model,
config=parameters.config,
)
else:
# For MLDev, we must create the file before creating the cache.
file = client.files.upload(file="tests/data/a-man-and-a-dog.png")
config = genai_types.CreateCachedContentConfig(
contents=[
genai_types.Part.from_uri(
file_uri=file.uri,
mime_type=file.mime_type,
)
]
* 5
)
cache = client.caches.create(model=parameters.model, config=config)
got_cache = client.caches.get(name=cache.name)
client.caches.delete(name=got_cache.name)
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name="test_create_get_delete",
parameters=genai_types._CreateCachedContentParameters(
model=shared.GEMINI_MODEL,
config=genai_types.CreateCachedContentConfig(
contents=[genai_types.Part.from_uri(
file_uri="gs://cloud-samples-data/generative-ai/image/a-man-and-a-dog.png",
mime_type="image/png",
)] * 5
),
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method="create_get_delete",
test_table=test_table,
)
pytest_plugins = ("pytest_asyncio",)
@@ -0,0 +1,72 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests for caches.create(), caches.update(), and caches.get()."""
from .... import types as genai_types
from ... import pytest_helper
from ... import shared
def create_update_get(client, parameters):
if client.vertexai:
cache = client.caches.create(
model=parameters.model,
config=parameters.config,
)
else:
# For MLDev, we must create the file before creating the cache.
file = client.files.upload(file="tests/data/a-man-and-a-dog.png")
config = genai_types.CreateCachedContentConfig(
contents=[
genai_types.Part.from_uri(
file_uri=file.uri,
mime_type=file.mime_type,
)
]
* 5
)
cache = client.caches.create(model=parameters.model, config=config)
updated_cache = client.caches.update(
name=cache.name,
config=genai_types.UpdateCachedContentConfig(ttl="7200s"),
)
_ = client.caches.get(name=updated_cache.name)
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name="test_create_update_get",
parameters=genai_types._CreateCachedContentParameters(
model=shared.GEMINI_MODEL,
config=genai_types.CreateCachedContentConfig(
contents=[genai_types.Part.from_uri(
file_uri="gs://cloud-samples-data/generative-ai/image/a-man-and-a-dog.png",
mime_type="image/png",
)] * 5
),
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method="create_update_get",
test_table=test_table,
)
pytest_plugins = ("pytest_asyncio",)
@@ -0,0 +1,40 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests for caches.list()."""
from .... import types as genai_types
from ... import pytest_helper
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name='test_list_cached_contents',
parameters=genai_types._ListCachedContentsParameters(
config=genai_types.ListCachedContentsConfig(
page_size=2,
),
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='caches.list',
test_table=test_table,
)
pytest_plugins = ('pytest_asyncio',)
@@ -0,0 +1,14 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
@@ -0,0 +1,50 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Table tests for chats.send_message()."""
import pydantic
from ... import pytest_helper
from ... import shared
class _SendMessageParameters(pydantic.BaseModel):
model: str
message: str
def send_message(client, parameters):
chat = client.chats.create(model=parameters.model)
chat.send_message(parameters.message)
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name="test_send_message",
parameters=_SendMessageParameters(
model=shared.GEMINI_MODEL,
message="Hello",
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method="send_message",
test_table=test_table,
)
pytest_plugins = ("pytest_asyncio",)
@@ -0,0 +1,52 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Table tests for chats.send_message_stream()."""
import pydantic
from ... import pytest_helper
from ... import shared
class _SendMessageStreamParameters(pydantic.BaseModel):
model: str
message: str
def send_message_stream(client, parameters):
chat = client.chats.create(model=parameters.model)
response = chat.send_message_stream(parameters.message)
for _ in response:
pass
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name="test_send_message_stream",
parameters=_SendMessageStreamParameters(
model=shared.GEMINI_MODEL,
message="Tell a joke.",
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method="send_message_stream",
test_table=test_table,
)
pytest_plugins = ("pytest_asyncio",)
@@ -0,0 +1,14 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
@@ -0,0 +1,41 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests for files.list()."""
from .... import types as genai_types
from ... import pytest_helper
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name='test_list_files',
parameters=genai_types._ListFilesParameters(
config=genai_types.ListFilesConfig(
page_size=2,
),
),
exception_if_vertex='only supported in Gemini Developer API mode',
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='files.list',
test_table=test_table,
)
pytest_plugins = ('pytest_asyncio',)
@@ -0,0 +1,54 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests for files.upload(), files.get(), and files.delete()."""
from pydantic import BaseModel
from ... import pytest_helper
class _UploadGetDeleteParameters(BaseModel):
file_path: str
def upload_get_delete(client, parameters):
file = None
try:
file = client.files.upload(file=parameters.file_path)
assert file.name
got_file = client.files.get(name=file.name)
assert got_file.name == file.name
finally:
if file and file.name:
client.files.delete(name=file.name)
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name="test_upload_get_delete_image",
parameters=_UploadGetDeleteParameters(
file_path="tests/data/google.png",
),
exception_if_vertex='only supported in the Gemini Developer client',
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method="upload_get_delete",
test_table=test_table,
)
pytest_plugins = ("pytest_asyncio",)
@@ -0,0 +1,14 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
@@ -0,0 +1,44 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests for models.compute_tokens()."""
from .... import types as genai_types
from ... import pytest_helper
from ... import shared
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name='test_compute_tokens',
parameters=genai_types._ComputeTokensParameters(
model=shared.GEMINI_MODEL,
contents='The quick brown fox jumps over the lazy dog.',
),
exception_if_mldev=(
'only supported in Gemini Enterprise Agent Platform'
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='models.compute_tokens',
test_table=test_table,
)
pytest_plugins = ('pytest_asyncio',)
@@ -0,0 +1,41 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests for models.count_tokens()."""
from .... import types as genai_types
from ... import pytest_helper
from ... import shared
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name='test_count_tokens',
parameters=genai_types._CountTokensParameters(
model=shared.GEMINI_MODEL,
contents='The quick brown fox jumps over the lazy dog.',
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='models.count_tokens',
test_table=test_table,
)
pytest_plugins = ('pytest_asyncio',)
@@ -0,0 +1,69 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests for edit_image."""
import os
from .... import types
from ... import pytest_helper
CAPABILITY_MODEL_NAME = 'imagen-3.0-capability-001'
IMAGE_FILE_PATH = os.path.abspath(
os.path.join(os.path.dirname(__file__), '../../data/google.png')
)
MASK_FILE_PATH = os.path.abspath(
os.path.join(os.path.dirname(__file__), '../../data/checkerboard.png')
)
raw_ref_image = types.RawReferenceImage(
reference_id=1,
reference_image=types.Image.from_file(location=IMAGE_FILE_PATH),
)
mask_ref_image = types.MaskReferenceImage(
reference_id=2,
config=types.MaskReferenceConfig(
mask_mode='MASK_MODE_BACKGROUND',
mask_dilation=0.06,
),
)
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name='test_edit_mask_inpaint_insert',
exception_if_mldev=(
'only supported in Gemini Enterprise Agent Platform'
),
parameters=types._EditImageParameters(
model=CAPABILITY_MODEL_NAME,
prompt='Sunlight and clear weather',
reference_images=[raw_ref_image, mask_ref_image],
config=types.EditImageConfig(
edit_mode=types.EditMode.EDIT_MODE_INPAINT_INSERTION,
),
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='models.edit_image',
test_table=test_table,
)
@@ -0,0 +1,53 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests for models.embed()."""
from .... import types as genai_types
from ... import pytest_helper
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name='test_embed',
parameters=genai_types.EmbedContentParameters(
model='gemini-embedding-001',
contents='Hello world!',
config={
'output_dimensionality': 10,
},
),
),
pytest_helper.TestTableItem(
name='test_embed_gemini_embedding_2',
parameters=genai_types.EmbedContentParameters(
model='gemini-embedding-2-preview',
contents='Hello world!',
config={
'output_dimensionality': 10,
},
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='models.embed_content',
test_table=test_table,
)
pytest_plugins = ('pytest_asyncio',)
@@ -0,0 +1,58 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests for models.generate_content()."""
from .... import types as genai_types
from ... import pytest_helper
from ... import shared
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name='test_generate_content',
parameters=genai_types._GenerateContentParameters(
model=shared.GEMINI_MODEL,
contents='The quick brown fox jumps over the lazy dog.',
),
),
pytest_helper.TestTableItem(
name='test_generate_content_with_config_schema',
parameters=genai_types._GenerateContentParameters(
model=shared.GEMINI_MODEL,
contents='Return a summary of the passage.',
config={'response_mime_type': 'application/json', 'response_schema': {'type': 'OBJECT', 'properties': {'summary': {'type': 'STRING'}}}},
),
ignore_keys=['parsed'],
),
pytest_helper.TestTableItem(
name='test_generate_content_with_config_json_schema',
parameters=genai_types._GenerateContentParameters(
model=shared.GEMINI_MODEL,
contents='Return a JSON summary.',
config={'response_mime_type': 'application/json', 'response_json_schema': {'type': 'object', 'properties': {'summary': {'type': 'string'}}}},
),
ignore_keys=['parsed'],
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='models.generate_content',
test_table=test_table,
)
pytest_plugins = ('pytest_asyncio',)
@@ -0,0 +1,55 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests for models.generate_content_stream()."""
import pydantic
from ... import pytest_helper
from ... import shared
class _GenerateContentStreamParameters(pydantic.BaseModel):
model: str
contents: str
def generate_content_stream(client, parameters):
response = client.models.generate_content_stream(
model=parameters.model,
contents=parameters.contents,
)
for _ in response:
pass
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name='test_generate_content_stream',
parameters=_GenerateContentStreamParameters(
model=shared.GEMINI_MODEL,
contents='The quick brown fox jumps over the lazy dog.',
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='generate_content_stream',
test_table=test_table,
)
pytest_plugins = ('pytest_asyncio',)
@@ -0,0 +1,40 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests for generate_images."""
from .... import types
from ... import pytest_helper
IMAGEN_MODEL_LATEST = 'imagen-4.0-generate-001'
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name='test_simple_prompt',
parameters=types._GenerateImagesParameters(
model=IMAGEN_MODEL_LATEST,
prompt='Red skateboard',
config=types.GenerateImagesConfig(
number_of_images=1,
output_mime_type='image/jpeg',
),
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='models.generate_images',
test_table=test_table,
)
@@ -0,0 +1,38 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests for generate_videos."""
import os
from .... import types
from ... import pytest_helper
VEO_MODEL_LATEST = "veo-2.0-generate-001"
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name="test_simple_prompt",
parameters=types._GenerateVideosParameters(
model=VEO_MODEL_LATEST,
prompt="Man with a dog",
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method="models.generate_videos",
test_table=test_table,
)
@@ -0,0 +1,37 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests for models.list."""
from .... import types
from ... import pytest_helper
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name='test_list',
parameters=types._ListModelsParameters(
config=types.ListModelsConfig(page_size=1)
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='models.list',
test_table=test_table,
)
@@ -0,0 +1,56 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests for recontext_image."""
from .... import types
from ... import pytest_helper
VIRTUAL_TRY_ON_IMAGE_MODEL_LATEST = 'virtual-try-on-001'
PERSON_IMAGE = types.Image(
gcs_uri='gs://genai-sdk-tests/inputs/images/man.jpg',
)
PANTS = types.Image(
gcs_uri='gs://genai-sdk-tests/inputs/images/pants.jpg',
)
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name='test_virtual_try_on',
exception_if_mldev=(
'only supported in Gemini Enterprise Agent Platform'
),
parameters=types._RecontextImageParameters(
model=VIRTUAL_TRY_ON_IMAGE_MODEL_LATEST,
source=types.RecontextImageSource(
person_image=PERSON_IMAGE,
product_images=[types.ProductImage(product_image=PANTS)],
),
config=types.RecontextImageConfig(
number_of_images=1,
output_mime_type='image/jpeg',
),
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='models.recontext_image',
test_table=test_table,
)
@@ -0,0 +1,54 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests for segment_image."""
import os
from .... import types
from ... import pytest_helper
SEGMENT_IMAGE_MODEL_LATEST = 'image-segmentation-001'
SOURCE_IMAGE_FILE_PATH1 = os.path.abspath(
os.path.join(os.path.dirname(__file__), '../../data/google.png')
)
SOURCE_IMAGE1 = types.Image.from_file(location=SOURCE_IMAGE_FILE_PATH1)
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name='test_segment_background',
exception_if_mldev=(
'only supported in Gemini Enterprise Agent Platform'
),
parameters=types._SegmentImageParameters(
model=SEGMENT_IMAGE_MODEL_LATEST,
source=types.SegmentImageSource(
image=SOURCE_IMAGE1,
),
config=types.SegmentImageConfig(
mode=types.SegmentMode.BACKGROUND,
),
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='models.segment_image',
test_table=test_table,
)
@@ -0,0 +1,54 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests for upscale_image."""
import os
from .... import types
from ... import pytest_helper
IMAGEN_MODEL_LATEST = 'imagen-4.0-upscale-preview'
IMAGE_FILE_PATH = os.path.abspath(
os.path.join(os.path.dirname(__file__), '../../data/bridge1.png')
)
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name='test_upscale',
exception_if_mldev=(
'only supported in Gemini Enterprise Agent Platform'
),
parameters=types.UpscaleImageParameters(
model=IMAGEN_MODEL_LATEST,
image=types.Image.from_file(location=IMAGE_FILE_PATH),
upscale_factor='x2',
config=types.UpscaleImageConfig(
include_rai_reason=True,
output_mime_type='image/jpeg',
output_compression_quality=80,
enhance_input_image=True,
image_preservation_factor=0.6,
),
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='models.upscale_image',
test_table=test_table,
)
@@ -0,0 +1,15 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# GEMINI_TUNABLE_MODEL = 'gemini-3.1-flash-lite'
GEMINI_TUNABLE_MODEL = 'gemini-2.5-pro'
@@ -0,0 +1,48 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests for tunings.tune()."""
from .... import types as genai_types
from ... import pytest_helper
from ...shared import tunings
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name='test_tune',
parameters=genai_types.CreateTuningJobParameters(
base_model=tunings.GEMINI_TUNABLE_MODEL,
training_dataset=genai_types.TuningDataset(
gcs_uri='gs://cloud-samples-data/ai-platform/generative_ai/gemini-2_0/text/sft_train_data.jsonl',
),
config=genai_types.CreateTuningJobConfig(
epoch_count=1,
),
),
exception_if_mldev=(
'only supported in Gemini Enterprise Agent Platform mode'
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='tunings.tune',
test_table=test_table,
)
pytest_plugins = ('pytest_asyncio',)
@@ -0,0 +1,59 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests tunings.tune(), tunings.get(), tunings.cancel()."""
from .... import types as genai_types
from ... import pytest_helper
from ...shared import tunings
def create_get_cancel(client, parameters):
tuning_job = client.tunings.tune(
base_model=parameters.base_model,
training_dataset=parameters.training_dataset,
config=parameters.config,
)
tuning_job = client.tunings.get(name=tuning_job.name)
client.tunings.cancel(name=tuning_job.name)
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name="test_create_get_cancel",
parameters=genai_types.CreateTuningJobParameters(
base_model=tunings.GEMINI_TUNABLE_MODEL,
training_dataset=genai_types.TuningDataset(
gcs_uri="gs://cloud-samples-data/ai-platform/generative_ai/gemini-2_0/text/sft_train_data.jsonl",
),
config=genai_types.CreateTuningJobConfig(
epoch_count=1,
),
),
exception_if_mldev=(
"only supported in Gemini Enterprise Agent Platform mode"
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method="create_get_cancel",
test_table=test_table,
)
pytest_plugins = ("pytest_asyncio",)
@@ -0,0 +1,42 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests for tunings.list()."""
from .... import types as genai_types
from ... import pytest_helper
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name='test_default',
parameters=genai_types._ListTuningJobsParameters(
config=genai_types.ListTuningJobsConfig(page_size=1)
),
exception_if_mldev=(
'only supported in Gemini Enterprise Agent Platform'
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='tunings.list',
test_table=test_table,
)
pytest_plugins = ('pytest_asyncio',)