Move endpoint version to conifg. Refactor ugli model lists

This commit is contained in:
Cohee
2025-04-27 14:56:51 +03:00
parent acc05e633d
commit 61c7f53d22
2 changed files with 30 additions and 23 deletions

View File

@ -234,6 +234,10 @@ claude:
# should be ideal for most use cases. # should be ideal for most use cases.
# Any value other than a non-negative integer will be ignored and caching at depth will not be enabled. # Any value other than a non-negative integer will be ignored and caching at depth will not be enabled.
cachingAtDepth: -1 cachingAtDepth: -1
# -- GOOGLE GEMINI API CONFIGURATION --
gemini:
# API endpoint version ("v1beta" or "v1alpha")
apiVersion: 'v1beta'
# -- SERVER PLUGIN CONFIGURATION -- # -- SERVER PLUGIN CONFIGURATION --
enableServerPlugins: false enableServerPlugins: false
# Attempt to automatically update server plugins on startup # Attempt to automatically update server plugins on startup

View File

@ -343,7 +343,6 @@ async function sendMakerSuiteRequest(request, response) {
const enableWebSearch = Boolean(request.body.enable_web_search); const enableWebSearch = Boolean(request.body.enable_web_search);
const requestImages = Boolean(request.body.request_images); const requestImages = Boolean(request.body.request_images);
const reasoningEffort = String(request.body.reasoning_effort); const reasoningEffort = String(request.body.reasoning_effort);
const isThinking = model.includes('thinking');
const isGemma = model.includes('gemma'); const isGemma = model.includes('gemma');
const isLearnLM = model.includes('learnlm'); const isLearnLM = model.includes('learnlm');
@ -359,43 +358,52 @@ async function sendMakerSuiteRequest(request, response) {
}; };
function getGeminiBody() { function getGeminiBody() {
// #region UGLY MODEL LISTS AREA
const imageGenerationModels = [
'gemini-2.0-flash-exp',
'gemini-2.0-flash-exp-image-generation',
];
const blockNoneModels = [
'gemini-1.5-pro-001',
'gemini-1.5-flash-001',
'gemini-1.5-flash-8b-exp-0827',
'gemini-1.5-flash-8b-exp-0924',
];
const thinkingBudgetModels = [
'gemini-2.5-flash-preview-04-17',
];
// #endregion
if (!Array.isArray(generationConfig.stopSequences) || !generationConfig.stopSequences.length) { if (!Array.isArray(generationConfig.stopSequences) || !generationConfig.stopSequences.length) {
delete generationConfig.stopSequences; delete generationConfig.stopSequences;
} }
const useMultiModal = requestImages && ['gemini-2.0-flash-exp', 'gemini-2.0-flash-exp-image-generation'].includes(model); const enableImageModality = requestImages && imageGenerationModels.includes(model);
if (useMultiModal) { if (enableImageModality) {
generationConfig.responseModalities = ['text', 'image']; generationConfig.responseModalities = ['text', 'image'];
} }
const useSystemPrompt = !useMultiModal && ( const useSystemPrompt = !enableImageModality && !isGemma && request.body.use_makersuite_sysprompt;
model.includes('gemini-2.5-pro') ||
model.includes('gemini-2.5-flash') ||
model.includes('gemini-2.0-pro') ||
model.includes('gemini-2.0-flash') ||
model.includes('gemini-1.5-pro') ||
model.includes('gemini-1.5-flash') ||
model.includes('learnlm') ||
model.startsWith('gemini-exp')
) && request.body.use_makersuite_sysprompt;
const tools = []; const tools = [];
const prompt = convertGooglePrompt(request.body.messages, model, useSystemPrompt, getPromptNames(request)); const prompt = convertGooglePrompt(request.body.messages, model, useSystemPrompt, getPromptNames(request));
let safetySettings = GEMINI_SAFETY; let safetySettings = GEMINI_SAFETY;
// These models do not support setting the threshold to OFF at all. // These models do not support setting the threshold to OFF at all.
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)) { if (blockNoneModels.includes(model)) {
safetySettings = GEMINI_SAFETY.map(setting => ({ ...setting, threshold: 'BLOCK_NONE' })); safetySettings = GEMINI_SAFETY.map(setting => ({ ...setting, threshold: 'BLOCK_NONE' }));
} }
if (enableWebSearch && !useMultiModal && !isGemma && !isLearnLM && !model.includes('gemini-2.0-flash-lite')) { if (enableWebSearch && !enableImageModality && !isGemma && !isLearnLM && !model.includes('gemini-2.0-flash-lite')) {
const searchTool = model.includes('1.5') || model.includes('1.0') const searchTool = model.includes('1.5')
? ({ google_search_retrieval: {} }) ? ({ google_search_retrieval: {} })
: ({ google_search: {} }); : ({ google_search: {} });
tools.push(searchTool); tools.push(searchTool);
} }
if (Array.isArray(request.body.tools) && request.body.tools.length > 0 && !useMultiModal && !isGemma) { if (Array.isArray(request.body.tools) && request.body.tools.length > 0 && !enableImageModality && !isGemma) {
const functionDeclarations = []; const functionDeclarations = [];
for (const tool of request.body.tools) { for (const tool of request.body.tools) {
if (tool.type === 'function') { if (tool.type === 'function') {
@ -411,11 +419,6 @@ async function sendMakerSuiteRequest(request, response) {
tools.push({ function_declarations: functionDeclarations }); tools.push({ function_declarations: functionDeclarations });
} }
// One more models list to maintain, yay
const thinkingBudgetModels = [
'gemini-2.5-flash-preview-04-17',
];
if (thinkingBudgetModels.includes(model)) { if (thinkingBudgetModels.includes(model)) {
const thinkingBudget = calculateGoogleBudgetTokens(generationConfig.maxOutputTokens, reasoningEffort); const thinkingBudget = calculateGoogleBudgetTokens(generationConfig.maxOutputTokens, reasoningEffort);
@ -451,7 +454,7 @@ async function sendMakerSuiteRequest(request, response) {
controller.abort(); controller.abort();
}); });
const apiVersion = isThinking ? 'v1alpha' : 'v1beta'; const apiVersion = getConfigValue('gemini.apiVersion', 'v1beta');
const responseType = (stream ? 'streamGenerateContent' : 'generateContent'); const responseType = (stream ? 'streamGenerateContent' : 'generateContent');
const generateResponse = await fetch(`${apiUrl.toString().replace(/\/$/, '')}/${apiVersion}/models/${model}:${responseType}?key=${apiKey}${stream ? '&alt=sse' : ''}`, { const generateResponse = await fetch(`${apiUrl.toString().replace(/\/$/, '')}/${apiVersion}/models/${model}:${responseType}?key=${apiKey}${stream ? '&alt=sse' : ''}`, {