feat: update Gemini safety settings - Set threshold to OFF for most models, except for HARM_CATEGORY_CIVIC_INTEGRITY. - Handle specific cases for a few models.

d35bd3b073a21d5772a13968ba072d10b4c3b8f3

sirius422 <sirius42@gfw.moe>

2 files changed, +11 -5Showing whitespace changes
src/constants.js+4 -4
@@ -139,19 +139,19 @@ export const UNSAFE_EXTENSIONS = [
139export const GEMINI_SAFETY = [139export const GEMINI_SAFETY = [
140 {140 {
141 category: 'HARM_CATEGORY_HARASSMENT',141 category: 'HARM_CATEGORY_HARASSMENT',
142 threshold: 'BLOCK_NONE',142 threshold: 'OFF',
143 },143 },
144 {144 {
145 category: 'HARM_CATEGORY_HATE_SPEECH',145 category: 'HARM_CATEGORY_HATE_SPEECH',
146 threshold: 'BLOCK_NONE',146 threshold: 'OFF',
147 },147 },
148 {148 {
149 category: 'HARM_CATEGORY_SEXUALLY_EXPLICIT',149 category: 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
150 threshold: 'BLOCK_NONE',150 threshold: 'OFF',
151 },151 },
152 {152 {
153 category: 'HARM_CATEGORY_DANGEROUS_CONTENT',153 category: 'HARM_CATEGORY_DANGEROUS_CONTENT',
154 threshold: 'BLOCK_NONE',154 threshold: 'OFF',
155 },155 },
156 {156 {
157 category: 'HARM_CATEGORY_CIVIC_INTEGRITY',157 category: 'HARM_CATEGORY_CIVIC_INTEGRITY',
src/endpoints/backends/chat-completions.js+7 -1
@@ -316,9 +316,15 @@ async function sendMakerSuiteRequest(request, response) {
316 const prompt = convertGooglePrompt(request.body.messages, model, should_use_system_prompt, getPromptNames(request));316 const prompt = convertGooglePrompt(request.body.messages, model, should_use_system_prompt, getPromptNames(request));
317 let safetySettings = GEMINI_SAFETY;317 let safetySettings = GEMINI_SAFETY;
318318
319 if (model.includes('gemini-2.0-flash-exp')) {319 // These old models do not support setting the threshold to OFF at all.
320 if (['gemini-1.5-pro-001', 'gemini-1.5-flash-001', 'gemini-1.0-pro-001'].includes(model)) {
321 safetySettings = GEMINI_SAFETY.map(setting => ({ ...setting, threshold: 'BLOCK_NONE' }));
322 }
323 // Interestingly, Gemini 2.0 Flash does support setting the threshold for HARM_CATEGORY_CIVIC_INTEGRITY to OFF.
324 else if (['gemini-2.0-flash', 'gemini-2.0-flash-001', 'gemini-2.0-flash-exp'].includes(model)) {
320 safetySettings = GEMINI_SAFETY.map(setting => ({ ...setting, threshold: 'OFF' }));325 safetySettings = GEMINI_SAFETY.map(setting => ({ ...setting, threshold: 'OFF' }));
321 }326 }
327 // Most of the other models allow for setting the threshold of filters, except for HARM_CATEGORY_CIVIC_INTEGRITY, to OFF.
322328
323 let body = {329 let body = {
324 contents: prompt.contents,330 contents: prompt.contents,