Skip to content

Commit b200d5b

Browse files
hkt74copybara-github
authored andcommitted
chore: update comments
PiperOrigin-RevId: 878135574
1 parent 6c3379f commit b200d5b

24 files changed

+181
-166
lines changed

google/genai/_interactions/_compat.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from typing import TYPE_CHECKING, Any, Union, Generic, TypeVar, Callable, cast, overload
1919
from datetime import date, datetime
20-
from typing_extensions import Self, Literal
20+
from typing_extensions import Self, Literal, TypedDict
2121

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

148148

149+
class _ModelDumpKwargs(TypedDict, total=False):
150+
by_alias: bool
151+
152+
149153
def model_dump(
150154
model: pydantic.BaseModel,
151155
*,
@@ -157,14 +161,17 @@ def model_dump(
157161
by_alias: bool | None = None,
158162
) -> dict[str, Any]:
159163
if (not PYDANTIC_V1) or hasattr(model, "model_dump"):
164+
kwargs: _ModelDumpKwargs = {}
165+
if by_alias is not None:
166+
kwargs["by_alias"] = by_alias
160167
return model.model_dump(
161168
mode=mode,
162169
exclude=exclude,
163170
exclude_unset=exclude_unset,
164171
exclude_defaults=exclude_defaults,
165172
# warnings are not supported in Pydantic v1
166173
warnings=True if PYDANTIC_V1 else warnings,
167-
by_alias=by_alias,
174+
**kwargs,
168175
)
169176
return cast(
170177
"dict[str, Any]",

google/genai/_interactions/types/content.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@
5151
VideoContent,
5252
ThoughtContent,
5353
FunctionCallContent,
54-
FunctionResultContent,
5554
CodeExecutionCallContent,
56-
CodeExecutionResultContent,
5755
URLContextCallContent,
58-
URLContextResultContent,
56+
MCPServerToolCallContent,
5957
GoogleSearchCallContent,
58+
FileSearchCallContent,
59+
GoogleMapsCallContent,
60+
FunctionResultContent,
61+
CodeExecutionResultContent,
62+
URLContextResultContent,
6063
GoogleSearchResultContent,
61-
MCPServerToolCallContent,
6264
MCPServerToolResultContent,
63-
FileSearchCallContent,
6465
FileSearchResultContent,
65-
GoogleMapsCallContent,
6666
GoogleMapsResultContent,
6767
],
6868
PropertyInfo(discriminator="type"),

google/genai/_interactions/types/content_delta.py

Lines changed: 86 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,20 @@
4343
"DeltaThoughtSummaryContent",
4444
"DeltaThoughtSignature",
4545
"DeltaFunctionCall",
46-
"DeltaFunctionResult",
47-
"DeltaFunctionResultResult",
48-
"DeltaFunctionResultResultItems",
49-
"DeltaFunctionResultResultItemsItem",
5046
"DeltaCodeExecutionCall",
51-
"DeltaCodeExecutionResult",
5247
"DeltaURLContextCall",
53-
"DeltaURLContextResult",
5448
"DeltaGoogleSearchCall",
55-
"DeltaGoogleSearchResult",
5649
"DeltaMCPServerToolCall",
57-
"DeltaMCPServerToolResult",
58-
"DeltaMCPServerToolResultResult",
59-
"DeltaMCPServerToolResultResultItems",
60-
"DeltaMCPServerToolResultResultItemsItem",
6150
"DeltaFileSearchCall",
62-
"DeltaFileSearchResult",
6351
"DeltaGoogleMapsCall",
52+
"DeltaFunctionResult",
53+
"DeltaFunctionResultResultFunctionResultSubcontentList",
54+
"DeltaCodeExecutionResult",
55+
"DeltaURLContextResult",
56+
"DeltaGoogleSearchResult",
57+
"DeltaMCPServerToolResult",
58+
"DeltaMCPServerToolResultResultFunctionResultSubcontentList",
59+
"DeltaFileSearchResult",
6460
"DeltaGoogleMapsResult",
6561
]
6662

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

165161

166-
DeltaFunctionResultResultItemsItem: TypeAlias = Union[TextContent, ImageContent]
162+
class DeltaCodeExecutionCall(BaseModel):
163+
id: str
164+
"""A unique ID for this specific tool call."""
167165

166+
arguments: CodeExecutionCallArguments
167+
"""The arguments to pass to the code execution."""
168168

169-
class DeltaFunctionResultResultItems(BaseModel):
170-
items: Optional[List[DeltaFunctionResultResultItemsItem]] = None
169+
type: Literal["code_execution_call"]
171170

