mirror of
https://github.com/linux-do/new-api.git
synced 2025-09-22 02:06:38 +08:00
feat: able to change gemini safety setting
This commit is contained in:
parent
6a24e8953f
commit
aca8d25372
@ -104,6 +104,8 @@ var BatchUpdateInterval = GetOrDefault("BATCH_UPDATE_INTERVAL", 5)
|
|||||||
|
|
||||||
var RelayTimeout = GetOrDefault("RELAY_TIMEOUT", 0) // unit is second
|
var RelayTimeout = GetOrDefault("RELAY_TIMEOUT", 0) // unit is second
|
||||||
|
|
||||||
|
var GeminiSafetySetting = GetOrDefaultString("GEMINI_SAFETY_SETTING", "BLOCK_NONE")
|
||||||
|
|
||||||
const (
|
const (
|
||||||
RequestIdKey = "X-Oneapi-Request-Id"
|
RequestIdKey = "X-Oneapi-Request-Id"
|
||||||
)
|
)
|
||||||
|
@ -202,6 +202,13 @@ func GetOrDefault(env string, defaultValue int) int {
|
|||||||
return num
|
return num
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetOrDefaultString(env string, defaultValue string) string {
|
||||||
|
if env == "" || os.Getenv(env) == "" {
|
||||||
|
return defaultValue
|
||||||
|
}
|
||||||
|
return os.Getenv(env)
|
||||||
|
}
|
||||||
|
|
||||||
func MessageWithRequestId(message string, id string) string {
|
func MessageWithRequestId(message string, id string) string {
|
||||||
return fmt.Sprintf("%s (request id: %s)", message, id)
|
return fmt.Sprintf("%s (request id: %s)", message, id)
|
||||||
}
|
}
|
||||||
|
@ -60,24 +60,24 @@ type GeminiChatGenerationConfig struct {
|
|||||||
func requestOpenAI2Gemini(textRequest GeneralOpenAIRequest) *GeminiChatRequest {
|
func requestOpenAI2Gemini(textRequest GeneralOpenAIRequest) *GeminiChatRequest {
|
||||||
geminiRequest := GeminiChatRequest{
|
geminiRequest := GeminiChatRequest{
|
||||||
Contents: make([]GeminiChatContent, 0, len(textRequest.Messages)),
|
Contents: make([]GeminiChatContent, 0, len(textRequest.Messages)),
|
||||||
//SafetySettings: []GeminiChatSafetySettings{
|
SafetySettings: []GeminiChatSafetySettings{
|
||||||
// {
|
{
|
||||||
// Category: "HARM_CATEGORY_HARASSMENT",
|
Category: "HARM_CATEGORY_HARASSMENT",
|
||||||
// Threshold: "BLOCK_ONLY_HIGH",
|
Threshold: common.GeminiSafetySetting,
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// Category: "HARM_CATEGORY_HATE_SPEECH",
|
Category: "HARM_CATEGORY_HATE_SPEECH",
|
||||||
// Threshold: "BLOCK_ONLY_HIGH",
|
Threshold: common.GeminiSafetySetting,
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// Category: "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
Category: "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
||||||
// Threshold: "BLOCK_ONLY_HIGH",
|
Threshold: common.GeminiSafetySetting,
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// Category: "HARM_CATEGORY_DANGEROUS_CONTENT",
|
Category: "HARM_CATEGORY_DANGEROUS_CONTENT",
|
||||||
// Threshold: "BLOCK_ONLY_HIGH",
|
Threshold: common.GeminiSafetySetting,
|
||||||
// },
|
},
|
||||||
//},
|
},
|
||||||
GenerationConfig: GeminiChatGenerationConfig{
|
GenerationConfig: GeminiChatGenerationConfig{
|
||||||
Temperature: textRequest.Temperature,
|
Temperature: textRequest.Temperature,
|
||||||
TopP: textRequest.TopP,
|
TopP: textRequest.TopP,
|
||||||
|
@ -332,7 +332,7 @@ func Relay(c *gin.Context) {
|
|||||||
retryTimes = common.RetryTimes
|
retryTimes = common.RetryTimes
|
||||||
}
|
}
|
||||||
if retryTimes > 0 {
|
if retryTimes > 0 {
|
||||||
c.Redirect(http.StatusTemporaryRedirect, fmt.Sprintf("%s?retry=%d", c.Request.URL.Path, retryTimes-1))
|
c.Redirect(http.StatusTemporaryRedirect, fmt.Sprintf("%s?retry=%d&error=%s", c.Request.URL.Path, retryTimes-1, err.Message))
|
||||||
} else {
|
} else {
|
||||||
if err.StatusCode == http.StatusTooManyRequests {
|
if err.StatusCode == http.StatusTooManyRequests {
|
||||||
//err.OpenAIError.Message = "当前分组上游负载已饱和,请稍后再试"
|
//err.OpenAIError.Message = "当前分组上游负载已饱和,请稍后再试"
|
||||||
|
Loading…
Reference in New Issue
Block a user