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
699e29e2
authored
May 12, 2024
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 支持自定义特殊模型补全倍率
parent
a03cfe9e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
2 deletions
+54
-2
common/model-ratio.go
+31
-2
model/option.go
+3
-0
web/src/components/OperationSetting.js
+20
-0
No files found.
common/model-ratio.go
View file @
699e29e2
...
...
@@ -138,6 +138,12 @@ var DefaultModelPrice = map[string]float64{
var
modelPrice
map
[
string
]
float64
=
nil
var
modelRatio
map
[
string
]
float64
=
nil
var
CompletionRatio
map
[
string
]
float64
=
nil
var
DefaultCompletionRatio
=
map
[
string
]
float64
{
"gpt-4-gizmo-*"
:
2
,
"gpt-4-all"
:
2
,
}
func
ModelPrice2JSONString
()
string
{
if
modelPrice
==
nil
{
modelPrice
=
DefaultModelPrice
...
...
@@ -202,6 +208,22 @@ func GetModelRatio(name string) float64 {
return
ratio
}
func
CompletionRatio2JSONString
()
string
{
if
CompletionRatio
==
nil
{
CompletionRatio
=
DefaultCompletionRatio
}
jsonBytes
,
err
:=
json
.
Marshal
(
CompletionRatio
)
if
err
!=
nil
{
SysError
(
"error marshalling completion ratio: "
+
err
.
Error
())
}
return
string
(
jsonBytes
)
}
func
UpdateCompletionRatioByJSONString
(
jsonStr
string
)
error
{
CompletionRatio
=
make
(
map
[
string
]
float64
)
return
json
.
Unmarshal
([]
byte
(
jsonStr
),
&
CompletionRatio
)
}
func
GetCompletionRatio
(
name
string
)
float64
{
if
strings
.
HasPrefix
(
name
,
"gpt-3.5"
)
{
if
name
==
"gpt-3.5-turbo"
||
strings
.
HasSuffix
(
name
,
"0125"
)
{
...
...
@@ -214,7 +236,7 @@ func GetCompletionRatio(name string) float64 {
}
return
4.0
/
3.0
}
if
strings
.
HasPrefix
(
name
,
"gpt-4"
)
{
if
strings
.
HasPrefix
(
name
,
"gpt-4"
)
&&
name
!=
"gpt-4-all"
&&
!
strings
.
HasPrefix
(
name
,
"gpt-4-gizmo"
)
{
if
strings
.
HasPrefix
(
name
,
"gpt-4-turbo"
)
||
strings
.
HasSuffix
(
name
,
"preview"
)
{
return
3
}
...
...
@@ -248,7 +270,14 @@ func GetCompletionRatio(name string) float64 {
}
switch
name
{
case
"llama2-70b-4096"
:
return
0.8
/
0.7
return
0.8
/
0.64
case
"llama3-8b-8192"
:
return
2
case
"llama3-70b-8192"
:
return
0.79
/
0.59
}
if
ratio
,
ok
:=
CompletionRatio
[
name
];
ok
{
return
ratio
}
return
1
}
model/option.go
View file @
699e29e2
...
...
@@ -83,6 +83,7 @@ func InitOptionMap() {
common
.
OptionMap
[
"ModelRatio"
]
=
common
.
ModelRatio2JSONString
()
common
.
OptionMap
[
"ModelPrice"
]
=
common
.
ModelPrice2JSONString
()
common
.
OptionMap
[
"GroupRatio"
]
=
common
.
GroupRatio2JSONString
()
common
.
OptionMap
[
"CompletionRatio"
]
=
common
.
CompletionRatio2JSONString
()
common
.
OptionMap
[
"TopUpLink"
]
=
common
.
TopUpLink
common
.
OptionMap
[
"ChatLink"
]
=
common
.
ChatLink
common
.
OptionMap
[
"ChatLink2"
]
=
common
.
ChatLink2
...
...
@@ -290,6 +291,8 @@ func updateOptionMap(key string, value string) (err error) {
err
=
common
.
UpdateModelRatioByJSONString
(
value
)
case
"GroupRatio"
:
err
=
common
.
UpdateGroupRatioByJSONString
(
value
)
case
"CompletionRatio"
:
err
=
common
.
UpdateCompletionRatioByJSONString
(
value
)
case
"ModelPrice"
:
err
=
common
.
UpdateModelPriceByJSONString
(
value
)
case
"TopUpLink"
:
...
...
web/src/components/OperationSetting.js
View file @
699e29e2
...
...
@@ -20,6 +20,7 @@ const OperationSetting = () => {
PreConsumedQuota
:
0
,
StreamCacheQueueLength
:
0
,
ModelRatio
:
''
,
CompletionRatio
:
''
,
ModelPrice
:
''
,
GroupRatio
:
''
,
TopUpLink
:
''
,
...
...
@@ -68,6 +69,7 @@ const OperationSetting = () => {
if
(
item
.
key
===
'ModelRatio'
||
item
.
key
===
'GroupRatio'
||
item
.
key
===
'CompletionRatio'
||
item
.
key
===
'ModelPrice'
)
{
item
.
value
=
JSON
.
stringify
(
JSON
.
parse
(
item
.
value
),
null
,
2
);
...
...
@@ -157,6 +159,13 @@ const OperationSetting = () => {
}
await
updateOption
(
'ModelRatio'
,
inputs
.
ModelRatio
);
}
if
(
originInputs
[
'CompletionRatio'
]
!==
inputs
.
CompletionRatio
)
{
if
(
!
verifyJSON
(
inputs
.
CompletionRatio
))
{
showError
(
'模型补全倍率不是合法的 JSON 字符串'
);
return
;
}
await
updateOption
(
'CompletionRatio'
,
inputs
.
CompletionRatio
);
}
if
(
originInputs
[
'GroupRatio'
]
!==
inputs
.
GroupRatio
)
{
if
(
!
verifyJSON
(
inputs
.
GroupRatio
))
{
showError
(
'分组倍率不是合法的 JSON 字符串'
);
...
...
@@ -595,6 +604,17 @@ const OperationSetting = () => {
<
/Form.Group
>
<
Form
.
Group
widths
=
'equal'
>
<
Form
.
TextArea
label
=
'模型补全倍率(仅对自定义模型有效)'
name
=
'CompletionRatio'
onChange
=
{
handleInputChange
}
style
=
{{
minHeight
:
250
,
fontFamily
:
'JetBrains Mono, Consolas'
}}
autoComplete
=
'new-password'
value
=
{
inputs
.
CompletionRatio
}
placeholder
=
'为一个 JSON 文本,键为分组名称,值为倍率'
/>
<
/Form.Group
>
<
Form
.
Group
widths
=
'equal'
>
<
Form
.
TextArea
label
=
'分组倍率'
name
=
'GroupRatio'
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