171+
signature: Optional[str] = None
172+
"""A signature hash for backend validation."""
172173

173-
DeltaFunctionResultResult: TypeAlias = Union[DeltaFunctionResultResultItems, str, object]
174174

175+
class DeltaURLContextCall(BaseModel):
176+
id: str
177+
"""A unique ID for this specific tool call."""
175178

176-
class DeltaFunctionResult(BaseModel):
177-
call_id: str
178-
"""ID to match the ID from the function call block."""
179+
arguments: URLContextCallArguments
180+
"""The arguments to pass to the URL context."""
179181

180-
result: DeltaFunctionResultResult
181-
"""Tool call result delta."""
182+
type: Literal["url_context_call"]
182183

183-
type: Literal["function_result"]
184+
signature: Optional[str] = None
185+
"""A signature hash for backend validation."""
184186

185-
is_error: Optional[bool] = None
186187

187-
name: Optional[str] = None
188+
class DeltaGoogleSearchCall(BaseModel):
189+
id: str
190+
"""A unique ID for this specific tool call."""
191+
192+
arguments: GoogleSearchCallArguments
193+
"""The arguments to pass to Google Search."""
194+
195+
type: Literal["google_search_call"]
188196

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

192200

193-
class DeltaCodeExecutionCall(BaseModel):
201+
class DeltaMCPServerToolCall(BaseModel):
194202
id: str
195203
"""A unique ID for this specific tool call."""
196204

197-
arguments: CodeExecutionCallArguments
198-
"""The arguments to pass to the code execution."""
205+
arguments: Dict[str, object]
199206

200-
type: Literal["code_execution_call"]
207+
name: str
201208

202-
signature: Optional[str] = None
203-
"""A signature hash for backend validation."""
209+
server_name: str
204210

211+
type: Literal["mcp_server_tool_call"]
205212

206-
class DeltaCodeExecutionResult(BaseModel):
207-
call_id: str
208-
"""ID to match the ID from the function call block."""
213+
signature: Optional[str] = None
214+
"""A signature hash for backend validation."""
209215

210-
result: str
211216

212-
type: Literal["code_execution_result"]
217+
class DeltaFileSearchCall(BaseModel):
218+
id: str
219+
"""A unique ID for this specific tool call."""
213220

214-
is_error: Optional[bool] = None
221+
type: Literal["file_search_call"]
215222

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

219226

220-
class DeltaURLContextCall(BaseModel):
227+
class DeltaGoogleMapsCall(BaseModel):
221228
id: str
222229
"""A unique ID for this specific tool call."""
223230

224-
arguments: URLContextCallArguments
225-
"""The arguments to pass to the URL context."""
231+
type: Literal["google_maps_call"]
226232

227-
type: Literal["url_context_call"]
233+
arguments: Optional[GoogleMapsCallArguments] = None
234+
"""The arguments to pass to the Google Maps tool."""
228235

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

232239

233-
class DeltaURLContextResult(BaseModel):
240+
DeltaFunctionResultResultFunctionResultSubcontentList: TypeAlias = Annotated[
241+
Union[TextContent, ImageContent], PropertyInfo(discriminator="type")
242+
]
243+
244+
245+
class DeltaFunctionResult(BaseModel):
234246
call_id: str
235247
"""ID to match the ID from the function call block."""
236248

237-
result: List[URLContextResult]
249+
result: Union[List[DeltaFunctionResultResultFunctionResultSubcontentList], str, object]
238250

239-
type: Literal["url_context_result"]
251+
type: Literal["function_result"]
240252

241253
is_error: Optional[bool] = None
242254

255+
name: Optional[str] = None
256+
243257
signature: Optional[str] = None
244258
"""A signature hash for backend validation."""
245259

246260

247-
class DeltaGoogleSearchCall(BaseModel):
248-
id: str
249-
"""A unique ID for this specific tool call."""
261+
class DeltaCodeExecutionResult(BaseModel):
262+
call_id: str
263+
"""ID to match the ID from the function call block."""
250264

251-
arguments: GoogleSearchCallArguments
252-
"""The arguments to pass to Google Search."""
265+
result: str
253266

254-
type: Literal["google_search_call"]
267+
type: Literal["code_execution_result"]
268+
269+
is_error: Optional[bool] = None
255270

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

259274

260-
class DeltaGoogleSearchResult(BaseModel):
275+
class DeltaURLContextResult(BaseModel):
261276
call_id: str
262277
"""ID to match the ID from the function call block."""
263278

