Skip to content

Commit 886c7a8

Browse files
google-genai-botcopybara-github
authored andcommitted
feat: Deprecate legacy response_format and publish new polymorphic field.
PiperOrigin-RevId: 908361634
1 parent 41d8e5b commit 886c7a8

12 files changed

Lines changed: 382 additions & 16 deletions

google/genai/_interactions/resources/interactions.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def create(
7575
background: bool | Omit = omit,
7676
generation_config: GenerationConfigParam | Omit = omit,
7777
previous_interaction_id: str | Omit = omit,
78-
response_format: object | Omit = omit,
78+
response_format: interaction_create_params.ResponseFormat | Omit = omit,
7979
response_mime_type: str | Omit = omit,
8080
response_modalities: List[Literal["text", "image", "audio", "video", "document"]] | Omit = omit,
8181
service_tier: Literal["flex", "standard", "priority"] | Omit = omit,
@@ -146,7 +146,7 @@ def create(
146146
background: bool | Omit = omit,
147147
generation_config: GenerationConfigParam | Omit = omit,
148148
previous_interaction_id: str | Omit = omit,
149-
response_format: object | Omit = omit,
149+
response_format: interaction_create_params.ResponseFormat | Omit = omit,
150150
response_mime_type: str | Omit = omit,
151151
response_modalities: List[Literal["text", "image", "audio", "video", "document"]] | Omit = omit,
152152
service_tier: Literal["flex", "standard", "priority"] | Omit = omit,
@@ -222,7 +222,7 @@ def create(
222222
agent_config: interaction_create_params.AgentConfig | Omit = omit,
223223
background: bool | Omit = omit,
224224
previous_interaction_id: str | Omit = omit,
225-
response_format: object | Omit = omit,
225+
response_format: interaction_create_params.ResponseFormat | Omit = omit,
226226
response_mime_type: str | Omit = omit,
227227
response_modalities: List[Literal["text", "image", "audio", "video", "document"]] | Omit = omit,
228228
service_tier: Literal["flex", "standard", "priority"] | Omit = omit,
@@ -300,7 +300,7 @@ def create(
300300
agent_config: interaction_create_params.AgentConfig | Omit = omit,
301301
background: bool | Omit = omit,
302302
previous_interaction_id: str | Omit = omit,
303-
response_format: object | Omit = omit,
303+
response_format: interaction_create_params.ResponseFormat | Omit = omit,
304304
response_mime_type: str | Omit = omit,
305305
response_modalities: List[Literal["text", "image", "audio", "video", "document"]] | Omit = omit,
306306
service_tier: Literal["flex", "standard", "priority"] | Omit = omit,
@@ -370,7 +370,7 @@ def create(
370370
background: bool | Omit = omit,
371371
generation_config: GenerationConfigParam | Omit = omit,
372372
previous_interaction_id: str | Omit = omit,
373-
response_format: object | Omit = omit,
373+
response_format: interaction_create_params.ResponseFormat | Omit = omit,
374374
response_mime_type: str | Omit = omit,
375375
response_modalities: List[Literal["text", "image", "audio", "video", "document"]] | Omit = omit,
376376
service_tier: Literal["flex", "standard", "priority"] | Omit = omit,
@@ -439,7 +439,7 @@ def create(
439439
background: bool | Omit = omit,
440440
generation_config: GenerationConfigParam | Omit = omit,
441441
previous_interaction_id: str | Omit = omit,
442-
response_format: object | Omit = omit,
442+
response_format: interaction_create_params.ResponseFormat | Omit = omit,
443443
response_mime_type: str | Omit = omit,
444444
response_modalities: List[Literal["text", "image", "audio", "video", "document"]] | Omit = omit,
445445
service_tier: Literal["flex", "standard", "priority"] | Omit = omit,
@@ -771,7 +771,7 @@ async def create(
771771
background: bool | Omit = omit,
772772
generation_config: GenerationConfigParam | Omit = omit,
773773
previous_interaction_id: str | Omit = omit,
774-
response_format: object | Omit = omit,
774+
response_format: interaction_create_params.ResponseFormat | Omit = omit,
775775
response_mime_type: str | Omit = omit,
776776
response_modalities: List[Literal["text", "image", "audio", "video", "document"]] | Omit = omit,
777777
service_tier: Literal["flex", "standard", "priority"] | Omit = omit,
@@ -842,7 +842,7 @@ async def create(
842842
background: bool | Omit = omit,
843843
generation_config: GenerationConfigParam | Omit = omit,
844844
previous_interaction_id: str | Omit = omit,
845-
response_format: object | Omit = omit,
845+
response_format: interaction_create_params.ResponseFormat | Omit = omit,
846846
response_mime_type: str | Omit = omit,
847847
response_modalities: List[Literal["text", "image", "audio", "video", "document"]] | Omit = omit,
848848
service_tier: Literal["flex", "standard", "priority"] | Omit = omit,
@@ -918,7 +918,7 @@ async def create(
918918
agent_config: interaction_create_params.AgentConfig | Omit = omit,
919919
background: bool | Omit = omit,
920920
previous_interaction_id: str | Omit = omit,
921-
response_format: object | Omit = omit,
921+
response_format: interaction_create_params.ResponseFormat | Omit = omit,
922922
response_mime_type: str | Omit = omit,
923923
response_modalities: List[Literal["text", "image", "audio", "video", "document"]] | Omit = omit,
924924
service_tier: Literal["flex", "standard", "priority"] | Omit = omit,
@@ -996,7 +996,7 @@ async def create(
996996
agent_config: interaction_create_params.AgentConfig | Omit = omit,
997997
background: bool | Omit = omit,
998998
previous_interaction_id: str | Omit = omit,
999-
response_format: object | Omit = omit,
999+
response_format: interaction_create_params.ResponseFormat | Omit = omit,
10001000
response_mime_type: str | Omit = omit,
10011001
response_modalities: List[Literal["text", "image", "audio", "video", "document"]] | Omit = omit,
10021002
service_tier: Literal["flex", "standard", "priority"] | Omit = omit,
@@ -1066,7 +1066,7 @@ async def create(
10661066
background: bool | Omit = omit,
10671067
generation_config: GenerationConfigParam | Omit = omit,
10681068
previous_interaction_id: str | Omit = omit,
1069-
response_format: object | Omit = omit,
1069+
response_format: interaction_create_params.ResponseFormat | Omit = omit,
10701070
response_mime_type: str | Omit = omit,
10711071
response_modalities: List[Literal["text", "image", "audio", "video", "document"]] | Omit = omit,
10721072
service_tier: Literal["flex", "standard", "priority"] | Omit = omit,
@@ -1135,7 +1135,7 @@ async def create(
11351135
background: bool | Omit = omit,
11361136
generation_config: GenerationConfigParam | Omit = omit,
11371137
previous_interaction_id: str | Omit = omit,
1138-
response_format: object | Omit = omit,
1138+
response_format: interaction_create_params.ResponseFormat | Omit = omit,
11391139
response_mime_type: str | Omit = omit,
11401140
response_modalities: List[Literal["text", "image", "audio", "video", "document"]] | Omit = omit,
11411141
service_tier: Literal["flex", "standard", "priority"] | Omit = omit,

google/genai/_interactions/types/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,16 @@
7979
from .function_result_step import FunctionResultStep as FunctionResultStep
8080
from .google_search_result import GoogleSearchResult as GoogleSearchResult
8181
from .place_citation_param import PlaceCitationParam as PlaceCitationParam
82+
from .text_response_format import TextResponseFormat as TextResponseFormat
8283
from .webhook_config_param import WebhookConfigParam as WebhookConfigParam
84+
from .audio_response_format import AudioResponseFormat as AudioResponseFormat
8385
from .file_search_call_step import FileSearchCallStep as FileSearchCallStep
8486
from .google_maps_call_step import GoogleMapsCallStep as GoogleMapsCallStep
87+
from .image_response_format import ImageResponseFormat as ImageResponseFormat
8588
from .interaction_sse_event import InteractionSSEEvent as InteractionSSEEvent
8689
from .url_context_call_step import URLContextCallStep as URLContextCallStep
8790
from .user_input_step_param import UserInputStepParam as UserInputStepParam
91+
from .video_response_format import VideoResponseFormat as VideoResponseFormat
8892
from .webhook_create_params import WebhookCreateParams as WebhookCreateParams
8993
from .webhook_list_response import WebhookListResponse as WebhookListResponse
9094
from .webhook_ping_response import WebhookPingResponse as WebhookPingResponse
@@ -112,11 +116,15 @@
112116
from .function_result_step_param import FunctionResultStepParam as FunctionResultStepParam
113117
from .google_maps_call_arguments import GoogleMapsCallArguments as GoogleMapsCallArguments
114118
from .interaction_complete_event import InteractionCompleteEvent as InteractionCompleteEvent
119+
from .text_response_format_param import TextResponseFormatParam as TextResponseFormatParam
115120
from .url_context_call_arguments import URLContextCallArguments as URLContextCallArguments
121+
from .audio_response_format_param import AudioResponseFormatParam as AudioResponseFormatParam
116122
from .file_search_call_step_param import FileSearchCallStepParam as FileSearchCallStepParam
117123
from .google_maps_call_step_param import GoogleMapsCallStepParam as GoogleMapsCallStepParam
124+
from .image_response_format_param import ImageResponseFormatParam as ImageResponseFormatParam
118125
from .mcp_server_tool_result_step import MCPServerToolResultStep as MCPServerToolResultStep
119126
from .url_context_call_step_param import URLContextCallStepParam as URLContextCallStepParam
127+
from .video_response_format_param import VideoResponseFormatParam as VideoResponseFormatParam
120128
from .google_search_call_arguments import GoogleSearchCallArguments as GoogleSearchCallArguments
121129
from .code_execution_call_arguments import CodeExecutionCallArguments as CodeExecutionCallArguments
122130
from .file_search_result_step_param import FileSearchResultStepParam as FileSearchResultStepParam
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
17+
18+
from typing import Optional
19+
from typing_extensions import Literal
20+
21+
from pydantic import Field as FieldInfo
22+
23+
from .._models import BaseModel
24+
25+
__all__ = ["AudioResponseFormat"]
26+
27+
28+
class AudioResponseFormat(BaseModel):
29+
"""Configuration for audio output format."""
30+
31+
type: Literal["audio"]
32+
33+
bit_rate: Optional[int] = FieldInfo(alias="bitRate", default=None)
34+
"""Bit rate in bits per second (bps).
35+
36+
Only applicable for compressed formats (MP3, Opus).
37+
"""
38+
39+
delivery: Optional[Literal["inline", "url"]] = None
40+
"""The delivery mode for the audio output."""
41+
42+
mime_type: Optional[
43+
Literal["audio/mp3", "audio/ogg_opus", "audio/l16", "audio/wav", "audio/alaw", "audio/mulaw"]
44+
] = FieldInfo(alias="mimeType", default=None)
45+
"""The MIME type of the audio output."""
46+
47+
sample_rate: Optional[int] = FieldInfo(alias="sampleRate", default=None)
48+
"""Sample rate in Hz."""
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
17+
18+
from __future__ import annotations
19+
20+
from typing_extensions import Literal, Required, Annotated, TypedDict
21+
22+
from .._utils import PropertyInfo
23+
24+
__all__ = ["AudioResponseFormatParam"]
25+
26+
27+
class AudioResponseFormatParam(TypedDict, total=False):
28+
"""Configuration for audio output format."""
29+
30+
type: Required[Literal["audio"]]
31+
32+
bit_rate: Annotated[int, PropertyInfo(alias="bitRate")]
33+
"""Bit rate in bits per second (bps).
34+
35+
Only applicable for compressed formats (MP3, Opus).
36+
"""
37+
38+
delivery: Literal["inline", "url"]
39+
"""The delivery mode for the audio output."""
40+
41+
mime_type: Annotated[
42+
Literal["audio/mp3", "audio/ogg_opus", "audio/l16", "audio/wav", "audio/alaw", "audio/mulaw"],
43+
PropertyInfo(alias="mimeType"),
44+
]
45+
"""The MIME type of the audio output."""
46+
47+
sample_rate: Annotated[int, PropertyInfo(alias="sampleRate")]
48+
"""Sample rate in Hz."""
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
17+
18+
from typing import Optional
19+
from typing_extensions import Literal
20+
21+
from pydantic import Field as FieldInfo
22+
23+
from .._models import BaseModel
24+
25+
__all__ = ["ImageResponseFormat"]
26+
27+
28+
class ImageResponseFormat(BaseModel):
29+
"""Configuration for image output format."""
30+
31+
type: Literal["image"]
32+
33+
aspect_ratio: Optional[
34+
Literal["1:1", "2:3", "3:2", "3:4", "4:3", "4:5", "5:4", "9:16", "16:9", "21:9", "1:8", "8:1", "1:4", "4:1"]
35+
] = FieldInfo(alias="aspectRatio", default=None)
36+
"""The aspect ratio for the image output."""
37+
38+
delivery: Optional[Literal["inline", "url"]] = None
39+
"""The delivery mode for the image output."""
40+
41+
image_size: Optional[Literal["512", "1K", "2K", "4K"]] = FieldInfo(alias="imageSize", default=None)
42+
"""The size of the image output."""
43+
44+
mime_type: Optional[Literal["image/jpeg"]] = FieldInfo(alias="mimeType", default=None)
45+
"""The MIME type of the image output."""
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
17+
18+
from __future__ import annotations
19+
20+
from typing_extensions import Literal, Required, Annotated, TypedDict
21+
22+
from .._utils import PropertyInfo
23+
24+
__all__ = ["ImageResponseFormatParam"]
25+
26+
27+
class ImageResponseFormatParam(TypedDict, total=False):
28+
"""Configuration for image output format."""
29+
30+
type: Required[Literal["image"]]
31+
32+
aspect_ratio: Annotated[
33+
Literal["1:1", "2:3", "3:2", "3:4", "4:3", "4:5", "5:4", "9:16", "16:9", "21:9", "1:8", "8:1", "1:4", "4:1"],
34+
PropertyInfo(alias="aspectRatio"),
35+
]
36+
"""The aspect ratio for the image output."""
37+
38+
delivery: Literal["inline", "url"]
39+
"""The delivery mode for the image output."""
40+
41+
image_size: Annotated[Literal["512", "1K", "2K", "4K"], PropertyInfo(alias="imageSize")]
42+
"""The size of the image output."""
43+
44+
mime_type: Annotated[Literal["image/jpeg"], PropertyInfo(alias="mimeType")]
45+
"""The MIME type of the image output."""

google/genai/_interactions/types/interaction.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@
3333
from .webhook_config import WebhookConfig
3434
from .document_content import DocumentContent
3535
from .dynamic_agent_config import DynamicAgentConfig
36+
from .text_response_format import TextResponseFormat
37+
from .audio_response_format import AudioResponseFormat
38+
from .image_response_format import ImageResponseFormat
39+
from .video_response_format import VideoResponseFormat
3640
from .deep_research_agent_config import DeepResearchAgentConfig
3741

38-
__all__ = ["Interaction", "AgentConfig", "Input"]
42+
__all__ = ["Interaction", "AgentConfig", "Input", "ResponseFormat", "ResponseFormatResponseFormatList"]
3943

4044
AgentConfig: TypeAlias = Annotated[
4145
Union[DynamicAgentConfig, DeepResearchAgentConfig], PropertyInfo(discriminator="type")
@@ -45,6 +49,19 @@
4549
str, List[Step], List[Content], TextContent, ImageContent, AudioContent, DocumentContent, VideoContent
4650
]
4751

52+
ResponseFormatResponseFormatList: TypeAlias = Union[
53+
AudioResponseFormat, TextResponseFormat, ImageResponseFormat, VideoResponseFormat, object
54+
]
55+
56+
ResponseFormat: TypeAlias = Union[
57+
List[ResponseFormatResponseFormatList],
58+
AudioResponseFormat,
59+
TextResponseFormat,
60+
ImageResponseFormat,
61+
VideoResponseFormat,
62+
object,
63+
]
64+
4865

4966
class Interaction(BaseModel):
5067
"""The Interaction resource."""
@@ -90,7 +107,7 @@ class Interaction(BaseModel):
90107
previous_interaction_id: Optional[str] = None
91108
"""The ID of the previous interaction, if any."""
92109

93-
response_format: Optional[object] = None
110+
response_format: Optional[ResponseFormat] = None
94111
"""
95112
Enforces that the generated response is a JSON object that complies with the
96113
JSON schema specified in this field.

0 commit comments

Comments
 (0)