Gemini: Fix search tool is not supported when function tools are used
| @@ -421,10 +421,6 @@ async function sendMakerSuiteRequest(request, response) { | ||
| 421 | 421 | const prompt = convertGooglePrompt(request.body.messages, model, useSystemPrompt, getPromptNames(request)); |
| 422 | 422 | const safetySettings = [...GEMINI_SAFETY, ...(useVertexAi ? VERTEX_SAFETY : [])]; |
| 423 | 423 | |
| 424 | - if (enableWebSearch && !enableImageModality && !isGemma && !isLearnLM && !noSearchModels.includes(model)) { | |
| 425 | - tools.push({ google_search: {} }); | |
| 426 | - } | |
| 427 | - | |
| 428 | 424 | if (Array.isArray(request.body.tools) && request.body.tools.length > 0 && !enableImageModality && !isGemma) { |
| 429 | 425 | const functionDeclarations = []; |
| 430 | 426 | for (const tool of request.body.tools) { |
| @@ -445,6 +441,13 @@ async function sendMakerSuiteRequest(request, response) { | ||
| 445 | 441 | } |
| 446 | 442 | } |
| 447 | 443 | |
| 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 | 451 | if (isThinkingConfigModel(model)) { |
| 449 | 452 | const thinkingConfig = { includeThoughts: includeReasoning }; |
| 450 | 453 | |