Gemini: Fix search tool is not supported when function tools are used

068c6bdccdab05ba6755d638f6fb96fb9ad0a289

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +7 -4Showing whitespace changes
src/endpoints/backends/chat-completions.js+7 -4
@@ -421,10 +421,6 @@ async function sendMakerSuiteRequest(request, response) {
421 const prompt = convertGooglePrompt(request.body.messages, model, useSystemPrompt, getPromptNames(request));421 const prompt = convertGooglePrompt(request.body.messages, model, useSystemPrompt, getPromptNames(request));
422 const safetySettings = [...GEMINI_SAFETY, ...(useVertexAi ? VERTEX_SAFETY : [])];422 const safetySettings = [...GEMINI_SAFETY, ...(useVertexAi ? VERTEX_SAFETY : [])];
423423
424 if (enableWebSearch && !enableImageModality && !isGemma && !isLearnLM && !noSearchModels.includes(model)) {
425 tools.push({ google_search: {} });
426 }
427
428 if (Array.isArray(request.body.tools) && request.body.tools.length > 0 && !enableImageModality && !isGemma) {424 if (Array.isArray(request.body.tools) && request.body.tools.length > 0 && !enableImageModality && !isGemma) {
429 const functionDeclarations = [];425 const functionDeclarations = [];
430 for (const tool of request.body.tools) {426 for (const tool of request.body.tools) {
@@ -445,6 +441,13 @@ async function sendMakerSuiteRequest(request, response) {
445 }441 }
446 }442 }
447443
444 if (enableWebSearch && !enableImageModality && !isGemma && !isLearnLM && !noSearchModels.includes(model)) {
445 // Tool use with function calling is unsupported
446 if (!tools.some(t => t.function_declarations)) {
447 tools.push({ google_search: {} });
448 }
449 }
450
448 if (isThinkingConfigModel(model)) {451 if (isThinkingConfigModel(model)) {
449 const thinkingConfig = { includeThoughts: includeReasoning };452 const thinkingConfig = { includeThoughts: includeReasoning };
450453