Skip to content

Commit ece6787

Browse files
happy-qiaocopybara-github
authored andcommitted
chore: add httpOptions to LiveConnectConfig
PiperOrigin-RevId: 738166931
1 parent 122cdc8 commit ece6787

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

google/genai/live.py

+4
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,10 @@ async def connect(
849849
async for message in session.receive():
850850
print(message)
851851
"""
852+
# TODO(b/404946806): Remove this check once httpOptions is supported.
853+
if config and 'http_options' in config:
854+
raise ValueError('http_options is not supported for live connect.')
855+
852856
base_url = self._api_client._websocket_base_url()
853857
transformed_model = t.t_model(self._api_client, model)
854858
# Ensure the config is a LiveConnectConfig.

google/genai/tests/live/test_live.py

+24-8
Original file line numberDiff line numberDiff line change
@@ -899,9 +899,9 @@ def test_parse_client_message_function_response(
899899
api_client=mock_api_client(vertexai=vertexai), websocket=mock_websocket
900900
)
901901
input = types.FunctionResponse(
902-
id='test_id',
903-
name='test_name',
904-
response={'result': 'test_response'},
902+
id='test_id',
903+
name='test_name',
904+
response={'result': 'test_response'},
905905
)
906906
result = session._parse_client_message(input)
907907
assert 'tool_response' in result
@@ -928,11 +928,11 @@ def test_parse_client_message_tool_response_dict_with_only_response(
928928
api_client=mock_api_client(vertexai=vertexai), websocket=mock_websocket
929929
)
930930
input = {
931-
'id': 'test_id',
932-
'name': 'test_name',
933-
'response': {
934-
'result': 'test_response',
935-
}
931+
'id': 'test_id',
932+
'name': 'test_name',
933+
'response': {
934+
'result': 'test_response',
935+
},
936936
}
937937
result = session._parse_client_message(input)
938938
assert 'tool_response' in result
@@ -985,3 +985,19 @@ def test_parse_client_message_realtime_tool_response(
985985
],
986986
}
987987
}
988+
989+
990+
@pytest.mark.asyncio
991+
async def test_connect_with_http_options_throws_error(
992+
mock_api_client, mock_websocket
993+
):
994+
with pytest.raises(ValueError, match='http_options is not supported'):
995+
await live.AsyncLive(mock_api_client()).connect(
996+
model='models/gemini-pro',
997+
config=types.LiveConnectConfig(http_options={'proxy': 'test-proxy'}),
998+
)
999+
with pytest.raises(ValueError, match='http_options is not supported'):
1000+
await live.AsyncLive(mock_api_client()).connect(
1001+
model='models/gemini-pro',
1002+
config=types.LiveConnectConfig({'http_options': {'proxy': 'test-proxy'}}),
1003+
)

google/genai/types.py

+6
Original file line numberDiff line numberDiff line change
@@ -9129,6 +9129,9 @@ class LiveClientMessageDict(TypedDict, total=False):
91299129
class LiveConnectConfig(_common.BaseModel):
91309130
"""Session config for the API connection."""
91319131

9132+
http_options: Optional[HttpOptions] = Field(
9133+
default=None, description="""Used to override HTTP request options."""
9134+
)
91329135
generation_config: Optional[GenerationConfig] = Field(
91339136
default=None,
91349137
description="""The generation configuration for the session.""",
@@ -9163,6 +9166,9 @@ class LiveConnectConfig(_common.BaseModel):
91639166
class LiveConnectConfigDict(TypedDict, total=False):
91649167
"""Session config for the API connection."""
91659168

9169+
http_options: Optional[HttpOptionsDict]
9170+
"""Used to override HTTP request options."""
9171+
91669172
generation_config: Optional[GenerationConfigDict]
91679173
"""The generation configuration for the session."""
91689174

0 commit comments

Comments
 (0)