sidebar: gemini: add safety settings

This commit is contained in:
end-4
2024-03-23 16:08:48 +07:00
parent 25355946b6
commit 8dff78172d
2 changed files with 21 additions and 7 deletions
@@ -104,6 +104,15 @@ export const GeminiSettings = () => MarginRevealer({
GeminiService.assistantPrompt = newValue; 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;
},
}),
] ]
}) })
] ]
+12 -7
View File
@@ -133,6 +133,7 @@ class GeminiService extends Service {
_messages = []; _messages = [];
_cycleModels = true; _cycleModels = true;
_requestCount = 0; _requestCount = 0;
_safe = true;
_temperature = userOptions.ai.defaultTemperature; _temperature = userOptions.ai.defaultTemperature;
_modelIndex = 0; _modelIndex = 0;
_key = ''; _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 } get temperature() { return this._temperature }
set temperature(value) { this._temperature = value; } set temperature(value) { this._temperature = value; }
@@ -198,6 +202,7 @@ class GeminiService extends Service {
try { try {
const [bytes] = stream.read_line_finish(res); const [bytes] = stream.read_line_finish(res);
const line = this._decoder.decode(bytes); const line = this._decoder.decode(bytes);
console.log(line);
if (line == '[{') { // beginning of response if (line == '[{') { // beginning of response
aiResponse._rawData += '{'; aiResponse._rawData += '{';
this.thinking = false; this.thinking = false;
@@ -229,13 +234,13 @@ class GeminiService extends Service {
const body = const body =
{ {
"contents": this._messages.map(msg => { let m = { role: msg.role, parts: msg.parts }; return m; }), "contents": this._messages.map(msg => { let m = { role: msg.role, parts: msg.parts }; return m; }),
// "safetySettings": [ "safetySettings": this._safe ? [] : [
// { category: "HARM_CATEGORY_DEROGATORY", threshold: "BLOCK_NONE", }, // { category: "HARM_CATEGORY_DEROGATORY", threshold: "BLOCK_NONE", },
// { category: "HARM_CATEGORY_HARASSMENT", threshold: "BLOCK_NONE", }, { category: "HARM_CATEGORY_HARASSMENT", threshold: "BLOCK_NONE", },
// { category: "HARM_CATEGORY_HATE_SPEECH", threshold: "BLOCK_NONE", }, { category: "HARM_CATEGORY_HATE_SPEECH", threshold: "BLOCK_NONE", },
// { category: "HARM_CATEGORY_SEXUALLY_EXPLICIT", threshold: "BLOCK_NONE", }, { category: "HARM_CATEGORY_SEXUALLY_EXPLICIT", threshold: "BLOCK_NONE", },
// { category: "HARM_CATEGORY_UNSPECIFIED", threshold: "BLOCK_NONE", }, // { category: "HARM_CATEGORY_UNSPECIFIED", threshold: "BLOCK_NONE", },
// ], ],
"generationConfig": { "generationConfig": {
"temperature": this._temperature, "temperature": this._temperature,
}, },