Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,16 @@ async def _run(self) -> None:
)
self._extra_kwargs.pop("tools", None)
self._extra_kwargs.pop("tool_config", None)
http_options = self._llm._opts.http_options or types.HttpOptions(
timeout=int(self._conn_options.timeout * 1000)
)
if not http_options.headers:
http_options.headers = {}
http_options.headers["x-goog-api-client"] = f"livekit-agents/{__version__}"
if is_given(self._llm._opts.http_options):
http_options = self._llm._opts.http_options.model_copy()
if http_options.timeout is None:
http_options.timeout = int(self._conn_options.timeout * 1000)
else:
http_options = types.HttpOptions(timeout=int(self._conn_options.timeout * 1000))

headers = dict(http_options.headers or {})
headers["x-goog-api-client"] = f"livekit-agents/{__version__}"
http_options.headers = headers
config = types.GenerateContentConfig(
system_instruction=(
None
Expand Down
29 changes: 29 additions & 0 deletions tests/test_plugin_google_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from livekit.agents import llm
from livekit.agents.llm import ChatContext, function_tool
from livekit.agents.types import APIConnectOptions
from livekit.plugins.google.llm import LLM, LLMStream
from livekit.plugins.google.realtime.realtime_api import RealtimeModel, RealtimeSession

Expand Down Expand Up @@ -243,6 +244,34 @@ async def example_tool(query: str) -> str:
assert config.system_instruction is not None
assert config.tools is not None and len(config.tools) >= 1

@pytest.mark.asyncio
async def test_request_merges_timeout_into_caller_http_options(self) -> None:
caller_http_options = types.HttpOptions(headers={"X-Vertex-Test": "1"})
llm = LLM(
model="gemini-2.5-flash",
api_key="test",
http_options=caller_http_options,
)

fake, captured = self._patched_stream_capture()
with patch.object(llm._client.aio.models, "generate_content_stream", fake):
stream = llm.chat(
chat_ctx=ChatContext.empty(),
conn_options=APIConnectOptions(timeout=7.5),
)
try:
async for _ in stream:
pass
finally:
await stream.aclose()

config = captured["config"]
assert config.http_options.timeout == 7500
assert config.http_options.headers["X-Vertex-Test"] == "1"
assert "livekit-agents/" in config.http_options.headers["x-goog-api-client"]
assert caller_http_options.timeout is None
assert caller_http_options.headers == {"X-Vertex-Test": "1"}


class TestMediaResolution:
def test_llm_media_resolution_is_passed_to_stream_kwargs(self):
Expand Down
Loading