diff --git a/livekit-plugins/livekit-plugins-google/livekit/plugins/google/llm.py b/livekit-plugins/livekit-plugins-google/livekit/plugins/google/llm.py index 0f3fdc5f5e..eb45f0dcdd 100644 --- a/livekit-plugins/livekit-plugins-google/livekit/plugins/google/llm.py +++ b/livekit-plugins/livekit-plugins-google/livekit/plugins/google/llm.py @@ -63,6 +63,7 @@ class _LLMOptions: gemini_tools: NotGivenOr[list[_LLMTool]] http_options: NotGivenOr[types.HttpOptions] seed: NotGivenOr[int] + safety_settings: NotGivenOr[list[types.SafetySettingOrDict] | dict[str, str]] class LLM(llm.LLM): @@ -88,6 +89,7 @@ def __init__( gemini_tools: NotGivenOr[list[_LLMTool]] = NOT_GIVEN, http_options: NotGivenOr[types.HttpOptions] = NOT_GIVEN, seed: NotGivenOr[int] = NOT_GIVEN, + safety_settings: NotGivenOr[list[types.SafetySettingOrDict] | dict[str, str]] = NOT_GIVEN, ) -> None: """ Create a new instance of Google GenAI LLM. @@ -116,6 +118,14 @@ def __init__( automatic_function_calling_config (AutomaticFunctionCallingConfigOrDict, optional): The automatic function calling configuration for response generation. Defaults to None. gemini_tools (list[LLMTool], optional): The Gemini-specific tools to use for the session. http_options (HttpOptions, optional): The HTTP options to use for the session. + seed (int, optional): Random seed for reproducible generation. Defaults to None. + safety_settings (list[SafetySettingOrDict] | dict[str, str], optional): Safety settings for content filtering. Defaults to None. + Can be specified as: + - Dict mapping harm categories to thresholds (e.g., {"HARM_CATEGORY_HATE_SPEECH": "BLOCK_LOW_AND_ABOVE"}) + - List of SafetySetting objects from google.genai.types + Available categories: HARM_CATEGORY_HARASSMENT, HARM_CATEGORY_HATE_SPEECH, HARM_CATEGORY_SEXUALLY_EXPLICIT, HARM_CATEGORY_DANGEROUS_CONTENT + Available thresholds: BLOCK_NONE, BLOCK_ONLY_HIGH, BLOCK_MEDIUM_AND_ABOVE, BLOCK_LOW_AND_ABOVE + """ # noqa: E501 super().__init__() gcp_project = project if is_given(project) else os.environ.get("GOOGLE_CLOUD_PROJECT") @@ -179,6 +189,7 @@ def __init__( gemini_tools=gemini_tools, http_options=http_options, seed=seed, + safety_settings=safety_settings, ) self._client = Client( api_key=gemini_api_key, @@ -286,6 +297,9 @@ def chat( if is_given(self._opts.automatic_function_calling_config): extra["automatic_function_calling"] = self._opts.automatic_function_calling_config + if is_given(self._opts.safety_settings): + extra["safety_settings"] = self._opts.safety_settings + gemini_tools = gemini_tools if is_given(gemini_tools) else self._opts.gemini_tools return LLMStream(