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 = [
139139export const GEMINI_SAFETY = [
140140 {
141141 category: 'HARM_CATEGORY_HARASSMENT',
142142 threshold: 'BLOCK_NONEOFF',
143143 },
144144 {
145145 category: 'HARM_CATEGORY_HATE_SPEECH',
146146 threshold: 'BLOCK_NONEOFF',
147147 },
148148 {
149149 category: 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
150150 threshold: 'BLOCK_NONEOFF',
151151 },
152152 {
153153 category: 'HARM_CATEGORY_DANGEROUS_CONTENT',
154154 threshold: 'BLOCK_NONEOFF',
155155 },
156156 {
157157 category: 'HARM_CATEGORY_CIVIC_INTEGRITY',
src/endpoints/backends/chat-completions.js+7 -1
@@ -316,9 +316,15 @@ async function sendMakerSuiteRequest(request, response) {
316316 const prompt = convertGooglePrompt(request.body.messages, model, should_use_system_prompt, getPromptNames(request));
317317 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)) {
320325 safetySettings = GEMINI_SAFETY.map(setting => ({ ...setting, threshold: 'OFF' }));
321326 }
327+ // Most of the other models allow for setting the threshold of filters, except for HARM_CATEGORY_CIVIC_INTEGRITY, to OFF.
322328
323329 let body = {
324330 contents: prompt.contents,