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
11 changes: 9 additions & 2 deletions google/genai/_interactions/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from typing import TYPE_CHECKING, Any, Union, Generic, TypeVar, Callable, cast, overload
from datetime import date, datetime
from typing_extensions import Self, Literal
from typing_extensions import Self, Literal, TypedDict

import pydantic
from pydantic.fields import FieldInfo
Expand Down Expand Up @@ -146,6 +146,10 @@ def model_json(model: pydantic.BaseModel, *, indent: int | None = None) -> str:
return model.model_dump_json(indent=indent)


class _ModelDumpKwargs(TypedDict, total=False):
by_alias: bool


def model_dump(
model: pydantic.BaseModel,
*,
Expand All @@ -157,14 +161,17 @@ def model_dump(
by_alias: bool | None = None,
) -> dict[str, Any]:
if (not PYDANTIC_V1) or hasattr(model, "model_dump"):
kwargs: _ModelDumpKwargs = {}
if by_alias is not None:
kwargs["by_alias"] = by_alias
return model.model_dump(
mode=mode,
exclude=exclude,
exclude_unset=exclude_unset,
exclude_defaults=exclude_defaults,
# warnings are not supported in Pydantic v1
warnings=True if PYDANTIC_V1 else warnings,
by_alias=by_alias,
**kwargs,
)
return cast(
"dict[str, Any]",
Expand Down
12 changes: 6 additions & 6 deletions google/genai/_interactions/types/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@
VideoContent,
ThoughtContent,
FunctionCallContent,
FunctionResultContent,
CodeExecutionCallContent,
CodeExecutionResultContent,
URLContextCallContent,
URLContextResultContent,
MCPServerToolCallContent,
GoogleSearchCallContent,
FileSearchCallContent,
GoogleMapsCallContent,
FunctionResultContent,
CodeExecutionResultContent,
URLContextResultContent,
GoogleSearchResultContent,
MCPServerToolCallContent,
MCPServerToolResultContent,
FileSearchCallContent,
FileSearchResultContent,
GoogleMapsCallContent,
GoogleMapsResultContent,
],
PropertyInfo(discriminator="type"),
Expand Down
186 changes: 86 additions & 100 deletions google/genai/_interactions/types/content_delta.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,20 @@
"DeltaThoughtSummaryContent",
"DeltaThoughtSignature",
"DeltaFunctionCall",
"DeltaFunctionResult",
"DeltaFunctionResultResult",
"DeltaFunctionResultResultItems",
"DeltaFunctionResultResultItemsItem",
"DeltaCodeExecutionCall",
"DeltaCodeExecutionResult",
"DeltaURLContextCall",
"DeltaURLContextResult",
"DeltaGoogleSearchCall",
"DeltaGoogleSearchResult",
"DeltaMCPServerToolCall",
"DeltaMCPServerToolResult",
"DeltaMCPServerToolResultResult",
"DeltaMCPServerToolResultResultItems",
"DeltaMCPServerToolResultResultItemsItem",
"DeltaFileSearchCall",
"DeltaFileSearchResult",
"DeltaGoogleMapsCall",
"DeltaFunctionResult",
"DeltaFunctionResultResultFunctionResultSubcontentList",
"DeltaCodeExecutionResult",
"DeltaURLContextResult",
"DeltaGoogleSearchResult",
"DeltaMCPServerToolResult",
"DeltaMCPServerToolResultResultFunctionResultSubcontentList",
"DeltaFileSearchResult",
"DeltaGoogleMapsResult",
]

Expand Down Expand Up @@ -163,146 +159,157 @@ class DeltaFunctionCall(BaseModel):
"""A signature hash for backend validation."""


DeltaFunctionResultResultItemsItem: TypeAlias = Union[TextContent, ImageContent]
class DeltaCodeExecutionCall(BaseModel):
id: str
"""A unique ID for this specific tool call."""

arguments: CodeExecutionCallArguments
"""The arguments to pass to the code execution."""

