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
af690ed0
authored
Mar 23, 2024
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 模型固定价格为空时错误使用默认价格
parent
d162d959
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
24 deletions
+24
-24
common/model-ratio.go
+19
-19
model/option.go
+4
-4
service/token_counter.go
+1
-1
No files found.
common/model-ratio.go
View file @
af690ed0
...
@@ -6,7 +6,7 @@ import (
...
@@ -6,7 +6,7 @@ import (
"time"
"time"
)
)
//
M
odelRatio
//
m
odelRatio
// https://platform.openai.com/docs/models/model-endpoint-compatibility
// https://platform.openai.com/docs/models/model-endpoint-compatibility
// https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Blfmc9dlf
// https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Blfmc9dlf
// https://openai.com/pricing
// https://openai.com/pricing
...
@@ -114,14 +114,14 @@ var DefaultModelPrice = map[string]float64{
...
@@ -114,14 +114,14 @@ var DefaultModelPrice = map[string]float64{
"swap_face"
:
0.05
,
"swap_face"
:
0.05
,
}
}
var
ModelPrice
=
map
[
string
]
float64
{}
var
modelPrice
map
[
string
]
float64
=
nil
var
ModelRatio
=
map
[
string
]
float64
{}
var
modelRatio
map
[
string
]
float64
=
nil
func
ModelPrice2JSONString
()
string
{
func
ModelPrice2JSONString
()
string
{
if
len
(
ModelPrice
)
==
0
{
if
modelPrice
==
nil
{
M
odelPrice
=
DefaultModelPrice
m
odelPrice
=
DefaultModelPrice
}
}
jsonBytes
,
err
:=
json
.
Marshal
(
M
odelPrice
)
jsonBytes
,
err
:=
json
.
Marshal
(
m
odelPrice
)
if
err
!=
nil
{
if
err
!=
nil
{
SysError
(
"error marshalling model price: "
+
err
.
Error
())
SysError
(
"error marshalling model price: "
+
err
.
Error
())
}
}
...
@@ -129,18 +129,18 @@ func ModelPrice2JSONString() string {
...
@@ -129,18 +129,18 @@ func ModelPrice2JSONString() string {
}
}
func
UpdateModelPriceByJSONString
(
jsonStr
string
)
error
{
func
UpdateModelPriceByJSONString
(
jsonStr
string
)
error
{
M
odelPrice
=
make
(
map
[
string
]
float64
)
m
odelPrice
=
make
(
map
[
string
]
float64
)
return
json
.
Unmarshal
([]
byte
(
jsonStr
),
&
M
odelPrice
)
return
json
.
Unmarshal
([]
byte
(
jsonStr
),
&
m
odelPrice
)
}
}
func
GetModelPrice
(
name
string
,
printErr
bool
)
float64
{
func
GetModelPrice
(
name
string
,
printErr
bool
)
float64
{
if
len
(
ModelPrice
)
==
0
{
if
modelPrice
==
nil
{
M
odelPrice
=
DefaultModelPrice
m
odelPrice
=
DefaultModelPrice
}
}
if
strings
.
HasPrefix
(
name
,
"gpt-4-gizmo"
)
{
if
strings
.
HasPrefix
(
name
,
"gpt-4-gizmo"
)
{
name
=
"gpt-4-gizmo-*"
name
=
"gpt-4-gizmo-*"
}
}
price
,
ok
:=
M
odelPrice
[
name
]
price
,
ok
:=
m
odelPrice
[
name
]
if
!
ok
{
if
!
ok
{
if
printErr
{
if
printErr
{
SysError
(
"model price not found: "
+
name
)
SysError
(
"model price not found: "
+
name
)
...
@@ -151,10 +151,10 @@ func GetModelPrice(name string, printErr bool) float64 {
...
@@ -151,10 +151,10 @@ func GetModelPrice(name string, printErr bool) float64 {
}
}
func
ModelRatio2JSONString
()
string
{
func
ModelRatio2JSONString
()
string
{
if
len
(
ModelRatio
)
==
0
{
if
modelRatio
==
nil
{
M
odelRatio
=
DefaultModelRatio
m
odelRatio
=
DefaultModelRatio
}
}
jsonBytes
,
err
:=
json
.
Marshal
(
M
odelRatio
)
jsonBytes
,
err
:=
json
.
Marshal
(
m
odelRatio
)
if
err
!=
nil
{
if
err
!=
nil
{
SysError
(
"error marshalling model ratio: "
+
err
.
Error
())
SysError
(
"error marshalling model ratio: "
+
err
.
Error
())
}
}
...
@@ -162,18 +162,18 @@ func ModelRatio2JSONString() string {
...
@@ -162,18 +162,18 @@ func ModelRatio2JSONString() string {
}
}
func
UpdateModelRatioByJSONString
(
jsonStr
string
)
error
{
func
UpdateModelRatioByJSONString
(
jsonStr
string
)
error
{
M
odelRatio
=
make
(
map
[
string
]
float64
)
m
odelRatio
=
make
(
map
[
string
]
float64
)
return
json
.
Unmarshal
([]
byte
(
jsonStr
),
&
M
odelRatio
)
return
json
.
Unmarshal
([]
byte
(
jsonStr
),
&
m
odelRatio
)
}
}
func
GetModelRatio
(
name
string
)
float64
{
func
GetModelRatio
(
name
string
)
float64
{
if
len
(
ModelRatio
)
==
0
{
if
modelRatio
==
nil
{
M
odelRatio
=
DefaultModelRatio
m
odelRatio
=
DefaultModelRatio
}
}
if
strings
.
HasPrefix
(
name
,
"gpt-4-gizmo"
)
{
if
strings
.
HasPrefix
(
name
,
"gpt-4-gizmo"
)
{
name
=
"gpt-4-gizmo-*"
name
=
"gpt-4-gizmo-*"
}
}
ratio
,
ok
:=
M
odelRatio
[
name
]
ratio
,
ok
:=
m
odelRatio
[
name
]
if
!
ok
{
if
!
ok
{
SysError
(
"model ratio not found: "
+
name
)
SysError
(
"model ratio not found: "
+
name
)
return
30
return
30
...
...
model/option.go
View file @
af690ed0
...
@@ -78,8 +78,8 @@ func InitOptionMap() {
...
@@ -78,8 +78,8 @@ func InitOptionMap() {
common
.
OptionMap
[
"QuotaForInvitee"
]
=
strconv
.
Itoa
(
common
.
QuotaForInvitee
)
common
.
OptionMap
[
"QuotaForInvitee"
]
=
strconv
.
Itoa
(
common
.
QuotaForInvitee
)
common
.
OptionMap
[
"QuotaRemindThreshold"
]
=
strconv
.
Itoa
(
common
.
QuotaRemindThreshold
)
common
.
OptionMap
[
"QuotaRemindThreshold"
]
=
strconv
.
Itoa
(
common
.
QuotaRemindThreshold
)
common
.
OptionMap
[
"PreConsumedQuota"
]
=
strconv
.
Itoa
(
common
.
PreConsumedQuota
)
common
.
OptionMap
[
"PreConsumedQuota"
]
=
strconv
.
Itoa
(
common
.
PreConsumedQuota
)
common
.
OptionMap
[
"
M
odelRatio"
]
=
common
.
ModelRatio2JSONString
()
common
.
OptionMap
[
"
m
odelRatio"
]
=
common
.
ModelRatio2JSONString
()
common
.
OptionMap
[
"
M
odelPrice"
]
=
common
.
ModelPrice2JSONString
()
common
.
OptionMap
[
"
m
odelPrice"
]
=
common
.
ModelPrice2JSONString
()
common
.
OptionMap
[
"GroupRatio"
]
=
common
.
GroupRatio2JSONString
()
common
.
OptionMap
[
"GroupRatio"
]
=
common
.
GroupRatio2JSONString
()
common
.
OptionMap
[
"TopUpLink"
]
=
common
.
TopUpLink
common
.
OptionMap
[
"TopUpLink"
]
=
common
.
TopUpLink
common
.
OptionMap
[
"ChatLink"
]
=
common
.
ChatLink
common
.
OptionMap
[
"ChatLink"
]
=
common
.
ChatLink
...
@@ -271,11 +271,11 @@ func updateOptionMap(key string, value string) (err error) {
...
@@ -271,11 +271,11 @@ func updateOptionMap(key string, value string) (err error) {
common
.
DataExportInterval
,
_
=
strconv
.
Atoi
(
value
)
common
.
DataExportInterval
,
_
=
strconv
.
Atoi
(
value
)
case
"DataExportDefaultTime"
:
case
"DataExportDefaultTime"
:
common
.
DataExportDefaultTime
=
value
common
.
DataExportDefaultTime
=
value
case
"
M
odelRatio"
:
case
"
m
odelRatio"
:
err
=
common
.
UpdateModelRatioByJSONString
(
value
)
err
=
common
.
UpdateModelRatioByJSONString
(
value
)
case
"GroupRatio"
:
case
"GroupRatio"
:
err
=
common
.
UpdateGroupRatioByJSONString
(
value
)
err
=
common
.
UpdateGroupRatioByJSONString
(
value
)
case
"
M
odelPrice"
:
case
"
m
odelPrice"
:
err
=
common
.
UpdateModelPriceByJSONString
(
value
)
err
=
common
.
UpdateModelPriceByJSONString
(
value
)
case
"TopUpLink"
:
case
"TopUpLink"
:
common
.
TopUpLink
=
value
common
.
TopUpLink
=
value
...
...
service/token_counter.go
View file @
af690ed0
...
@@ -29,7 +29,7 @@ func InitTokenEncoders() {
...
@@ -29,7 +29,7 @@ func InitTokenEncoders() {
if
err
!=
nil
{
if
err
!=
nil
{
common
.
FatalLog
(
fmt
.
Sprintf
(
"failed to get gpt-4 token encoder: %s"
,
err
.
Error
()))
common
.
FatalLog
(
fmt
.
Sprintf
(
"failed to get gpt-4 token encoder: %s"
,
err
.
Error
()))
}
}
for
model
,
_
:=
range
common
.
ModelRatio
{
for
model
,
_
:=
range
common
.
Default
ModelRatio
{
if
strings
.
HasPrefix
(
model
,
"gpt-3.5"
)
{
if
strings
.
HasPrefix
(
model
,
"gpt-3.5"
)
{
tokenEncoderMap
[
model
]
=
gpt35TokenEncoder
tokenEncoderMap
[
model
]
=
gpt35TokenEncoder
}
else
if
strings
.
HasPrefix
(
model
,
"gpt-4"
)
{
}
else
if
strings
.
HasPrefix
(
model
,
"gpt-4"
)
{
...
...
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