Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add httpOptions to LiveConnectConfig #539

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions google/genai/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,10 @@ async def connect(
async for message in session.receive():
print(message)
"""
# TODO(b/404946806): Remove this check once httpOptions is supported.
if config and 'http_options' in config:
raise ValueError('http_options is not supported for live connect.')

base_url = self._api_client._websocket_base_url()
transformed_model = t.t_model(self._api_client, model)
# Ensure the config is a LiveConnectConfig.
Expand Down
32 changes: 24 additions & 8 deletions google/genai/tests/live/test_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,9 +899,9 @@ def test_parse_client_message_function_response(
api_client=mock_api_client(vertexai=vertexai), websocket=mock_websocket
)
input = types.FunctionResponse(
id='test_id',
name='test_name',
response={'result': 'test_response'},
id='test_id',
name='test_name',
response={'result': 'test_response'},
)
result = session._parse_client_message(input)
assert 'tool_response' in result
Expand All @@ -928,11 +928,11 @@ def test_parse_client_message_tool_response_dict_with_only_response(
api_client=mock_api_client(vertexai=vertexai), websocket=mock_websocket
)
input = {
'id': 'test_id',
'name': 'test_name',
'response': {
'result': 'test_response',
}
'id': 'test_id',
'name': 'test_name',
'response': {
'result': 'test_response',
},
}
result = session._parse_client_message(input)
assert 'tool_response' in result
Expand Down Expand Up @@ -985,3 +985,19 @@ def test_parse_client_message_realtime_tool_response(
],
}
}


@pytest.mark.asyncio
async def test_connect_with_http_options_throws_error(
mock_api_client, mock_websocket
):
with pytest.raises(ValueError, match='http_options is not supported'):
await live.AsyncLive(mock_api_client()).connect(
model='models/gemini-pro',
config=types.LiveConnectConfig(http_options={'proxy': 'test-proxy'}),
)
with pytest.raises(ValueError, match='http_options is not supported'):
await live.AsyncLive(mock_api_client()).connect(
model='models/gemini-pro',
config=types.LiveConnectConfig({'http_options': {'proxy': 'test-proxy'}}),
)
6 changes: 6 additions & 0 deletions google/genai/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9162,6 +9162,9 @@ class LiveClientMessageDict(TypedDict, total=False):
class LiveConnectConfig(_common.BaseModel):
"""Session config for the API connection."""

http_options: Optional[HttpOptions] = Field(
default=None, description="""Used to override HTTP request options."""
)
generation_config: Optional[GenerationConfig] = Field(
default=None,
description="""The generation configuration for the session.""",
Expand Down Expand Up @@ -9196,6 +9199,9 @@ class LiveConnectConfig(_common.BaseModel):
class LiveConnectConfigDict(TypedDict, total=False):
"""Session config for the API connection."""

http_options: Optional[HttpOptionsDict]
"""Used to override HTTP request options."""

generation_config: Optional[GenerationConfigDict]
"""The generation configuration for the session."""

Expand Down