Convert OAI tool_choice to Gemini functionCallingConfig for Gemini requests (#4840) * Send toolConfig block to Gemini, if defined and tools block also present. * Convert OAI tool_choice to Gemini functionCallingConfig for Gemini requests * Remove blank line --------- Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>

1f780943227ddb45ef7e855de9adb4dd8f136ec5

mightytribble <246552901+mightytribble@users.noreply.github.com>

Signed
1 files changed, +28 -0Ignore whitespace
src/endpoints/backends/chat-completions.js+28 -0
@@ -495,6 +495,34 @@ async function sendMakerSuiteRequest(request, response) {
495495
496 if (tools.length) {496 if (tools.length) {
497 body.tools = tools;497 body.tools = tools;
498
499 const toolChoice = request.body.tool_choice;
500 let functionCallingConfig;
501
502 // Translate OpenAI's `tool_choice` to Gemini's `functionCallingConfig`
503 if (typeof toolChoice === 'string') {
504 switch (toolChoice) {
505 case 'none':
506 functionCallingConfig = { mode: 'NONE' };
507 break;
508 case 'required':
509 functionCallingConfig = { mode: 'ANY' };
510 break;
511 case 'auto':
512 functionCallingConfig = { mode: 'AUTO' };
513 break;
514 }
515 } else if (typeof toolChoice === 'object' && toolChoice?.function?.name) {
516 // Force a specific function call
517 functionCallingConfig = {
518 mode: 'ANY',
519 allowedFunctionNames: [toolChoice.function.name],
520 };
521 }
522
523 if (functionCallingConfig) {
524 body.toolConfig = { functionCallingConfig };
525 }
498 }526 }
499527
500 return body;528 return body;