class DeltaFunctionResultResultItems(BaseModel):
items: Optional[List[DeltaFunctionResultResultItemsItem]] = None
type: Literal["code_execution_call"]

signature: Optional[str] = None
"""A signature hash for backend validation."""

DeltaFunctionResultResult: TypeAlias = Union[DeltaFunctionResultResultItems, str, object]

class DeltaURLContextCall(BaseModel):
id: str
"""A unique ID for this specific tool call."""

class DeltaFunctionResult(BaseModel):
call_id: str
"""ID to match the ID from the function call block."""
arguments: URLContextCallArguments
"""The arguments to pass to the URL context."""

result: DeltaFunctionResultResult
"""Tool call result delta."""
type: Literal["url_context_call"]

type: Literal["function_result"]
signature: Optional[str] = None
"""A signature hash for backend validation."""

is_error: Optional[bool] = None

name: Optional[str] = None
class DeltaGoogleSearchCall(BaseModel):
id: str
"""A unique ID for this specific tool call."""

arguments: GoogleSearchCallArguments
"""The arguments to pass to Google Search."""

type: Literal["google_search_call"]

signature: Optional[str] = None
"""A signature hash for backend validation."""


class DeltaCodeExecutionCall(BaseModel):
class DeltaMCPServerToolCall(BaseModel):
id: str
"""A unique ID for this specific tool call."""

arguments: CodeExecutionCallArguments
"""The arguments to pass to the code execution."""
arguments: Dict[str, object]

type: Literal["code_execution_call"]
name: str

signature: Optional[str] = None
"""A signature hash for backend validation."""
server_name: str

type: Literal["mcp_server_tool_call"]

class DeltaCodeExecutionResult(BaseModel):
call_id: str
"""ID to match the ID from the function call block."""
signature: Optional[str] = None
"""A signature hash for backend validation."""

result: str

type: Literal["code_execution_result"]
class DeltaFileSearchCall(BaseModel):
id: str
"""A unique ID for this specific tool call."""

is_error: Optional[bool] = None
type: Literal["file_search_call"]

signature: Optional[str] = None
"""A signature hash for backend validation."""


class DeltaURLContextCall(BaseModel):
class DeltaGoogleMapsCall(BaseModel):
id: str
"""A unique ID for this specific tool call."""

arguments: URLContextCallArguments
"""The arguments to pass to the URL context."""
type: Literal["google_maps_call"]

type: Literal["url_context_call"]
arguments: Optional[GoogleMapsCallArguments] = None
"""The arguments to pass to the Google Maps tool."""

signature: Optional[str] = None
"""A signature hash for backend validation."""


class DeltaURLContextResult(BaseModel):
DeltaFunctionResultResultFunctionResultSubcontentList: TypeAlias = Annotated[
Union[TextContent, ImageContent], PropertyInfo(discriminator="type")
]


class DeltaFunctionResult(BaseModel):
call_id: str
"""ID to match the ID from the function call block."""

result: List[URLContextResult]
result: Union[List[DeltaFunctionResultResultFunctionResultSubcontentList], str, object]

type: Literal["url_context_result"]
type: Literal["function_result"]

is_error: Optional[bool] = None

name: Optional[str] = None

signature: Optional[str] = None
"""A signature hash for backend validation."""


class DeltaGoogleSearchCall(BaseModel):
id: str
"""A unique ID for this specific tool call."""
class DeltaCodeExecutionResult(BaseModel):
call_id: str
"""ID to match the ID from the function call block."""

arguments: GoogleSearchCallArguments
"""The arguments to pass to Google Search."""
result: str

type: Literal["google_search_call"]
type: Literal["code_execution_result"]

is_error: Optional[bool] = None

signature: Optional[str] = None
"""A signature hash for backend validation."""


class DeltaGoogleSearchResult(BaseModel):
class DeltaURLContextResult(BaseModel):
call_id: str
"""ID to match the ID from the function call block."""

result: List[GoogleSearchResult]
result: List[URLContextResult]

