Skip to content
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
3 changes: 2 additions & 1 deletion google/genai/_gaos/resources/interactions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
from ...types.interactions.mediaresolution import MediaResolution
from ...types.interactions.modalitytokens import ModalityTokens
from ...types.interactions.model import Model
from ...types.interactions.modeloutputstep import ModelOutputStep
from ...types.interactions.modeloutputstep import ModelOutputStep, ModelOutputStepError
from ...types.interactions.parallelaisearchconfig import ParallelAISearchConfig
from ...types.interactions.placecitation import PlaceCitation
from ...types.interactions.ragresource import RagResource
Expand Down Expand Up @@ -270,6 +270,7 @@
"ModalityTokens",
"Model",
"ModelOutputStep",
"ModelOutputStepError",
"ModelParam",
"ParallelAISearchConfig",
"PlaceCitation",
Expand Down
11 changes: 10 additions & 1 deletion google/genai/_gaos/types/interactions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,12 @@
from .mediaresolution import MediaResolution
from .modalitytokens import ModalityTokens, ModalityTokensParam
from .model import Model
from .modeloutputstep import ModelOutputStep, ModelOutputStepParam
from .modeloutputstep import (
ModelOutputStep,
ModelOutputStepError,
ModelOutputStepErrorParam,
ModelOutputStepParam,
)
from .parallelaisearchconfig import (
ParallelAISearchConfig,
ParallelAISearchConfigParam,
Expand Down Expand Up @@ -573,6 +578,8 @@
"ModalityTokensParam",
"Model",
"ModelOutputStep",
"ModelOutputStepError",
"ModelOutputStepErrorParam",
"ModelOutputStepParam",
"Network",
"NetworkEnum",
Expand Down Expand Up @@ -915,6 +922,8 @@
"ModalityTokensParam": ".modalitytokens",
"Model": ".model",
"ModelOutputStep": ".modeloutputstep",
"ModelOutputStepError": ".modeloutputstep",
"ModelOutputStepErrorParam": ".modeloutputstep",
"ModelOutputStepParam": ".modeloutputstep",
"ParallelAISearchConfig": ".parallelaisearchconfig",
"ParallelAISearchConfigParam": ".parallelaisearchconfig",
Expand Down
59 changes: 57 additions & 2 deletions google/genai/_gaos/types/interactions/modeloutputstep.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,67 @@
import pydantic
from pydantic import model_serializer
from pydantic.functional_validators import AfterValidator
from typing import List, Literal, Optional
from typing import Any, Dict, List, Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class ModelOutputStepErrorParam(TypedDict):
r"""The error result of the operation in case of failure or cancellation."""

code: NotRequired[int]
r"""The status code, which should be an enum value of google.rpc.Code."""
message: NotRequired[str]
r"""A developer-facing error message, which should be in English. Any
user-facing error message should be localized and sent in the
google.rpc.Status.details field, or localized by the client.
"""
details: NotRequired[List[Dict[str, Any]]]
r"""A list of messages that carry the error details. There is a common set of
message types for APIs to use.
"""


class ModelOutputStepError(BaseModel):
r"""The error result of the operation in case of failure or cancellation."""

code: Optional[int] = None
r"""The status code, which should be an enum value of google.rpc.Code."""

message: Optional[str] = None
r"""A developer-facing error message, which should be in English. Any
user-facing error message should be localized and sent in the
google.rpc.Status.details field, or localized by the client.
"""

details: Optional[List[Dict[str, Any]]] = None
r"""A list of messages that carry the error details. There is a common set of
message types for APIs to use.
"""

@model_serializer(mode="wrap")
def serialize_model(self, handler):
optional_fields = set(["code", "message", "details"])
serialized = handler(self)
m = {}

for n, f in type(self).model_fields.items():
k = f.alias or n
val = serialized.get(k, serialized.get(n))

if val != UNSET_SENTINEL:
if val is not None or k not in optional_fields:
m[k] = val

return m


class ModelOutputStepParam(TypedDict):
r"""Output generated by the model."""

type: Literal["model_output"]
content: NotRequired[List[ContentParam]]
error: NotRequired[ModelOutputStepErrorParam]
r"""The error result of the operation in case of failure or cancellation."""


class ModelOutputStep(BaseModel):
Expand All @@ -46,9 +98,12 @@ class ModelOutputStep(BaseModel):

content: Optional[List[Content]] = None

error: Optional[ModelOutputStepError] = None
r"""The error result of the operation in case of failure or cancellation."""

@model_serializer(mode="wrap")
def serialize_model(self, handler):
optional_fields = set(["content"])
optional_fields = set(["content", "error"])
serialized = handler(self)
m = {}

Expand Down
2 changes: 1 addition & 1 deletion google/genai/_gaos/types/interactions/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
StepParam = TypeAliasType(
"StepParam",
Union[
ModelOutputStepParam,
UserInputStepParam,
FileSearchCallStepParam,
ModelOutputStepParam,
ThoughtStepParam,
FileSearchResultStepParam,
CodeExecutionCallStepParam,
Expand Down
Loading