From 31b0d212624a3e925d4f346922ad00d15b9967ed Mon Sep 17 00:00:00 2001 From: Paul Aubry Date: Fri, 5 Jun 2026 13:00:14 +0200 Subject: [PATCH 1/2] Fixed tool config and removed tool combination setter --- src/code.gs | 69 +++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/src/code.gs b/src/code.gs index 34ebe74..955e424 100644 --- a/src/code.gs +++ b/src/code.gs @@ -54,7 +54,6 @@ const GenAIApp = (function () { let knowledgeLink = []; let compaction_enabled = false; let compaction_threshold = 10000; - let tool_combination_enabled = false; let previous_response_id; let last_response_id = null; @@ -296,18 +295,6 @@ const GenAIApp = (function () { return this; }; - /** - * OPTIONAL - * - * Enable or disable server-side tool invocations for Gemini (Tool Combination). - * @param {boolean} enabled - True to enable tool combination. - * @returns {Chat} - The current Chat instance. - */ - this.enableToolCombination = function (enabled) { - tool_combination_enabled = enabled; - return this; - }; - /** * Includes the content of a web page in the prompt sent to openAI * @param {string} url - the url of the webpage you want to fetch @@ -742,40 +729,27 @@ const GenAIApp = (function () { } /** - * Builds and returns a payload for a Gemini API call, configuring content, model parameters, - * and tool settings based on advanced options and feature flags such as browsing. + * Builds and returns a payload for a Gemini API call, configuring content, model parameters, + * and tool settings based on advanced options and feature flags such as browsing. * Adapts the payload for specific function calls and tools. * * @private - * @param {Object} advancedParametersObject - An object with optional advanced parameters, + * @param {Object} advancedParametersObject - An object with optional advanced parameters, * such as function call preferences. - * @returns {Object} - The configured payload object for the Gemini API, including content, model settings, + * @returns {Object} - The configured payload object for the Gemini API, including content, model settings, * generation configuration, and available tools. - * @throws {Error} If an incompatible feature is selected (e.g., assistant usage with the Gemini model). + * @throws {Error} If an incompatible feature is selected. */ this._buildGeminiPayload = function (advancedParametersObject) { const payload = { - 'contents': contents, - 'model': model, - 'generationConfig': { + contents: contents, + model: model, + generationConfig: { maxOutputTokens: max_tokens, temperature: temperature, - }, - 'tool_config': { - function_calling_config: { - mode: "AUTO" - }, - includeServerSideToolInvocations: tool_combination_enabled - }, - tools: [] + } }; - if (advancedParametersObject?.function_call) { - payload.tool_config.function_calling_config.mode = "ANY"; - payload.tool_config.function_calling_config.allowed_function_names = advancedParametersObject.function_call; - delete advancedParametersObject.function_call; - } - if (tools.length > 0) { // the user has added functions, enable function calling const payloadTools = Object.keys(tools).map(t => { @@ -796,19 +770,42 @@ const GenAIApp = (function () { payload.tools = [{ functionDeclarations: payloadTools }]; + + payload.tool_config = { + function_calling_config: { + mode: "AUTO" + } + }; + + if (advancedParametersObject?.function_call) { + payload.tool_config.function_calling_config.mode = "ANY"; + payload.tool_config.function_calling_config.allowed_function_names = + advancedParametersObject.function_call; + + delete advancedParametersObject.function_call; + } } if (browsing) { + if (tools.length > 0) { + payload.tool_config.includeServerSideToolInvocations = true; + } + + if (!payload.tools) { + payload.tools = []; + } + payload.tools.push({ url_context: {} }); + payload.tools.push({ google_search: {} }); } return payload; - } + }; /** * Get a blob from a Google Drive file ID From ea8fc74b165077e371de28f7494ef7dfc00442b7 Mon Sep 17 00:00:00 2001 From: Paul Aubry Date: Tue, 9 Jun 2026 10:10:39 +0200 Subject: [PATCH 2/2] fixed bracket error --- src/code.gs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/code.gs b/src/code.gs index ea0722f..4b5712b 100644 --- a/src/code.gs +++ b/src/code.gs @@ -319,6 +319,7 @@ const GenAIApp = (function () { if (containerId) { this._codeInterpreterContainerId = containerId; } + }; /** * Includes the content of a web page in the prompt sent to openAI