From 8dff78172dbda14bc8d21ef35213ac137d21f28b Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sat, 23 Mar 2024 16:08:48 +0700 Subject: [PATCH] sidebar: gemini: add safety settings --- .config/ags/modules/sideleft/apis/gemini.js | 9 +++++++++ .config/ags/services/gemini.js | 19 ++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/.config/ags/modules/sideleft/apis/gemini.js b/.config/ags/modules/sideleft/apis/gemini.js index a5fb278bc..06a888dab 100644 --- a/.config/ags/modules/sideleft/apis/gemini.js +++ b/.config/ags/modules/sideleft/apis/gemini.js @@ -104,6 +104,15 @@ export const GeminiSettings = () => MarginRevealer({ GeminiService.assistantPrompt = newValue; }, }), + ConfigToggle({ + icon: 'shield', + name: 'Safety', + desc: 'When turned off, tells the API not to block harmful/explicit content', + initValue: GeminiService.safe, + onChange: (self, newValue) => { + GeminiService.safe = newValue; + }, + }), ] }) ] diff --git a/.config/ags/services/gemini.js b/.config/ags/services/gemini.js index a553776b9..4457749f0 100644 --- a/.config/ags/services/gemini.js +++ b/.config/ags/services/gemini.js @@ -133,6 +133,7 @@ class GeminiService extends Service { _messages = []; _cycleModels = true; _requestCount = 0; + _safe = true; _temperature = userOptions.ai.defaultTemperature; _modelIndex = 0; _key = ''; @@ -170,6 +171,9 @@ class GeminiService extends Service { } } + get safe() { return this._safe } + set safe(value) { this._safe = value; } + get temperature() { return this._temperature } set temperature(value) { this._temperature = value; } @@ -198,6 +202,7 @@ class GeminiService extends Service { try { const [bytes] = stream.read_line_finish(res); const line = this._decoder.decode(bytes); + console.log(line); if (line == '[{') { // beginning of response aiResponse._rawData += '{'; this.thinking = false; @@ -229,13 +234,13 @@ class GeminiService extends Service { const body = { "contents": this._messages.map(msg => { let m = { role: msg.role, parts: msg.parts }; return m; }), - // "safetySettings": [ - // { category: "HARM_CATEGORY_DEROGATORY", threshold: "BLOCK_NONE", }, - // { category: "HARM_CATEGORY_HARASSMENT", threshold: "BLOCK_NONE", }, - // { category: "HARM_CATEGORY_HATE_SPEECH", threshold: "BLOCK_NONE", }, - // { category: "HARM_CATEGORY_SEXUALLY_EXPLICIT", threshold: "BLOCK_NONE", }, - // { category: "HARM_CATEGORY_UNSPECIFIED", threshold: "BLOCK_NONE", }, - // ], + "safetySettings": this._safe ? [] : [ + // { category: "HARM_CATEGORY_DEROGATORY", threshold: "BLOCK_NONE", }, + { category: "HARM_CATEGORY_HARASSMENT", threshold: "BLOCK_NONE", }, + { category: "HARM_CATEGORY_HATE_SPEECH", threshold: "BLOCK_NONE", }, + { category: "HARM_CATEGORY_SEXUALLY_EXPLICIT", threshold: "BLOCK_NONE", }, + // { category: "HARM_CATEGORY_UNSPECIFIED", threshold: "BLOCK_NONE", }, + ], "generationConfig": { "temperature": this._temperature, },