type: Literal["google_search_result"]
type: Literal["url_context_result"]

is_error: Optional[bool] = None

signature: Optional[str] = None
"""A signature hash for backend validation."""


class DeltaMCPServerToolCall(BaseModel):
id: str
"""A unique ID for this specific tool call."""

arguments: Dict[str, object]
class DeltaGoogleSearchResult(BaseModel):
call_id: str
"""ID to match the ID from the function call block."""

name: str
result: List[GoogleSearchResult]

server_name: str
type: Literal["google_search_result"]

type: Literal["mcp_server_tool_call"]
is_error: Optional[bool] = None

signature: Optional[str] = None
"""A signature hash for backend validation."""


DeltaMCPServerToolResultResultItemsItem: TypeAlias = Union[TextContent, ImageContent]


class DeltaMCPServerToolResultResultItems(BaseModel):
items: Optional[List[DeltaMCPServerToolResultResultItemsItem]] = None


DeltaMCPServerToolResultResult: TypeAlias = Union[DeltaMCPServerToolResultResultItems, str, object]
DeltaMCPServerToolResultResultFunctionResultSubcontentList: TypeAlias = Annotated[
Union[TextContent, ImageContent], PropertyInfo(discriminator="type")
]


class DeltaMCPServerToolResult(BaseModel):
call_id: str
"""ID to match the ID from the function call block."""

result: DeltaMCPServerToolResultResult
"""Tool call result delta."""
result: Union[List[DeltaMCPServerToolResultResultFunctionResultSubcontentList], str, object]

type: Literal["mcp_server_tool_result"]

Expand All @@ -314,16 +321,6 @@ class DeltaMCPServerToolResult(BaseModel):
"""A signature hash for backend validation."""


class DeltaFileSearchCall(BaseModel):
id: str
"""A unique ID for this specific tool call."""

type: Literal["file_search_call"]

signature: Optional[str] = None
"""A signature hash for backend validation."""


class DeltaFileSearchResult(BaseModel):
call_id: str
"""ID to match the ID from the function call block."""
Expand All @@ -336,19 +333,6 @@ class DeltaFileSearchResult(BaseModel):
"""A signature hash for backend validation."""


class DeltaGoogleMapsCall(BaseModel):
id: str
"""A unique ID for this specific tool call."""

type: Literal["google_maps_call"]

arguments: Optional[GoogleMapsCallArguments] = None
"""The arguments to pass to the Google Maps tool."""

signature: Optional[str] = None
"""A signature hash for backend validation."""


class DeltaGoogleMapsResult(BaseModel):
call_id: str
"""ID to match the ID from the function call block."""
Expand All @@ -372,18 +356,18 @@ class DeltaGoogleMapsResult(BaseModel):
DeltaThoughtSummary,
DeltaThoughtSignature,
DeltaFunctionCall,
DeltaFunctionResult,
DeltaCodeExecutionCall,
DeltaCodeExecutionResult,
DeltaURLContextCall,
DeltaURLContextResult,
DeltaGoogleSearchCall,
DeltaGoogleSearchResult,
DeltaMCPServerToolCall,
DeltaMCPServerToolResult,
DeltaFileSearchCall,
DeltaFileSearchResult,
DeltaGoogleMapsCall,
DeltaFunctionResult,
DeltaCodeExecutionResult,
DeltaURLContextResult,
DeltaGoogleSearchResult,
DeltaMCPServerToolResult,
DeltaFileSearchResult,
DeltaGoogleMapsResult,
],
PropertyInfo(discriminator="type"),
Expand All @@ -392,12 +376,14 @@ class DeltaGoogleMapsResult(BaseModel):

class ContentDelta(BaseModel):
delta: Delta
"""The delta content data for a content block."""

event_type: Literal["content.delta"]

index: int

event_id: Optional[str] = None
"""
The event_id token to be used to resume the interaction stream, from this event.
The event_id token to be used to resume the interaction stream, from
this event.
"""
Loading
Loading