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
146ab7d2
authored
May 16, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: able to set pre consumed quota now
parent
afbf20b5
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
3 deletions
+22
-3
common/constants.go
+1
-0
controller/relay.go
+2
-2
model/option.go
+3
-0
web/src/components/SystemSetting.js
+16
-1
No files found.
common/constants.go
View file @
146ab7d2
...
@@ -54,6 +54,7 @@ var QuotaForNewUser = 0
...
@@ -54,6 +54,7 @@ var QuotaForNewUser = 0
var
ChannelDisableThreshold
=
5.0
var
ChannelDisableThreshold
=
5.0
var
AutomaticDisableChannelEnabled
=
false
var
AutomaticDisableChannelEnabled
=
false
var
QuotaRemindThreshold
=
1000
var
QuotaRemindThreshold
=
1000
var
PreConsumedQuota
=
500
var
RootUserEmail
=
""
var
RootUserEmail
=
""
...
...
controller/relay.go
View file @
146ab7d2
...
@@ -128,7 +128,8 @@ func relayHelper(c *gin.Context) error {
...
@@ -128,7 +128,8 @@ func relayHelper(c *gin.Context) error {
model_
=
strings
.
TrimSuffix
(
model_
,
"-0314"
)
model_
=
strings
.
TrimSuffix
(
model_
,
"-0314"
)
fullRequestURL
=
fmt
.
Sprintf
(
"%s/openai/deployments/%s/%s"
,
baseURL
,
model_
,
task
)
fullRequestURL
=
fmt
.
Sprintf
(
"%s/openai/deployments/%s/%s"
,
baseURL
,
model_
,
task
)
}
}
preConsumedQuota
:=
500
// TODO: make this configurable, take ratio into account
ratio
:=
common
.
GetModelRatio
(
textRequest
.
Model
)
preConsumedQuota
:=
int
(
float64
(
common
.
PreConsumedQuota
)
*
ratio
)
if
consumeQuota
{
if
consumeQuota
{
err
:=
model
.
PreConsumeTokenQuota
(
tokenId
,
preConsumedQuota
)
err
:=
model
.
PreConsumeTokenQuota
(
tokenId
,
preConsumedQuota
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -184,7 +185,6 @@ func relayHelper(c *gin.Context) error {
...
@@ -184,7 +185,6 @@ func relayHelper(c *gin.Context) error {
}
else
{
}
else
{
quota
=
textResponse
.
Usage
.
PromptTokens
+
textResponse
.
Usage
.
CompletionTokens
*
completionRatio
quota
=
textResponse
.
Usage
.
PromptTokens
+
textResponse
.
Usage
.
CompletionTokens
*
completionRatio
}
}
ratio
:=
common
.
GetModelRatio
(
textRequest
.
Model
)
quota
=
int
(
float64
(
quota
)
*
ratio
)
quota
=
int
(
float64
(
quota
)
*
ratio
)
quotaDelta
:=
quota
-
preConsumedQuota
quotaDelta
:=
quota
-
preConsumedQuota
err
:=
model
.
PostConsumeTokenQuota
(
tokenId
,
quotaDelta
)
err
:=
model
.
PostConsumeTokenQuota
(
tokenId
,
quotaDelta
)
...
...
model/option.go
View file @
146ab7d2
...
@@ -55,6 +55,7 @@ func InitOptionMap() {
...
@@ -55,6 +55,7 @@ func InitOptionMap() {
common
.
OptionMap
[
"TurnstileSecretKey"
]
=
""
common
.
OptionMap
[
"TurnstileSecretKey"
]
=
""
common
.
OptionMap
[
"QuotaForNewUser"
]
=
strconv
.
Itoa
(
common
.
QuotaForNewUser
)
common
.
OptionMap
[
"QuotaForNewUser"
]
=
strconv
.
Itoa
(
common
.
QuotaForNewUser
)
common
.
OptionMap
[
"QuotaRemindThreshold"
]
=
strconv
.
Itoa
(
common
.
QuotaRemindThreshold
)
common
.
OptionMap
[
"QuotaRemindThreshold"
]
=
strconv
.
Itoa
(
common
.
QuotaRemindThreshold
)
common
.
OptionMap
[
"PreConsumedQuota"
]
=
strconv
.
Itoa
(
common
.
PreConsumedQuota
)
common
.
OptionMap
[
"ModelRatio"
]
=
common
.
ModelRatio2JSONString
()
common
.
OptionMap
[
"ModelRatio"
]
=
common
.
ModelRatio2JSONString
()
common
.
OptionMap
[
"TopUpLink"
]
=
common
.
TopUpLink
common
.
OptionMap
[
"TopUpLink"
]
=
common
.
TopUpLink
common
.
OptionMapRWMutex
.
Unlock
()
common
.
OptionMapRWMutex
.
Unlock
()
...
@@ -159,6 +160,8 @@ func updateOptionMap(key string, value string) (err error) {
...
@@ -159,6 +160,8 @@ func updateOptionMap(key string, value string) (err error) {
common
.
QuotaForNewUser
,
_
=
strconv
.
Atoi
(
value
)
common
.
QuotaForNewUser
,
_
=
strconv
.
Atoi
(
value
)
case
"QuotaRemindThreshold"
:
case
"QuotaRemindThreshold"
:
common
.
QuotaRemindThreshold
,
_
=
strconv
.
Atoi
(
value
)
common
.
QuotaRemindThreshold
,
_
=
strconv
.
Atoi
(
value
)
case
"PreConsumedQuota"
:
common
.
PreConsumedQuota
,
_
=
strconv
.
Atoi
(
value
)
case
"ModelRatio"
:
case
"ModelRatio"
:
err
=
common
.
UpdateModelRatioByJSONString
(
value
)
err
=
common
.
UpdateModelRatioByJSONString
(
value
)
case
"TopUpLink"
:
case
"TopUpLink"
:
...
...
web/src/components/SystemSetting.js
View file @
146ab7d2
...
@@ -28,6 +28,7 @@ const SystemSetting = () => {
...
@@ -28,6 +28,7 @@ const SystemSetting = () => {
RegisterEnabled
:
''
,
RegisterEnabled
:
''
,
QuotaForNewUser
:
0
,
QuotaForNewUser
:
0
,
QuotaRemindThreshold
:
0
,
QuotaRemindThreshold
:
0
,
PreConsumedQuota
:
0
,
ModelRatio
:
''
,
ModelRatio
:
''
,
TopUpLink
:
''
,
TopUpLink
:
''
,
AutomaticDisableChannelEnabled
:
''
,
AutomaticDisableChannelEnabled
:
''
,
...
@@ -98,6 +99,7 @@ const SystemSetting = () => {
...
@@ -98,6 +99,7 @@ const SystemSetting = () => {
name
===
'TurnstileSecretKey'
||
name
===
'TurnstileSecretKey'
||
name
===
'QuotaForNewUser'
||
name
===
'QuotaForNewUser'
||
name
===
'QuotaRemindThreshold'
||
name
===
'QuotaRemindThreshold'
||
name
===
'PreConsumedQuota'
||
name
===
'ModelRatio'
||
name
===
'ModelRatio'
||
name
===
'TopUpLink'
name
===
'TopUpLink'
)
{
)
{
...
@@ -119,6 +121,9 @@ const SystemSetting = () => {
...
@@ -119,6 +121,9 @@ const SystemSetting = () => {
if
(
originInputs
[
'QuotaRemindThreshold'
]
!==
inputs
.
QuotaRemindThreshold
)
{
if
(
originInputs
[
'QuotaRemindThreshold'
]
!==
inputs
.
QuotaRemindThreshold
)
{
await
updateOption
(
'QuotaRemindThreshold'
,
inputs
.
QuotaRemindThreshold
);
await
updateOption
(
'QuotaRemindThreshold'
,
inputs
.
QuotaRemindThreshold
);
}
}
if
(
originInputs
[
'PreConsumedQuota'
]
!==
inputs
.
PreConsumedQuota
)
{
await
updateOption
(
'PreConsumedQuota'
,
inputs
.
PreConsumedQuota
);
}
if
(
originInputs
[
'ModelRatio'
]
!==
inputs
.
ModelRatio
)
{
if
(
originInputs
[
'ModelRatio'
]
!==
inputs
.
ModelRatio
)
{
if
(
!
verifyJSON
(
inputs
.
ModelRatio
))
{
if
(
!
verifyJSON
(
inputs
.
ModelRatio
))
{
showError
(
'模型倍率不是合法的 JSON 字符串'
);
showError
(
'模型倍率不是合法的 JSON 字符串'
);
...
@@ -272,7 +277,7 @@ const SystemSetting = () => {
...
@@ -272,7 +277,7 @@ const SystemSetting = () => {
<
Header
as
=
'h3'
>
<
Header
as
=
'h3'
>
运营设置
运营设置
<
/Header
>
<
/Header
>
<
Form
.
Group
widths
=
{
3
}
>
<
Form
.
Group
widths
=
{
4
}
>
<
Form
.
Input
<
Form
.
Input
label
=
'新用户初始配额'
label
=
'新用户初始配额'
name
=
'QuotaForNewUser'
name
=
'QuotaForNewUser'
...
@@ -302,6 +307,16 @@ const SystemSetting = () => {
...
@@ -302,6 +307,16 @@ const SystemSetting = () => {
min
=
'0'
min
=
'0'
placeholder
=
'低于此额度时将发送邮件提醒用户'
placeholder
=
'低于此额度时将发送邮件提醒用户'
/>
/>
<
Form
.
Input
label
=
'请求预扣费额度'
name
=
'PreConsumedQuota'
onChange
=
{
handleInputChange
}
autoComplete
=
'new-password'
value
=
{
inputs
.
PreConsumedQuota
}
type
=
'number'
min
=
'0'
placeholder
=
'请求结束后多退少补'
/>
<
/Form.Group
>
<
/Form.Group
>
<
Form
.
Group
widths
=
'equal'
>
<
Form
.
Group
widths
=
'equal'
>
<
Form
.
TextArea
<
Form
.
TextArea
...
...
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