sidebar: gemini: add safety settings

This commit is contained in:
end-4
2024-03-23 16:08:48 +07:00
parent dc9d63b6e5
commit 77743625c7
2 changed files with 21 additions and 7 deletions
@@ -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;
},
}),
]
})
]
+12 -7
View File
@@ -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,
},