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
0760dcf6
authored
Apr 28, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: support configuring ratio when estimating token number in stream mode
parent
52e92554
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
1 deletions
+21
-1
common/constants.go
+1
-0
controller/relay.go
+1
-1
model/option.go
+3
-0
web/src/components/SystemSetting.js
+16
-0
No files found.
common/constants.go
View file @
0760dcf6
...
...
@@ -48,6 +48,7 @@ var TurnstileSiteKey = ""
var
TurnstileSecretKey
=
""
var
QuotaForNewUser
=
100
var
BytesNumber2Quota
=
0.8
const
(
RoleGuestUser
=
0
...
...
controller/relay.go
View file @
0760dcf6
...
...
@@ -110,7 +110,7 @@ func relayHelper(c *gin.Context) error {
if
consumeQuota
{
quota
:=
0
if
isStream
{
quota
=
int
(
float64
(
len
(
streamResponseText
))
*
0.8
)
quota
=
int
(
float64
(
len
(
streamResponseText
))
*
common
.
BytesNumber2Quota
)
}
else
{
quota
=
textResponse
.
Usage
.
TotalTokens
}
...
...
model/option.go
View file @
0760dcf6
...
...
@@ -47,6 +47,7 @@ func InitOptionMap() {
common
.
OptionMap
[
"TurnstileSiteKey"
]
=
""
common
.
OptionMap
[
"TurnstileSecretKey"
]
=
""
common
.
OptionMap
[
"QuotaForNewUser"
]
=
strconv
.
Itoa
(
common
.
QuotaForNewUser
)
common
.
OptionMap
[
"BytesNumber2Quota"
]
=
strconv
.
FormatFloat
(
common
.
BytesNumber2Quota
,
'f'
,
-
1
,
64
)
common
.
OptionMap
[
"TopUpLink"
]
=
common
.
TopUpLink
common
.
OptionMapRWMutex
.
Unlock
()
options
,
_
:=
AllOption
()
...
...
@@ -135,6 +136,8 @@ func updateOptionMap(key string, value string) {
common
.
TurnstileSecretKey
=
value
case
"QuotaForNewUser"
:
common
.
QuotaForNewUser
,
_
=
strconv
.
Atoi
(
value
)
case
"BytesNumber2Quota"
:
common
.
BytesNumber2Quota
,
_
=
strconv
.
ParseFloat
(
value
,
64
)
case
"TopUpLink"
:
common
.
TopUpLink
=
value
}
...
...
web/src/components/SystemSetting.js
View file @
0760dcf6
...
...
@@ -25,6 +25,7 @@ const SystemSetting = () => {
TurnstileSecretKey
:
''
,
RegisterEnabled
:
''
,
QuotaForNewUser
:
0
,
BytesNumber2Quota
:
0.8
,
TopUpLink
:
''
});
let
originInputs
=
{};
...
...
@@ -90,6 +91,7 @@ const SystemSetting = () => {
name
===
'TurnstileSiteKey'
||
name
===
'TurnstileSecretKey'
||
name
===
'QuotaForNewUser'
||
name
===
'BytesNumber2Quota'
||
name
===
'TopUpLink'
)
{
setInputs
((
inputs
)
=>
({
...
inputs
,
[
name
]:
value
}));
...
...
@@ -107,6 +109,9 @@ const SystemSetting = () => {
if
(
originInputs
[
'QuotaForNewUser'
]
!==
inputs
.
QuotaForNewUser
)
{
await
updateOption
(
'QuotaForNewUser'
,
inputs
.
QuotaForNewUser
);
}
if
(
originInputs
[
'BytesNumber2Quota'
]
!==
inputs
.
BytesNumber2Quota
)
{
await
updateOption
(
'BytesNumber2Quota'
,
inputs
.
BytesNumber2Quota
);
}
if
(
originInputs
[
'TopUpLink'
]
!==
inputs
.
TopUpLink
)
{
await
updateOption
(
'TopUpLink'
,
inputs
.
TopUpLink
);
}
...
...
@@ -256,6 +261,17 @@ const SystemSetting = () => {
placeholder
=
'例如:100'
/>
<
Form
.
Input
label
=
'Stream 模式下估算 token 时所使用的倍率'
name
=
'BytesNumber2Quota'
onChange
=
{
handleInputChange
}
autoComplete
=
'off'
value
=
{
inputs
.
BytesNumber2Quota
}
type
=
'number'
step
=
'0.01'
min
=
'0'
placeholder
=
'例如:0.8'
/>
<
Form
.
Input
label
=
'充值链接'
name
=
'TopUpLink'
onChange
=
{
handleInputChange
}
...
...
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