Gemma 3 (#3686) * Gemma 3 * Adjust safetySettings * Disable sysprompt * Add isGemma check to tool processing logic * Disable a google search tool for gemma

f607c3bc0d656c5f349e8745e37d8700feec9f9f

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

Signed
3 files changed, +11 -5Showing whitespace changes
public/index.html+3 -0
@@ -3134,6 +3134,9 @@
3134 <option value="gemini-ultra">Gemini Ultra (1.0)</option>3134 <option value="gemini-ultra">Gemini Ultra (1.0)</option>
3135 <option value="gemini-1.0-ultra-latest">Gemini 1.0 Ultra</option>3135 <option value="gemini-1.0-ultra-latest">Gemini 1.0 Ultra</option>
3136 </optgroup>3136 </optgroup>
3137 <optgroup label="Gemma">
3138 <option value="gemma-3-27b-it">Gemma 3 27B</option>
3139 </optgroup>
3137 <optgroup label="Subversions">3140 <optgroup label="Subversions">
3138 <option value="gemini-2.0-pro-exp">Gemini 2.0 Pro Experimental</option>3141 <option value="gemini-2.0-pro-exp">Gemini 2.0 Pro Experimental</option>
3139 <option value="gemini-2.0-pro-exp-02-05">Gemini 2.0 Pro Experimental 2025-02-05</option>3142 <option value="gemini-2.0-pro-exp-02-05">Gemini 2.0 Pro Experimental 2025-02-05</option>
public/scripts/openai.js+3 -1
@@ -4341,10 +4341,12 @@ async function onModelChange() {
4341 $('#openai_max_context').attr('max', max_32k);4341 $('#openai_max_context').attr('max', max_32k);
4342 } else if (value.includes('gemini-1.0-ultra') || value === 'gemini-ultra') {4342 } else if (value.includes('gemini-1.0-ultra') || value === 'gemini-ultra') {
4343 $('#openai_max_context').attr('max', max_32k);4343 $('#openai_max_context').attr('max', max_32k);
4344 } else if (value.includes('gemma-3')) {
4345 $('#openai_max_context').attr('max', max_128k);
4344 } else {4346 } else {
4345 $('#openai_max_context').attr('max', max_4k);4347 $('#openai_max_context').attr('max', max_4k);
4346 }4348 }
4347 let makersuite_max_temp = (value.includes('vision') || value.includes('ultra')) ? 1.0 : 2.0;4349 let makersuite_max_temp = (value.includes('vision') || value.includes('ultra') || value.includes('gemma')) ? 1.0 : 2.0;
4348 oai_settings.temp_openai = Math.min(makersuite_max_temp, oai_settings.temp_openai);4350 oai_settings.temp_openai = Math.min(makersuite_max_temp, oai_settings.temp_openai);
4349 $('#temp_openai').attr('max', makersuite_max_temp).val(oai_settings.temp_openai).trigger('input');4351 $('#temp_openai').attr('max', makersuite_max_temp).val(oai_settings.temp_openai).trigger('input');
4350 oai_settings.openai_max_context = Math.min(Number($('#openai_max_context').attr('max')), oai_settings.openai_max_context);4352 oai_settings.openai_max_context = Math.min(Number($('#openai_max_context').attr('max')), oai_settings.openai_max_context);
src/endpoints/backends/chat-completions.js+5 -4
@@ -340,6 +340,7 @@ async function sendMakerSuiteRequest(request, response) {
340 const enableWebSearch = Boolean(request.body.enable_web_search);340 const enableWebSearch = Boolean(request.body.enable_web_search);
341 const requestImages = Boolean(request.body.request_images);341 const requestImages = Boolean(request.body.request_images);
342 const isThinking = model.includes('thinking');342 const isThinking = model.includes('thinking');
343 const isGemma = model.includes('gemma');
343344
344 const generationConfig = {345 const generationConfig = {
345 stopSequences: request.body.stop,346 stopSequences: request.body.stop,
@@ -375,8 +376,8 @@ async function sendMakerSuiteRequest(request, response) {
375 const prompt = convertGooglePrompt(request.body.messages, model, useSystemPrompt, getPromptNames(request));376 const prompt = convertGooglePrompt(request.body.messages, model, useSystemPrompt, getPromptNames(request));
376 let safetySettings = GEMINI_SAFETY;377 let safetySettings = GEMINI_SAFETY;
377378
378 // These old models do not support setting the threshold to OFF at all.379 // These models do not support setting the threshold to OFF at all.
379 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', 'gemini-pro', 'gemini-1.0-pro', 'gemini-1.0-pro-001'].includes(model)) {380 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', 'gemini-pro', 'gemini-1.0-pro', 'gemini-1.0-pro-001', 'gemma-3-27b-it'].includes(model)) {
380 safetySettings = GEMINI_SAFETY.map(setting => ({ ...setting, threshold: 'BLOCK_NONE' }));381 safetySettings = GEMINI_SAFETY.map(setting => ({ ...setting, threshold: 'BLOCK_NONE' }));
381 }382 }
382 // Interestingly, Gemini 2.0 Flash does support setting the threshold for HARM_CATEGORY_CIVIC_INTEGRITY to OFF.383 // Interestingly, Gemini 2.0 Flash does support setting the threshold for HARM_CATEGORY_CIVIC_INTEGRITY to OFF.
@@ -385,14 +386,14 @@ async function sendMakerSuiteRequest(request, response) {
385 }386 }
386 // Most of the other models allow for setting the threshold of filters, except for HARM_CATEGORY_CIVIC_INTEGRITY, to OFF.387 // Most of the other models allow for setting the threshold of filters, except for HARM_CATEGORY_CIVIC_INTEGRITY, to OFF.
387388
388 if (enableWebSearch && !useMultiModal) {389 if (enableWebSearch && !useMultiModal && !isGemma) {
389 const searchTool = model.includes('1.5') || model.includes('1.0')390 const searchTool = model.includes('1.5') || model.includes('1.0')
390 ? ({ google_search_retrieval: {} })391 ? ({ google_search_retrieval: {} })
391 : ({ google_search: {} });392 : ({ google_search: {} });
392 tools.push(searchTool);393 tools.push(searchTool);
393 }394 }
394395
395 if (Array.isArray(request.body.tools) && request.body.tools.length > 0 && !useMultiModal) {396 if (Array.isArray(request.body.tools) && request.body.tools.length > 0 && !useMultiModal && !isGemma) {
396 const functionDeclarations = [];397 const functionDeclarations = [];
397 for (const tool of request.body.tools) {398 for (const tool of request.body.tools) {
398 if (tool.type === 'function') {399 if (tool.type === 'function') {