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
0e85d0af
authored
Jun 14, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update gpt3.5 completion ratio
parent
8dda3fd2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
11 deletions
+12
-11
common/model-ratio.go
+7
-5
controller/relay.go
+5
-6
No files found.
common/model-ratio.go
View file @
0e85d0af
...
...
@@ -2,9 +2,11 @@ package common
import
"encoding/json"
// ModelRatio
// https://platform.openai.com/docs/models/model-endpoint-compatibility
// https://openai.com/pricing
// TODO: when a new api is enabled, check the pricing here
// 1 === $0.002 / 1K tokens
var
ModelRatio
=
map
[
string
]
float64
{
"gpt-4"
:
15
,
"gpt-4-0314"
:
15
,
...
...
@@ -12,11 +14,11 @@ var ModelRatio = map[string]float64{
"gpt-4-32k"
:
30
,
"gpt-4-32k-0314"
:
30
,
"gpt-4-32k-0613"
:
30
,
"gpt-3.5-turbo"
:
1
,
// $0.002
/ 1K tokens
"gpt-3.5-turbo-0301"
:
1
,
"gpt-3.5-turbo-0613"
:
1
,
"gpt-3.5-turbo-16k"
:
2
,
// $0.004
/ 1K tokens
"gpt-3.5-turbo-16k-0613"
:
2
,
"gpt-3.5-turbo"
:
0.75
,
// $0.0015
/ 1K tokens
"gpt-3.5-turbo-0301"
:
0.75
,
"gpt-3.5-turbo-0613"
:
0.75
,
"gpt-3.5-turbo-16k"
:
1.5
,
// $0.003
/ 1K tokens
"gpt-3.5-turbo-16k-0613"
:
1.5
,
"text-ada-001"
:
0.2
,
"text-babbage-001"
:
0.25
,
"text-curie-001"
:
1
,
...
...
controller/relay.go
View file @
0e85d0af
...
...
@@ -239,16 +239,15 @@ func relayHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
defer
func
()
{
if
consumeQuota
{
quota
:=
0
usingGPT4
:=
strings
.
HasPrefix
(
textRequest
.
Model
,
"gpt-4"
)
completionRatio
:=
1
if
usingGPT4
{
completionRatio
:=
1.34
// default for gpt-3
if
strings
.
HasPrefix
(
textRequest
.
Model
,
"gpt-4"
)
{
completionRatio
=
2
}
if
isStream
{
responseTokens
:=
countTokenText
(
streamResponseText
,
textRequest
.
Model
)
quota
=
promptTokens
+
responseTokens
*
completionRatio
quota
=
promptTokens
+
int
(
float64
(
responseTokens
)
*
completionRatio
)
}
else
{
quota
=
textResponse
.
Usage
.
PromptTokens
+
textResponse
.
Usage
.
CompletionTokens
*
completionRatio
quota
=
textResponse
.
Usage
.
PromptTokens
+
int
(
float64
(
textResponse
.
Usage
.
CompletionTokens
)
*
completionRatio
)
}
quota
=
int
(
float64
(
quota
)
*
ratio
)
if
ratio
!=
0
&&
quota
<=
0
{
...
...
@@ -260,7 +259,7 @@ func relayHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
common
.
SysError
(
"Error consuming token remain quota: "
+
err
.
Error
())
}
userId
:=
c
.
GetInt
(
"id"
)
model
.
RecordLog
(
userId
,
model
.
LogTypeConsume
,
fmt
.
Sprintf
(
"使用模型 %s 消耗 %d 点额度(模型倍率 %.2f,分组倍率 %.2f
)"
,
textRequest
.
Model
,
quota
,
modelRatio
,
group
Ratio
))
model
.
RecordLog
(
userId
,
model
.
LogTypeConsume
,
fmt
.
Sprintf
(
"使用模型 %s 消耗 %d 点额度(模型倍率 %.2f,分组倍率 %.2f
,补全倍率 %.2f)"
,
textRequest
.
Model
,
quota
,
modelRatio
,
groupRatio
,
completion
Ratio
))
}
}()
...
...
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