Skip to content

Commit

Permalink
google-genai version bump (#1480)
Browse files Browse the repository at this point in the history
  • Loading branch information
jayeshp19 authored Feb 27, 2025
1 parent 1eafe7f commit 38ae694
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
from livekit.agents.llm.function_context import _is_optional_type

from google.genai import types

JSON_SCHEMA_TYPE_MAP: dict[type, types.Type] = {
str: "STRING",
int: "INTEGER",
float: "NUMBER",
bool: "BOOLEAN",
dict: "OBJECT",
list: "ARRAY",
from google.genai.types import Type as GenaiType

JSON_SCHEMA_TYPE_MAP: dict[type, GenaiType] = {
str: GenaiType.STRING,
int: GenaiType.INTEGER,
float: GenaiType.NUMBER,
bool: GenaiType.BOOLEAN,
dict: GenaiType.OBJECT,
list: GenaiType.ARRAY,
}

__all__ = ["_build_gemini_ctx", "_build_tools"]
Expand All @@ -38,7 +39,7 @@ def _build_parameters(arguments: Dict[str, Any]) -> types.Schema | None:
item_type = get_args(py_type)[0]
if item_type not in JSON_SCHEMA_TYPE_MAP:
raise ValueError(f"Unsupported type: {item_type}")
prop.type = "ARRAY"
prop.type = GenaiType.ARRAY
prop.items = types.Schema(type=JSON_SCHEMA_TYPE_MAP[item_type])

if arg_info.choices:
Expand All @@ -62,7 +63,7 @@ def _build_parameters(arguments: Dict[str, Any]) -> types.Schema | None:
required.append(arg_name)

if properties:
parameters = types.Schema(type="OBJECT", properties=properties)
parameters = types.Schema(type=GenaiType.OBJECT, properties=properties)
if required:
parameters.required = required

Expand Down Expand Up @@ -119,7 +120,6 @@ def _build_gemini_ctx(
parts.append(
types.Part(
function_call=types.FunctionCall(
id=fnc.tool_call_id,
name=fnc.function_info.name,
args=fnc.arguments,
)
Expand All @@ -132,7 +132,6 @@ def _build_gemini_ctx(
parts.append(
types.Part(
function_response=types.FunctionResponse(
id=msg.tool_call_id,
name=msg.name,
response=msg.content,
)
Expand All @@ -142,7 +141,6 @@ def _build_gemini_ctx(
parts.append(
types.Part(
function_response=types.FunctionResponse(
id=msg.tool_call_id,
name=msg.name,
response={"result": msg.content},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
from livekit.agents.llm.function_context import _create_ai_function_info

from google import genai
from google.genai._api_client import HttpOptions
from google.genai.types import (
Blob,
Content,
FunctionResponse,
GenerationConfig,
HttpOptions,
LiveClientContent,
LiveClientRealtimeInput,
LiveClientToolResponse,
Expand Down Expand Up @@ -107,7 +107,7 @@ def __init__(
model: LiveAPIModels | str = "gemini-2.0-flash-exp",
api_key: str | None = None,
voice: Voice | str = "Puck",
modalities: list[Modality] = ["AUDIO"],
modalities: list[Modality] = [Modality.AUDIO],
enable_user_audio_transcription: bool = True,
enable_agent_audio_transcription: bool = True,
vertexai: bool = False,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, *, client: genai.Client, model: LiveAPIModels | str):
parts=[types.Part(text=SYSTEM_INSTRUCTIONS)]
)
self._config = types.LiveConnectConfig(
response_modalities=["TEXT"],
response_modalities=[types.Modality.TEXT],
system_instruction=system_instructions,
generation_config=types.GenerationConfig(temperature=0.0),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,15 @@ async def _run(self) -> None:
# specific function
tool_config = types.ToolConfig(
function_calling_config=types.FunctionCallingConfig(
mode="ANY",
mode=types.FunctionCallingConfigMode.ANY,
allowed_function_names=[self._tool_choice.name],
)
)
elif self._tool_choice == "required":
# model must call any function
tool_config = types.ToolConfig(
function_calling_config=types.FunctionCallingConfig(
mode="ANY",
mode=types.FunctionCallingConfigMode.ANY,
allowed_function_names=[
fnc.name
for fnc in self._fnc_ctx.ai_functions.values()
Expand All @@ -259,14 +259,14 @@ async def _run(self) -> None:
# model can call any function
tool_config = types.ToolConfig(
function_calling_config=types.FunctionCallingConfig(
mode="AUTO"
mode=types.FunctionCallingConfigMode.AUTO
)
)
elif self._tool_choice == "none":
# model cannot call any function
tool_config = types.ToolConfig(
function_calling_config=types.FunctionCallingConfig(
mode="NONE",
mode=types.FunctionCallingConfigMode.NONE,
)
)
opts["tool_config"] = tool_config
Expand All @@ -282,11 +282,12 @@ async def _run(self) -> None:
system_instruction=system_instruction,
**opts,
)
async for response in self._client.aio.models.generate_content_stream(
stream = await self._client.aio.models.generate_content_stream(
model=self._model,
contents=cast(types.ContentListUnion, turns),
config=config,
):
)
async for response in stream: # type: ignore
if response.prompt_feedback:
raise APIStatusError(
response.prompt_feedback.json(),
Expand Down
2 changes: 1 addition & 1 deletion livekit-plugins/livekit-plugins-google/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"google-auth >= 2, < 3",
"google-cloud-speech >= 2, < 3",
"google-cloud-texttospeech >= 2, < 3",
"google-genai == 0.5.0",
"google-genai == 1.3.0",
"livekit-agents>=0.12.11",
],
package_data={"livekit.plugins.google": ["py.typed"]},
Expand Down

0 comments on commit 38ae694

Please sign in to comment.