264-
result: List[GoogleSearchResult]
279+
result: List[URLContextResult]
265280

266-
type: Literal["google_search_result"]
281+
type: Literal["url_context_result"]
267282

268283
is_error: Optional[bool] = None
269284

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

273288

274-
class DeltaMCPServerToolCall(BaseModel):
275-
id: str
276-
"""A unique ID for this specific tool call."""
277-
278-
arguments: Dict[str, object]
289+
class DeltaGoogleSearchResult(BaseModel):
290+
call_id: str
291+
"""ID to match the ID from the function call block."""
279292

280-
name: str
293+
result: List[GoogleSearchResult]
281294

282-
server_name: str
295+
type: Literal["google_search_result"]
283296

284-
type: Literal["mcp_server_tool_call"]
297+
is_error: Optional[bool] = None
285298

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

289302

290-
DeltaMCPServerToolResultResultItemsItem: TypeAlias = Union[TextContent, ImageContent]
291-
292-
293-
class DeltaMCPServerToolResultResultItems(BaseModel):
294-
items: Optional[List[DeltaMCPServerToolResultResultItemsItem]] = None
295-
296-
297-
DeltaMCPServerToolResultResult: TypeAlias = Union[DeltaMCPServerToolResultResultItems, str, object]
303+
DeltaMCPServerToolResultResultFunctionResultSubcontentList: TypeAlias = Annotated[
304+
Union[TextContent, ImageContent], PropertyInfo(discriminator="type")
305+
]
298306

299307

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

304-
result: DeltaMCPServerToolResultResult
305-
"""Tool call result delta."""
312+
result: Union[List[DeltaMCPServerToolResultResultFunctionResultSubcontentList], str, object]
306313

307314
type: Literal["mcp_server_tool_result"]
308315

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

316323

317-
class DeltaFileSearchCall(BaseModel):
318-
id: str
319-
"""A unique ID for this specific tool call."""
320-
321-
type: Literal["file_search_call"]
322-
323-
signature: Optional[str] = None
324-
"""A signature hash for backend validation."""
325-
326-
327324
class DeltaFileSearchResult(BaseModel):
328325
call_id: str
329326
"""ID to match the ID from the function call block."""
@@ -336,19 +333,6 @@ class DeltaFileSearchResult(BaseModel):
336333
"""A signature hash for backend validation."""
337334

338335

339-
class DeltaGoogleMapsCall(BaseModel):
340-
id: str
341-
"""A unique ID for this specific tool call."""
342-
343-
type: Literal["google_maps_call"]
344-
345-
arguments: Optional[GoogleMapsCallArguments] = None
346-
"""The arguments to pass to the Google Maps tool."""
347-
348-
signature: Optional[str] = None
349-
"""A signature hash for backend validation."""
350-
351-
352336
class DeltaGoogleMapsResult(BaseModel):
353337
call_id: str
354338
"""ID to match the ID from the function call block."""
@@ -372,18 +356,18 @@ class DeltaGoogleMapsResult(BaseModel):
372356
DeltaThoughtSummary,
373357
DeltaThoughtSignature,
374358
DeltaFunctionCall,
375-
DeltaFunctionResult,
376359
DeltaCodeExecutionCall,
377-
DeltaCodeExecutionResult,
378360
DeltaURLContextCall,
379-
DeltaURLContextResult,
380361
DeltaGoogleSearchCall,
381-
DeltaGoogleSearchResult,
382362
DeltaMCPServerToolCall,
383-
DeltaMCPServerToolResult,
384363
DeltaFileSearchCall,
385-
DeltaFileSearchResult,
386364
DeltaGoogleMapsCall,
365+
DeltaFunctionResult,
366+
DeltaCodeExecutionResult,
367+
DeltaURLContextResult,
368+
DeltaGoogleSearchResult,
369+
DeltaMCPServerToolResult,
370+
DeltaFileSearchResult,
387371
DeltaGoogleMapsResult,
388372
],
389373
PropertyInfo(discriminator="type"),
@@ -392,12 +376,14 @@ class DeltaGoogleMapsResult(BaseModel):
392376

393377
class ContentDelta(BaseModel):
394378
delta: Delta
379+
"""The delta content data for a content block."""
395380

396381
event_type: Literal["content.delta"]
397382

398383
index: int
399384

400385
event_id: Optional[str] = None
401386
"""
402-
The event_id token to be used to resume the interaction stream, from this event.
387+
The event_id token to be used to resume the interaction stream, from
388+
this event.
403389
"""

0 commit comments

Comments
 (0)