Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
741522d4
authored
Jan 10, 2024
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: able to change gemini safety setting
parent
3c91d753
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
19 deletions
+28
-19
common/constants.go
+2
-0
common/utils.go
+7
-0
controller/relay-gemini.go
+18
-18
controller/relay.go
+1
-1
No files found.
common/constants.go
View file @
741522d4
...
...
@@ -104,6 +104,8 @@ var BatchUpdateInterval = GetOrDefault("BATCH_UPDATE_INTERVAL", 5)
var
RelayTimeout
=
GetOrDefault
(
"RELAY_TIMEOUT"
,
0
)
// unit is second
var
GeminiSafetySetting
=
GetOrDefaultString
(
"GEMINI_SAFETY_SETTING"
,
"BLOCK_NONE"
)
const
(
RequestIdKey
=
"X-Oneapi-Request-Id"
)
...
...
common/utils.go
View file @
741522d4
...
...
@@ -202,6 +202,13 @@ func GetOrDefault(env string, defaultValue int) int {
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
{
return
fmt
.
Sprintf
(
"%s (request id: %s)"
,
message
,
id
)
}
...
...
controller/relay-gemini.go
View file @
741522d4
...
...
@@ -60,24 +60,24 @@ type GeminiChatGenerationConfig struct {
func
requestOpenAI2Gemini
(
textRequest
GeneralOpenAIRequest
)
*
GeminiChatRequest
{
geminiRequest
:=
GeminiChatRequest
{
Contents
:
make
([]
GeminiChatContent
,
0
,
len
(
textRequest
.
Messages
)),
//
SafetySettings: []GeminiChatSafetySettings{
//
{
//
Category: "HARM_CATEGORY_HARASSMENT",
// Threshold: "BLOCK_ONLY_HIGH"
,
//
},
//
{
//
Category: "HARM_CATEGORY_HATE_SPEECH",
// Threshold: "BLOCK_ONLY_HIGH"
,
//
},
//
{
//
Category: "HARM_CATEGORY_SEXUALLY_EXPLICIT",
// Threshold: "BLOCK_ONLY_HIGH"
,
//
},
//
{
//
Category: "HARM_CATEGORY_DANGEROUS_CONTENT",
// Threshold: "BLOCK_ONLY_HIGH"
,
//
},
//
},
SafetySettings
:
[]
GeminiChatSafetySettings
{
{
Category
:
"HARM_CATEGORY_HARASSMENT"
,
Threshold
:
common
.
GeminiSafetySetting
,
},
{
Category
:
"HARM_CATEGORY_HATE_SPEECH"
,
Threshold
:
common
.
GeminiSafetySetting
,
},
{
Category
:
"HARM_CATEGORY_SEXUALLY_EXPLICIT"
,
Threshold
:
common
.
GeminiSafetySetting
,
},
{
Category
:
"HARM_CATEGORY_DANGEROUS_CONTENT"
,
Threshold
:
common
.
GeminiSafetySetting
,
},
},
GenerationConfig
:
GeminiChatGenerationConfig
{
Temperature
:
textRequest
.
Temperature
,
TopP
:
textRequest
.
TopP
,
...
...
controller/relay.go
View file @
741522d4
...
...
@@ -332,7 +332,7 @@ func Relay(c *gin.Context) {
retryTimes
=
common
.
RetryTimes
}
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
{
if
err
.
StatusCode
==
http
.
StatusTooManyRequests
{
//err.OpenAIError.Message = "当前分组上游负载已饱和,请稍后再试"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment