Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No public description #547

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions google/genai/_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,6 @@ def process_schema(
):
"""Updates the schema and each sub-schema inplace to be API-compatible.

- Removes the `title` field from the schema if the client is not vertexai.
- Inlines the $defs.

Example of a schema before and after (with mldev):
Expand Down Expand Up @@ -579,21 +578,22 @@ def process_schema(
'items': {
'properties': {
'continent': {
'type': 'string'
'title': 'Continent',
'type': 'string'
},
'gdp': {
'type': 'integer'}
'title': 'Gdp',
'type': 'integer'
},
}
'required':['continent', 'gdp'],
'title': 'CountryInfo',
'type': 'object'
},
'type': 'array'
}
"""
if not client.vertexai:
schema.pop('title', None)

if schema.get('default') is not None:
raise ValueError(
'Default value is not supported in the response schema for the Gemini'
Expand Down
12 changes: 6 additions & 6 deletions google/genai/caches.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ def _Schema_to_mldev(
if getv(from_object, ['max_length']) is not None:
raise ValueError('max_length parameter is not supported in Gemini API.')

if getv(from_object, ['title']) is not None:
raise ValueError('title parameter is not supported in Gemini API.')

if getv(from_object, ['min_length']) is not None:
raise ValueError('min_length parameter is not supported in Gemini API.')

Expand Down Expand Up @@ -235,6 +232,9 @@ def _Schema_to_mldev(
if getv(from_object, ['required']) is not None:
setv(to_object, ['required'], getv(from_object, ['required']))

if getv(from_object, ['title']) is not None:
setv(to_object, ['title'], getv(from_object, ['title']))

if getv(from_object, ['type']) is not None:
setv(to_object, ['type'], getv(from_object, ['type']))

Expand All @@ -259,9 +259,6 @@ def _Schema_to_vertex(
if getv(from_object, ['max_length']) is not None:
setv(to_object, ['maxLength'], getv(from_object, ['max_length']))

if getv(from_object, ['title']) is not None:
setv(to_object, ['title'], getv(from_object, ['title']))

if getv(from_object, ['min_length']) is not None:
setv(to_object, ['minLength'], getv(from_object, ['min_length']))

Expand Down Expand Up @@ -314,6 +311,9 @@ def _Schema_to_vertex(
if getv(from_object, ['required']) is not None:
setv(to_object, ['required'], getv(from_object, ['required']))

if getv(from_object, ['title']) is not None:
setv(to_object, ['title'], getv(from_object, ['title']))

if getv(from_object, ['type']) is not None:
setv(to_object, ['type'], getv(from_object, ['type']))

Expand Down
12 changes: 6 additions & 6 deletions google/genai/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@ def _Schema_to_mldev(
if getv(from_object, ['max_length']) is not None:
raise ValueError('max_length parameter is not supported in Gemini API.')

if getv(from_object, ['title']) is not None:
raise ValueError('title parameter is not supported in Gemini API.')

if getv(from_object, ['min_length']) is not None:
raise ValueError('min_length parameter is not supported in Gemini API.')

Expand Down Expand Up @@ -236,6 +233,9 @@ def _Schema_to_mldev(
if getv(from_object, ['required']) is not None:
setv(to_object, ['required'], getv(from_object, ['required']))

if getv(from_object, ['title']) is not None:
setv(to_object, ['title'], getv(from_object, ['title']))

if getv(from_object, ['type']) is not None:
setv(to_object, ['type'], getv(from_object, ['type']))

Expand All @@ -260,9 +260,6 @@ def _Schema_to_vertex(
if getv(from_object, ['max_length']) is not None:
setv(to_object, ['maxLength'], getv(from_object, ['max_length']))

if getv(from_object, ['title']) is not None:
setv(to_object, ['title'], getv(from_object, ['title']))

if getv(from_object, ['min_length']) is not None:
setv(to_object, ['minLength'], getv(from_object, ['min_length']))

Expand Down Expand Up @@ -315,6 +312,9 @@ def _Schema_to_vertex(
if getv(from_object, ['required']) is not None:
setv(to_object, ['required'], getv(from_object, ['required']))

if getv(from_object, ['title']) is not None:
setv(to_object, ['title'], getv(from_object, ['title']))

if getv(from_object, ['type']) is not None:
setv(to_object, ['type'], getv(from_object, ['type']))

Expand Down
27 changes: 3 additions & 24 deletions google/genai/tests/transformers/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,26 +213,8 @@ def test_schema_with_default_value_raises_for_mldev(client):


def test_schema_with_any_of(client):
transformed_schema = _transformers.t_schema(
client, CountryInfoWithAnyOf
)
expected_schema_mldev = types.Schema(
properties={
'name': types.Schema(
type='STRING',
),
'restaurants_per_capita': types.Schema(
any_of=[
types.Schema(type='INTEGER'),
types.Schema(type='NUMBER'),
],
),
},
type='OBJECT',
required=['name', 'restaurants_per_capita'],
property_ordering=['name', 'restaurants_per_capita'],
)
expected_schema_vertex = types.Schema(
transformed_schema = _transformers.t_schema(client, CountryInfoWithAnyOf)
expected_schema = types.Schema(
properties={
'name': types.Schema(
type='STRING',
Expand All @@ -252,10 +234,7 @@ def test_schema_with_any_of(client):
property_ordering=['name', 'restaurants_per_capita'],
)

if client.vertexai:
assert transformed_schema == expected_schema_vertex
else:
assert transformed_schema == expected_schema_mldev
assert transformed_schema == expected_schema


@pytest.mark.parametrize('use_vertex', [True, False])
Expand Down
12 changes: 6 additions & 6 deletions google/genai/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,9 +837,6 @@ class Schema(_common.BaseModel):
default=None,
description="""Optional. Maximum length of the Type.STRING""",
)
title: Optional[str] = Field(
default=None, description="""Optional. The title of the Schema."""
)
min_length: Optional[int] = Field(
default=None,
description="""Optional. SCHEMA FIELDS FOR TYPE STRING Minimum length of the Type.STRING""",
Expand Down Expand Up @@ -903,6 +900,9 @@ class Schema(_common.BaseModel):
default=None,
description="""Optional. Required properties of Type.OBJECT.""",
)
title: Optional[str] = Field(
default=None, description="""Optional. The title of the Schema."""
)
type: Optional[Type] = Field(
default=None, description="""Optional. The type of the data."""
)
Expand All @@ -926,9 +926,6 @@ class SchemaDict(TypedDict, total=False):
max_length: Optional[int]
"""Optional. Maximum length of the Type.STRING"""

title: Optional[str]
"""Optional. The title of the Schema."""

min_length: Optional[int]
"""Optional. SCHEMA FIELDS FOR TYPE STRING Minimum length of the Type.STRING"""

Expand Down Expand Up @@ -977,6 +974,9 @@ class SchemaDict(TypedDict, total=False):
required: Optional[list[str]]
"""Optional. Required properties of Type.OBJECT."""

title: Optional[str]
"""Optional. The title of the Schema."""

type: Optional[Type]
"""Optional. The type of the data."""

Expand Down