Skip to content

Commit 6869eac

Browse files
yinghsienwucopybara-github
authored andcommitted
feat: support Blocking FunctionCall in Live API in AgentPlatform (Vertex)
PiperOrigin-RevId: 912037899
1 parent 00d76d1 commit 6869eac

5 files changed

Lines changed: 12 additions & 144 deletions

File tree

google/genai/_live_converters.py

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -167,46 +167,6 @@ def _FunctionCall_to_mldev(
167167
return to_object
168168

169169

170-
def _FunctionDeclaration_to_vertex(
171-
from_object: Union[dict[str, Any], object],
172-
parent_object: Optional[dict[str, Any]] = None,
173-
) -> dict[str, Any]:
174-
to_object: dict[str, Any] = {}
175-
if getv(from_object, ['description']) is not None:
176-
setv(to_object, ['description'], getv(from_object, ['description']))
177-
178-
if getv(from_object, ['name']) is not None:
179-
setv(to_object, ['name'], getv(from_object, ['name']))
180-
181-
if getv(from_object, ['parameters']) is not None:
182-
setv(to_object, ['parameters'], getv(from_object, ['parameters']))
183-
184-
if getv(from_object, ['parameters_json_schema']) is not None:
185-
setv(
186-
to_object,
187-
['parametersJsonSchema'],
188-
getv(from_object, ['parameters_json_schema']),
189-
)
190-
191-
if getv(from_object, ['response']) is not None:
192-
setv(to_object, ['response'], getv(from_object, ['response']))
193-
194-
if getv(from_object, ['response_json_schema']) is not None:
195-
setv(
196-
to_object,
197-
['responseJsonSchema'],
198-
getv(from_object, ['response_json_schema']),
199-
)
200-
201-
if getv(from_object, ['behavior']) is not None:
202-
raise ValueError(
203-
'behavior parameter is not supported in Gemini Enterprise Agent'
204-
' Platform.'
205-
)
206-
207-
return to_object
208-
209-
210170
def _GenerationConfig_to_vertex(
211171
from_object: Union[dict[str, Any], object],
212172
parent_object: Optional[dict[str, Any]] = None,
@@ -1854,10 +1814,7 @@ def _Tool_to_vertex(
18541814
setv(
18551815
to_object,
18561816
['functionDeclarations'],
1857-
[
1858-
_FunctionDeclaration_to_vertex(item, to_object)
1859-
for item in getv(from_object, ['function_declarations'])
1860-
],
1817+
[item for item in getv(from_object, ['function_declarations'])],
18611818
)
18621819

18631820
if getv(from_object, ['google_search_retrieval']) is not None:

google/genai/caches.py

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -407,46 +407,6 @@ def _FunctionCallingConfig_to_mldev(
407407
return to_object
408408

409409

410-
def _FunctionDeclaration_to_vertex(
411-
from_object: Union[dict[str, Any], object],
412-
parent_object: Optional[dict[str, Any]] = None,
413-
) -> dict[str, Any]:
414-
to_object: dict[str, Any] = {}
415-
if getv(from_object, ['description']) is not None:
416-
setv(to_object, ['description'], getv(from_object, ['description']))
417-
418-
if getv(from_object, ['name']) is not None:
419-
setv(to_object, ['name'], getv(from_object, ['name']))
420-
421-
if getv(from_object, ['parameters']) is not None:
422-
setv(to_object, ['parameters'], getv(from_object, ['parameters']))
423-
424-
if getv(from_object, ['parameters_json_schema']) is not None:
425-
setv(
426-
to_object,
427-
['parametersJsonSchema'],
428-
getv(from_object, ['parameters_json_schema']),
429-
)
430-
431-
if getv(from_object, ['response']) is not None:
432-
setv(to_object, ['response'], getv(from_object, ['response']))
433-
434-
if getv(from_object, ['response_json_schema']) is not None:
435-
setv(
436-
to_object,
437-
['responseJsonSchema'],
438-
getv(from_object, ['response_json_schema']),
439-
)
440-
441-
if getv(from_object, ['behavior']) is not None:
442-
raise ValueError(
443-
'behavior parameter is not supported in Gemini Enterprise Agent'
444-
' Platform.'
445-
)
446-
447-
return to_object
448-
449-
450410
def _GetCachedContentParameters_to_mldev(
451411
api_client: BaseApiClient,
452412
from_object: Union[dict[str, Any], object],
@@ -944,10 +904,7 @@ def _Tool_to_vertex(
944904
setv(
945905
to_object,
946906
['functionDeclarations'],
947-
[
948-
_FunctionDeclaration_to_vertex(item, to_object)
949-
for item in getv(from_object, ['function_declarations'])
950-
],
907+
[item for item in getv(from_object, ['function_declarations'])],
951908
)
952909

953910
if getv(from_object, ['google_search_retrieval']) is not None:

google/genai/models.py

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,47 +1135,6 @@ def _FunctionCallingConfig_to_mldev(
11351135
return to_object
11361136

11371137

1138-
def _FunctionDeclaration_to_vertex(
1139-
from_object: Union[dict[str, Any], object],
1140-
parent_object: Optional[dict[str, Any]] = None,
1141-
root_object: Optional[Union[dict[str, Any], object]] = None,
1142-
) -> dict[str, Any]:
1143-
to_object: dict[str, Any] = {}
1144-
if getv(from_object, ['description']) is not None:
1145-
setv(to_object, ['description'], getv(from_object, ['description']))
1146-
1147-
if getv(from_object, ['name']) is not None:
1148-
setv(to_object, ['name'], getv(from_object, ['name']))
1149-
1150-
if getv(from_object, ['parameters']) is not None:
1151-
setv(to_object, ['parameters'], getv(from_object, ['parameters']))
1152-
1153-
if getv(from_object, ['parameters_json_schema']) is not None:
1154-
setv(
1155-
to_object,
1156-
['parametersJsonSchema'],
1157-
getv(from_object, ['parameters_json_schema']),
1158-
)
1159-
1160-
if getv(from_object, ['response']) is not None:
1161-
setv(to_object, ['response'], getv(from_object, ['response']))
1162-
1163-
if getv(from_object, ['response_json_schema']) is not None:
1164-
setv(
1165-
to_object,
1166-
['responseJsonSchema'],
1167-
getv(from_object, ['response_json_schema']),
1168-
)
1169-
1170-
if getv(from_object, ['behavior']) is not None:
1171-
raise ValueError(
1172-
'behavior parameter is not supported in Gemini Enterprise Agent'
1173-
' Platform.'
1174-
)
1175-
1176-
return to_object
1177-
1178-
11791138
def _GenerateContentConfig_to_mldev(
11801139
api_client: BaseApiClient,
11811140
from_object: Union[dict[str, Any], object],
@@ -4252,10 +4211,7 @@ def _Tool_to_vertex(
42524211
setv(
42534212
to_object,
42544213
['functionDeclarations'],
4255-
[
4256-
_FunctionDeclaration_to_vertex(item, to_object, root_object)
4257-
for item in getv(from_object, ['function_declarations'])
4258-
],
4214+
[item for item in getv(from_object, ['function_declarations'])],
42594215
)
42604216

42614217
if getv(from_object, ['google_search_retrieval']) is not None:

google/genai/tests/live/test_live.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,12 +1193,9 @@ async def test_bidi_setup_to_api_with_tools_function_behavior(vertexai):
11931193
}
11941194
config = types.LiveConnectConfig(**config_dict)
11951195

1196-
with pytest_helper.exception_if_vertex(api_client, ValueError):
1197-
result = await get_connect_message(
1198-
mock_api_client(vertexai=vertexai), model='test_model', config=config
1199-
)
1200-
if vertexai:
1201-
return
1196+
result = await get_connect_message(
1197+
mock_api_client(vertexai=vertexai), model='test_model', config=config
1198+
)
12021199

12031200
assert (
12041201
result['setup']['tools'][0]['functionDeclarations'][0]['behavior']

google/genai/types.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,13 @@ class PhishBlockThreshold(_common.CaseInSensitiveEnum):
277277
class Behavior(_common.CaseInSensitiveEnum):
278278
"""Specifies the function Behavior.
279279

280-
Currently only supported by the BidiGenerateContent method. This enum is not
281-
supported in Vertex AI.
280+
Currently only non-blocking functions are supported. If not specified, the
281+
system keeps the current function call behavior. This field is currently only
282+
supported by the BidiGenerateContent method.
282283
"""
283284

284285
UNSPECIFIED = 'UNSPECIFIED'
285-
"""This value is unused."""
286+
"""This value is unspecified."""
286287
BLOCKING = 'BLOCKING'
287288
"""If set, the system will wait to receive the function response before continuing the conversation."""
288289
NON_BLOCKING = 'NON_BLOCKING'
@@ -4392,7 +4393,7 @@ class FunctionDeclaration(_common.BaseModel):
43924393
)
43934394
behavior: Optional[Behavior] = Field(
43944395
default=None,
4395-
description="""Optional. Specifies the function Behavior. Currently only supported by the BidiGenerateContent method. This field is not supported in Vertex AI.""",
4396+
description="""Optional. Specifies the function Behavior. Currently only non-blocking functions are supported. If not specified, the system keeps the current function call behavior. This field is currently only supported by the BidiGenerateContent method.""",
43964397
)
43974398

43984399
@classmethod
@@ -4615,7 +4616,7 @@ class FunctionDeclarationDict(TypedDict, total=False):
46154616
"""Optional. Describes the output from this function in JSON Schema format. The value specified by the schema is the response value of the function. This field is mutually exclusive with `response`."""
46164617

46174618
behavior: Optional[Behavior]
4618-
"""Optional. Specifies the function Behavior. Currently only supported by the BidiGenerateContent method. This field is not supported in Vertex AI."""
4619+
"""Optional. Specifies the function Behavior. Currently only non-blocking functions are supported. If not specified, the system keeps the current function call behavior. This field is currently only supported by the BidiGenerateContent method."""
46194620

46204621

46214622
FunctionDeclarationOrDict = Union[FunctionDeclaration, FunctionDeclarationDict]

0 commit comments

Comments
 (0)