mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
feat(gemini): apply default safety settings across request translators
This commit is contained in:
47
internal/translator/gemini/common/safety.go
Normal file
47
internal/translator/gemini/common/safety.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"github.com/tidwall/gjson"
|
||||
"github.com/tidwall/sjson"
|
||||
)
|
||||
|
||||
// DefaultSafetySettings returns the default Gemini safety configuration we attach to requests.
|
||||
func DefaultSafetySettings() []map[string]string {
|
||||
return []map[string]string{
|
||||
{
|
||||
"category": "HARM_CATEGORY_HARASSMENT",
|
||||
"threshold": "OFF",
|
||||
},
|
||||
{
|
||||
"category": "HARM_CATEGORY_HATE_SPEECH",
|
||||
"threshold": "OFF",
|
||||
},
|
||||
{
|
||||
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
||||
"threshold": "OFF",
|
||||
},
|
||||
{
|
||||
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
||||
"threshold": "OFF",
|
||||
},
|
||||
{
|
||||
"category": "HARM_CATEGORY_CIVIC_INTEGRITY",
|
||||
"threshold": "BLOCK_NONE",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// AttachDefaultSafetySettings ensures the default safety settings are present when absent.
|
||||
// The caller must provide the target JSON path (e.g. "safetySettings" or "request.safetySettings").
|
||||
func AttachDefaultSafetySettings(rawJSON []byte, path string) []byte {
|
||||
if gjson.GetBytes(rawJSON, path).Exists() {
|
||||
return rawJSON
|
||||
}
|
||||
|
||||
out, err := sjson.SetBytes(rawJSON, path, DefaultSafetySettings())
|
||||
if err != nil {
|
||||
return rawJSON
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
Reference in New Issue
Block a user