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
424424 if (Array.isArray(request.body.tools) && request.body.tools.length > 0 && !enableImageModality && !isGemma) {
425425 const functionDeclarations = [];
426+ const customTools = [];
426427 for (const tool of request.body.tools) {
427428 if (tool.type === 'function') {
428429 if (tool.function.parameters?.$schema) {
@@ -433,12 +434,16 @@ async function sendMakerSuiteRequest(request, response) {
433434 }
434435 functionDeclarations.push(tool.function);
435436 } else if (tool[tool.type]) {
436437 toolscustomTools.push({ [tool.type]: tool[tool.type] });
437438 }
438439 }
439440 if (functionDeclarations.length > 0) {
440441 tools.push({ function_declarations: functionDeclarations });
441442 }
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+ }
442447 }
443448
444449 if (enableWebSearch && !enableImageModality && !isGemma && !isLearnLM && !noSearchModels.includes(model)) {