Gemini: Only register custom tools when there are no function tools

3b59eae7c0a87f95368ee5da0e87f48b5837a461

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

1 files changed, +6 -1Ignore whitespace
src/endpoints/backends/chat-completions.js+6 -1
@@ -423,6 +423,7 @@ async function sendMakerSuiteRequest(request, response) {
423423
424 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) {
425 const functionDeclarations = [];425 const functionDeclarations = [];
426 const customTools = [];
426 for (const tool of request.body.tools) {427 for (const tool of request.body.tools) {
427 if (tool.type === 'function') {428 if (tool.type === 'function') {
428 if (tool.function.parameters?.$schema) {429 if (tool.function.parameters?.$schema) {
@@ -433,12 +434,16 @@ async function sendMakerSuiteRequest(request, response) {
433 }434 }
434 functionDeclarations.push(tool.function);435 functionDeclarations.push(tool.function);
435 } else if (tool[tool.type]) {436 } else if (tool[tool.type]) {
436 tools.push({ [tool.type]: tool[tool.type] });437 customTools.push({ [tool.type]: tool[tool.type] });
437 }438 }
438 }439 }
439 if (functionDeclarations.length > 0) {440 if (functionDeclarations.length > 0) {
440 tools.push({ function_declarations: functionDeclarations });441 tools.push({ function_declarations: functionDeclarations });
441 }442 }
443 // Custom tools are only supported when no function calling is present
444 if (functionDeclarations.length === 0 && customTools.length > 0) {
445 tools.push(...customTools);
446 }
442 }447 }
443448
444 if (enableWebSearch && !enableImageModality && !isGemma && !isLearnLM && !noSearchModels.includes(model)) {449 if (enableWebSearch && !enableImageModality && !isGemma && !isLearnLM && !noSearchModels.includes(model)) {