From 74ac883c8683c2b40dee19b2ca82585da1dc0505 Mon Sep 17 00:00:00 2001 From: Google Team Member Date: Fri, 24 Jul 2026 07:37:15 -0700 Subject: [PATCH] cleanup: Remove legacy `response_format` field. PiperOrigin-RevId: 953360105 --- .../_gaos/types/interactions/__init__.py | 8 +++- .../interactions/createagentinteraction.py | 13 ++++- .../interactions/createmodelinteraction.py | 13 ++++- .../_gaos/types/interactions/interaction.py | 13 ++++- .../types/interactions/responseformat.py | 47 +++++++++++++++---- 5 files changed, 81 insertions(+), 13 deletions(-) diff --git a/google/genai/_gaos/types/interactions/__init__.py b/google/genai/_gaos/types/interactions/__init__.py index 4ea4846625..a7c111397e 100644 --- a/google/genai/_gaos/types/interactions/__init__.py +++ b/google/genai/_gaos/types/interactions/__init__.py @@ -318,7 +318,11 @@ from .ragstoreconfig import RagStoreConfig, RagStoreConfigParam from .ranking import Ranking, RankingParam from .rankservice import RankService, RankServiceParam - from .responseformat import ResponseFormat, ResponseFormatParam + from .responseformat import ( + ResponseFormat, + ResponseFormatParam, + UnknownResponseFormat, + ) from .responsemodality import ResponseModality from .retrieval import Retrieval, RetrievalParam, RetrievalRetrievalType from .retrievalcallarguments import ( @@ -822,6 +826,7 @@ "UnknownFunctionResultSubcontent", "UnknownInteractionAgentConfig", "UnknownInteractionSSEEvent", + "UnknownResponseFormat", "UnknownStep", "UnknownStepDeltaData", "UnknownThoughtSummaryContent", @@ -1127,6 +1132,7 @@ "RankServiceParam": ".rankservice", "ResponseFormat": ".responseformat", "ResponseFormatParam": ".responseformat", + "UnknownResponseFormat": ".responseformat", "ResponseModality": ".responsemodality", "Retrieval": ".retrieval", "RetrievalParam": ".retrieval", diff --git a/google/genai/_gaos/types/interactions/createagentinteraction.py b/google/genai/_gaos/types/interactions/createagentinteraction.py index 24f48a6415..1df3fadcd3 100644 --- a/google/genai/_gaos/types/interactions/createagentinteraction.py +++ b/google/genai/_gaos/types/interactions/createagentinteraction.py @@ -19,6 +19,7 @@ from __future__ import annotations from .. import BaseModel, UNSET_SENTINEL, current_exclude_none, serialize_with_info +from ...utils.unions import dispatch_open_union_members from ..basemodel import current_filtered_dump from .agentoption import AgentOption from .antigravityagentconfig import AntigravityAgentConfig, AntigravityAgentConfigParam @@ -36,6 +37,7 @@ from .servicetier import ServiceTier from .tool import Tool, ToolParam from .webhookconfig import WebhookConfig, WebhookConfigParam +from functools import partial import pydantic from pydantic import Field, model_serializer from typing import Dict, List, Optional, Union @@ -94,7 +96,16 @@ CreateAgentInteractionResponseFormat = TypeAliasType( - "CreateAgentInteractionResponseFormat", Union[ResponseFormat, List[ResponseFormat]] + "CreateAgentInteractionResponseFormat", + Annotated[ + Union[ResponseFormat, List[ResponseFormat]], + pydantic.WrapValidator( + partial( + dispatch_open_union_members, + members=(ResponseFormat, List[ResponseFormat]), + ) + ), + ], ) r"""Enforces that the generated response is a JSON object that complies with the JSON schema specified in this field. diff --git a/google/genai/_gaos/types/interactions/createmodelinteraction.py b/google/genai/_gaos/types/interactions/createmodelinteraction.py index 0a04cf2dd3..779eaa5ea9 100644 --- a/google/genai/_gaos/types/interactions/createmodelinteraction.py +++ b/google/genai/_gaos/types/interactions/createmodelinteraction.py @@ -19,6 +19,7 @@ from __future__ import annotations from .. import BaseModel, UNSET_SENTINEL, current_exclude_none, serialize_with_info +from ...utils.unions import dispatch_open_union_members from ..basemodel import current_filtered_dump from .environment import Environment, EnvironmentParam from .generationconfig import GenerationConfig, GenerationConfigParam @@ -30,6 +31,7 @@ from .servicetier import ServiceTier from .tool import Tool, ToolParam from .webhookconfig import WebhookConfig, WebhookConfigParam +from functools import partial import pydantic from pydantic import model_serializer from typing import Dict, List, Optional, Union @@ -64,7 +66,16 @@ CreateModelInteractionResponseFormat = TypeAliasType( - "CreateModelInteractionResponseFormat", Union[ResponseFormat, List[ResponseFormat]] + "CreateModelInteractionResponseFormat", + Annotated[ + Union[ResponseFormat, List[ResponseFormat]], + pydantic.WrapValidator( + partial( + dispatch_open_union_members, + members=(ResponseFormat, List[ResponseFormat]), + ) + ), + ], ) r"""Enforces that the generated response is a JSON object that complies with the JSON schema specified in this field. diff --git a/google/genai/_gaos/types/interactions/interaction.py b/google/genai/_gaos/types/interactions/interaction.py index 71dc356356..2d0f49fd4c 100644 --- a/google/genai/_gaos/types/interactions/interaction.py +++ b/google/genai/_gaos/types/interactions/interaction.py @@ -25,7 +25,7 @@ current_exclude_none, serialize_with_info, ) -from ...utils.unions import parse_open_union +from ...utils.unions import dispatch_open_union_members, parse_open_union from ..basemodel import current_filtered_dump from .agentoption import AgentOption from .antigravityagentconfig import AntigravityAgentConfig, AntigravityAgentConfigParam @@ -139,7 +139,16 @@ class UnknownInteractionAgentConfig(BaseModel): InteractionResponseFormat = TypeAliasType( - "InteractionResponseFormat", Union[ResponseFormat, List[ResponseFormat]] + "InteractionResponseFormat", + Annotated[ + Union[ResponseFormat, List[ResponseFormat]], + pydantic.WrapValidator( + partial( + dispatch_open_union_members, + members=(ResponseFormat, List[ResponseFormat]), + ) + ), + ], ) r"""Enforces that the generated response is a JSON object that complies with the JSON schema specified in this field. diff --git a/google/genai/_gaos/types/interactions/responseformat.py b/google/genai/_gaos/types/interactions/responseformat.py index f020d27887..ea3d59b515 100644 --- a/google/genai/_gaos/types/interactions/responseformat.py +++ b/google/genai/_gaos/types/interactions/responseformat.py @@ -18,12 +18,17 @@ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" from __future__ import annotations +from .. import BaseModel +from ...utils.unions import parse_open_union from .audioresponseformat import AudioResponseFormat, AudioResponseFormatParam from .imageresponseformat import ImageResponseFormat, ImageResponseFormatParam from .textresponseformat import TextResponseFormat, TextResponseFormatParam from .videoresponseformat import VideoResponseFormat, VideoResponseFormatParam -from typing import Any, Dict, Union -from typing_extensions import TypeAliasType +from functools import partial +from pydantic import ConfigDict +from pydantic.functional_validators import BeforeValidator +from typing import Any, Literal, Union +from typing_extensions import Annotated, TypeAliasType ResponseFormatParam = TypeAliasType( @@ -33,18 +38,44 @@ AudioResponseFormatParam, ImageResponseFormatParam, VideoResponseFormatParam, - Dict[str, Any], ], ) -ResponseFormat = TypeAliasType( - "ResponseFormat", +class UnknownResponseFormat(BaseModel): + r"""A ResponseFormat variant the SDK doesn't recognize. Preserves the raw payload.""" + + type: Literal["UNKNOWN"] = "UNKNOWN" + raw: Any + is_unknown: Literal[True] = True + + model_config = ConfigDict(frozen=True) + + +_RESPONSE_FORMAT_VARIANTS: dict[str, Any] = { + "audio": AudioResponseFormat, + "image": ImageResponseFormat, + "text": TextResponseFormat, + "video": VideoResponseFormat, +} + + +ResponseFormat = Annotated[ Union[ - TextResponseFormat, AudioResponseFormat, ImageResponseFormat, + TextResponseFormat, VideoResponseFormat, - Dict[str, Any], + UnknownResponseFormat, ], -) + BeforeValidator( + partial( + parse_open_union, + disc_key="type", + variants=_RESPONSE_FORMAT_VARIANTS, + unknown_cls=UnknownResponseFormat, + union_name="ResponseFormat", + lenient=True, + ) + ), +]