Skip to content

Commit b69d96e

Browse files
happy-qiaocopybara-github
authored andcommitted
chore: add httpOptions to LiveConnectConfig
httpOptions is not supported by live connections yet, so it raises an error. PiperOrigin-RevId: 738166931
1 parent efbcb52 commit b69d96e

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
@@ -9062,6 +9062,9 @@ class LiveClientMessageDict(TypedDict, total=False):
90629062
class LiveConnectConfig(_common.BaseModel):
90639063
"""Session config for the API connection."""
90649064

9065+
http_options: Optional[HttpOptions] = Field(
9066+
default=None, description="""Used to override HTTP request options."""
9067+
)
90659068
generation_config: Optional[GenerationConfig] = Field(
90669069
default=None,
90679070
description="""The generation configuration for the session.""",
@@ -9096,6 +9099,9 @@ class LiveConnectConfig(_common.BaseModel):
90969099
class LiveConnectConfigDict(TypedDict, total=False):
90979100
"""Session config for the API connection."""
90989101

9102+
http_options: Optional[HttpOptionsDict]
9103+
"""Used to override HTTP request options."""
9104+
90999105
generation_config: Optional[GenerationConfigDict]
91009106
"""The generation configuration for the session."""
91019107

0 commit comments

Comments
 (0)