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,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,
)