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

068c6bdccdab05ba6755d638f6fb96fb9ad0a289

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

1 files changed, +7 -4Ignore whitespace
src/endpoints/backends/chat-completions.js+7 -4
@@ -421,10 +421,6 @@ async function sendMakerSuiteRequest(request, response) {
421421 const prompt = convertGooglePrompt(request.body.messages, model, useSystemPrompt, getPromptNames(request));
422422 const safetySettings = [...GEMINI_SAFETY, ...(useVertexAi ? VERTEX_SAFETY : [])];
423423
424- if (enableWebSearch && !enableImageModality && !isGemma && !isLearnLM && !noSearchModels.includes(model)) {
425- tools.push({ google_search: {} });
426- }
427-
428424 if (Array.isArray(request.body.tools) && request.body.tools.length > 0 && !enableImageModality && !isGemma) {
429425 const functionDeclarations = [];
430426 for (const tool of request.body.tools) {
@@ -445,6 +441,13 @@ async function sendMakerSuiteRequest(request, response) {
445441 }
446442 }
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+
448451 if (isThinkingConfigModel(model)) {
449452 const thinkingConfig = { includeThoughts: includeReasoning };
450453