Move endpoint version to conifg. Refactor ugli model lists

61c7f53d22ce351e3d7fcbf4c3a3a0922de4acdc

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

2 files changed, +30 -23Showing whitespace changes
default/config.yaml+4 -0
@@ -234,6 +234,10 @@ claude:
234234 # should be ideal for most use cases.
235235 # Any value other than a non-negative integer will be ignored and caching at depth will not be enabled.
236236 cachingAtDepth: -1
237+# -- GOOGLE GEMINI API CONFIGURATION --
238+gemini:
239+ # API endpoint version ("v1beta" or "v1alpha")
240+ apiVersion: 'v1beta'
237241# -- SERVER PLUGIN CONFIGURATION --
238242enableServerPlugins: false
239243# Attempt to automatically update server plugins on startup
src/endpoints/backends/chat-completions.js+26 -23
@@ -343,7 +343,6 @@ async function sendMakerSuiteRequest(request, response) {
343343 const enableWebSearch = Boolean(request.body.enable_web_search);
344344 const requestImages = Boolean(request.body.request_images);
345345 const reasoningEffort = String(request.body.reasoning_effort);
346- const isThinking = model.includes('thinking');
347346 const isGemma = model.includes('gemma');
348347 const isLearnLM = model.includes('learnlm');
349348
@@ -359,43 +358,52 @@ async function sendMakerSuiteRequest(request, response) {
359358 };
360359
361360 function getGeminiBody() {
361+ // #region UGLY MODEL LISTS AREA
362+ const imageGenerationModels = [
363+ 'gemini-2.0-flash-exp',
364+ 'gemini-2.0-flash-exp-image-generation',
365+ ];
366+
367+ const blockNoneModels = [
368+ 'gemini-1.5-pro-001',
369+ 'gemini-1.5-flash-001',
370+ 'gemini-1.5-flash-8b-exp-0827',
371+ 'gemini-1.5-flash-8b-exp-0924',
372+ ];
373+
374+ const thinkingBudgetModels = [
375+ 'gemini-2.5-flash-preview-04-17',
376+ ];
377+ // #endregion
378+
362379 if (!Array.isArray(generationConfig.stopSequences) || !generationConfig.stopSequences.length) {
363380 delete generationConfig.stopSequences;
364381 }
365382
366383 const useMultiModalenableImageModality = requestImages && ['gemini-2.0-flash-exp', 'gemini-2.0-flash-exp-image-generation']imageGenerationModels.includes(model);
367384 if (useMultiModalenableImageModality) {
368385 generationConfig.responseModalities = ['text', 'image'];
369386 }
370387
371388 const useSystemPrompt = !useMultiModalenableImageModality && (!isGemma && request.body.use_makersuite_sysprompt;
372- model.includes('gemini-2.5-pro') ||
373- model.includes('gemini-2.5-flash') ||
374- model.includes('gemini-2.0-pro') ||
375- model.includes('gemini-2.0-flash') ||
376- model.includes('gemini-1.5-pro') ||
377- model.includes('gemini-1.5-flash') ||
378- model.includes('learnlm') ||
379- model.startsWith('gemini-exp')
380- ) && request.body.use_makersuite_sysprompt;
381389
382390 const tools = [];
383391 const prompt = convertGooglePrompt(request.body.messages, model, useSystemPrompt, getPromptNames(request));
384392 let safetySettings = GEMINI_SAFETY;
385393
386394 // These models do not support setting the threshold to OFF at all.
387- if (['gemini-1.5-pro-001', 'gemini-1.5-flash-001', 'gemini-1.5-flash-8b-exp-0827', 'gemini-1.5-flash-8b-exp-0924'].includes(model)) {
395+ if (blockNoneModels.includes(model)) {
388396 safetySettings = GEMINI_SAFETY.map(setting => ({ ...setting, threshold: 'BLOCK_NONE' }));
389397 }
390398
391399 if (enableWebSearch && !useMultiModalenableImageModality && !isGemma && !isLearnLM && !model.includes('gemini-2.0-flash-lite')) {
392400 const searchTool = model.includes('1.5') || model.includes('1.0')
393401 ? ({ google_search_retrieval: {} })
394402 : ({ google_search: {} });
395403 tools.push(searchTool);
396404 }
397405
398406 if (Array.isArray(request.body.tools) && request.body.tools.length > 0 && !useMultiModalenableImageModality && !isGemma) {
399407 const functionDeclarations = [];
400408 for (const tool of request.body.tools) {
401409 if (tool.type === 'function') {
@@ -411,11 +419,6 @@ async function sendMakerSuiteRequest(request, response) {
411419 tools.push({ function_declarations: functionDeclarations });
412420 }
413421
414- // One more models list to maintain, yay
415- const thinkingBudgetModels = [
416- 'gemini-2.5-flash-preview-04-17',
417- ];
418-
419422 if (thinkingBudgetModels.includes(model)) {
420423 const thinkingBudget = calculateGoogleBudgetTokens(generationConfig.maxOutputTokens, reasoningEffort);
421424
@@ -451,7 +454,7 @@ async function sendMakerSuiteRequest(request, response) {
451454 controller.abort();
452455 });
453456
454457 const apiVersion = isThinking ? getConfigValue('v1alphagemini.apiVersion' :, 'v1beta');
455458 const responseType = (stream ? 'streamGenerateContent' : 'generateContent');
456459
457460 const generateResponse = await fetch(`${apiUrl.toString().replace(/\/$/, '')}/${apiVersion}/models/${model}:${responseType}?key=${apiKey}${stream ? '&alt=sse' : ''}`, {