From 5d5377332ce889cb137e0fd3733e583d39f34d66 Mon Sep 17 00:00:00 2001 From: Dreaming Computers Date: Fri, 30 Jan 2026 14:30:32 +0700 Subject: [PATCH] feat: add google search toggle for gemini --- README.md | 2 +- kie_api/gemini3_pro_llm.py | 30 ++++-------------------------- nodes.py | 10 +++++----- web/docs/KIE_Gemini3Pro_LLM.md | 6 +++--- 4 files changed, 13 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 73d5a37..5803213 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ This node pack currently includes the following nodes: - **Gemini 3 Pro (LLM) [Experimental]** - Text generation node using Gemini 3 Pro chat completions. - - Supports role selection, media inputs (images/video/audio), optional reasoning output, and JSON payload inputs. + - Supports role selection, media inputs (images/video/audio), optional reasoning output, and Google Search toggle. - **Kling 2.6 Image-to-Video** - Generates video from a single input image. diff --git a/kie_api/gemini3_pro_llm.py b/kie_api/gemini3_pro_llm.py index 7bc1b7b..f11ea8b 100644 --- a/kie_api/gemini3_pro_llm.py +++ b/kie_api/gemini3_pro_llm.py @@ -63,26 +63,6 @@ def _normalize_messages( ] -def _validate_tools_payload(tools_payload: Any | None) -> None: - if tools_payload is None: - return - if not isinstance(tools_payload, list): - raise RuntimeError("tools_json must be a JSON array.") - - tool_names = [] - for item in tools_payload: - if not isinstance(item, dict): - raise RuntimeError("tools_json must be a JSON array of objects.") - fn = (item.get("function") or {}) - if isinstance(fn, dict): - name = fn.get("name") - if isinstance(name, str): - tool_names.append(name) - - if "googleSearch" in tool_names and len(tool_names) > 1: - raise RuntimeError("googleSearch cannot be combined with other tools.") - - def run_gemini3_pro_chat( *, prompt: str, @@ -94,7 +74,7 @@ def run_gemini3_pro_chat( stream: bool = True, include_thoughts: bool = True, reasoning_effort: str = "high", - tools_json: str | None = None, + enable_google_search: bool = False, response_format_json: str | None = None, log: bool = True, ) -> tuple[str, str, str]: @@ -106,11 +86,9 @@ def run_gemini3_pro_chat( if reasoning_effort not in REASONING_EFFORT_OPTIONS: raise RuntimeError("Invalid reasoning_effort. Use the pinned enum options.") - tools_payload = _parse_json_optional(tools_json, "tools_json") response_format_payload = _parse_json_optional(response_format_json, "response_format_json") - if tools_payload is not None and response_format_payload is not None: + if enable_google_search and response_format_payload is not None: raise RuntimeError("response_format cannot be used with tools.") - _validate_tools_payload(tools_payload) api_key = _load_api_key() headers = { @@ -168,8 +146,8 @@ def run_gemini3_pro_chat( "include_thoughts": bool(include_thoughts), "reasoning_effort": reasoning_effort, } - if tools_payload is not None: - payload["tools"] = tools_payload + if enable_google_search: + payload["tools"] = [{"type": "function", "function": {"name": "googleSearch"}}] if response_format_payload is not None: payload["response_format"] = response_format_payload diff --git a/nodes.py b/nodes.py index 151ecd0..01e9bf8 100644 --- a/nodes.py +++ b/nodes.py @@ -649,8 +649,8 @@ Inputs: - stream: Stream responses (SSE); output is returned after completion - include_thoughts: Include reasoning content in output - reasoning_effort: low or high -- tools_json: Optional JSON array of tool definitions (mutually exclusive with response_format_json) -- response_format_json: Optional JSON schema output format (mutually exclusive with tools_json) +- enable_google_search: Enable the Google Search tool (mutually exclusive with response_format_json) +- response_format_json: Optional JSON schema output format (mutually exclusive with Google Search) - log: Console logging on/off Outputs: @@ -674,7 +674,7 @@ Outputs: "stream": ("BOOLEAN", {"default": True}), "include_thoughts": ("BOOLEAN", {"default": True}), "reasoning_effort": ("COMBO", {"options": GEMINI3_REASONING_EFFORT_OPTIONS, "default": "high"}), - "tools_json": ("STRING", {"multiline": True, "default": ""}), + "enable_google_search": ("BOOLEAN", {"default": False}), "response_format_json": ("STRING", {"multiline": True, "default": ""}), "log": ("BOOLEAN", {"default": True}), }, @@ -696,7 +696,7 @@ Outputs: stream: bool = True, include_thoughts: bool = True, reasoning_effort: str = "high", - tools_json: str = "", + enable_google_search: bool = False, response_format_json: str = "", log: bool = True, ): @@ -710,7 +710,7 @@ Outputs: stream=stream, include_thoughts=include_thoughts, reasoning_effort=reasoning_effort, - tools_json=tools_json, + enable_google_search=enable_google_search, response_format_json=response_format_json, log=log, ) diff --git a/web/docs/KIE_Gemini3Pro_LLM.md b/web/docs/KIE_Gemini3Pro_LLM.md index 9f57dc4..7d7c30f 100644 --- a/web/docs/KIE_Gemini3Pro_LLM.md +++ b/web/docs/KIE_Gemini3Pro_LLM.md @@ -12,7 +12,7 @@ Generate text using Gemini 3 Pro. This node is experimental. - **stream** (BOOLEAN, optional): Use streaming responses (SSE). Output is returned after completion. - **include_thoughts** (BOOLEAN, optional): When enabled, reasoning content is returned in the reasoning output. - **reasoning_effort** (COMBO, optional): Controls reasoning depth: `low` or `high`. -- **tools_json** (STRING, optional): JSON array of tool definitions. Mutually exclusive with `response_format_json`. +- **enable_google_search** (BOOLEAN, optional): Enable the Google Search tool. Mutually exclusive with `response_format_json`. - **response_format_json** (STRING, optional): JSON schema output format. Mutually exclusive with `tools_json`. - **log** (BOOLEAN, optional): Enable console logging for uploads and response status. @@ -26,7 +26,7 @@ Generate text using Gemini 3 Pro. This node is experimental. - **Stream (toggle)**: Enables SSE streaming under the hood; output still returns when complete. - **Include Thoughts (toggle)**: When on, reasoning text is captured and returned in the second output. - **Reasoning Effort (dropdown)**: `low` is faster, `high` is more thorough. -- **Tools JSON (text box)**: Raw JSON array of tool definitions (advanced). +- **Enable Google Search (toggle)**: Sends the Google Search tool payload to the API. - **Response Format JSON (text box)**: Raw JSON schema definition (advanced). - **Log (toggle)**: Emits upload and completion messages to the console. @@ -37,6 +37,6 @@ Generate text using Gemini 3 Pro. This node is experimental. ## Helper behavior - Validates `reasoning_effort`. -- Enforces mutual exclusivity for tools vs response_format. +- Enforces mutual exclusivity for Google Search vs response_format. - If `messages_json` is provided, it is used as the message array and media inputs are rejected. - Media inputs are uploaded and added to the message content using the unified `image_url` format.