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
60c39f5a
authored
Nov 16, 2023
by
CaIon
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'main' into latest
parents
a7bac4f1
4454af5f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
7 deletions
+53
-7
common/model-ratio.go
+2
-0
controller/model.go
+36
-0
controller/relay-audio.go
+8
-2
controller/relay.go
+7
-5
No files found.
common/model-ratio.go
View file @
60c39f5a
...
...
@@ -39,7 +39,9 @@ var ModelRatio = map[string]float64{
"code-davinci-edit-001"
:
10
,
"whisper-1"
:
15
,
// $0.006 / minute -> $0.006 / 150 words -> $0.006 / 200 tokens -> $0.03 / 1k tokens
"tts-1"
:
7.5
,
// 1k characters -> $0.015
"tts-1-1106"
:
7.5
,
// 1k characters -> $0.015
"tts-1-hd"
:
15
,
// 1k characters -> $0.03
"tts-1-hd-1106"
:
15
,
// 1k characters -> $0.03
"davinci"
:
10
,
"curie"
:
10
,
"babbage"
:
10
,
...
...
controller/model.go
View file @
60c39f5a
...
...
@@ -91,6 +91,42 @@ func init() {
Parent
:
nil
,
},
{
Id
:
"tts-1"
,
Object
:
"model"
,
Created
:
1677649963
,
OwnedBy
:
"openai"
,
Permission
:
permission
,
Root
:
"tts-1"
,
Parent
:
nil
,
},
{
Id
:
"tts-1-1106"
,
Object
:
"model"
,
Created
:
1677649963
,
OwnedBy
:
"openai"
,
Permission
:
permission
,
Root
:
"tts-1-1106"
,
Parent
:
nil
,
},
{
Id
:
"tts-1-hd"
,
Object
:
"model"
,
Created
:
1677649963
,
OwnedBy
:
"openai"
,
Permission
:
permission
,
Root
:
"tts-1-hd"
,
Parent
:
nil
,
},
{
Id
:
"tts-1-hd-1106"
,
Object
:
"model"
,
Created
:
1677649963
,
OwnedBy
:
"openai"
,
Permission
:
permission
,
Root
:
"tts-1-hd-1106"
,
Parent
:
nil
,
},
{
Id
:
"gpt-3.5-turbo"
,
Object
:
"model"
,
Created
:
1677649963
,
...
...
controller/relay-audio.go
View file @
60c39f5a
...
...
@@ -126,12 +126,18 @@ func relayAudioHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode
defer
func
(
ctx
context
.
Context
)
{
go
func
()
{
var
quota
int
quota
:=
0
var
promptTokens
=
0
if
strings
.
HasPrefix
(
audioRequest
.
Model
,
"tts-1"
)
{
quota
=
countAudioToken
(
audioRequest
.
Input
,
audioRequest
.
Model
)
promptTokens
=
quota
}
else
{
quota
=
countAudioToken
(
audioResponse
.
Text
,
audioRequest
.
Model
)
}
quota
=
int
(
float64
(
quota
)
*
ratio
)
if
ratio
!=
0
&&
quota
<=
0
{
quota
=
1
}
quotaDelta
:=
quota
-
preConsumedQuota
err
:=
model
.
PostConsumeTokenQuota
(
tokenId
,
userQuota
,
quotaDelta
,
preConsumedQuota
,
true
)
if
err
!=
nil
{
...
...
@@ -144,7 +150,7 @@ func relayAudioHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode
if
quota
!=
0
{
tokenName
:=
c
.
GetString
(
"token_name"
)
logContent
:=
fmt
.
Sprintf
(
"模型倍率 %.2f,分组倍率 %.2f"
,
modelRatio
,
groupRatio
)
model
.
RecordConsumeLog
(
ctx
,
userId
,
channelId
,
0
,
0
,
audioRequest
.
Model
,
tokenName
,
quota
,
logContent
,
tokenId
)
model
.
RecordConsumeLog
(
ctx
,
userId
,
channelId
,
promptTokens
,
0
,
audioRequest
.
Model
,
tokenName
,
quota
,
logContent
,
tokenId
)
model
.
UpdateUserUsedQuotaAndRequestCount
(
userId
,
quota
)
channelId
:=
c
.
GetInt
(
"channel_id"
)
model
.
UpdateChannelUsedQuota
(
channelId
,
quota
)
...
...
controller/relay.go
View file @
60c39f5a
...
...
@@ -91,11 +91,13 @@ type TextRequest struct {
}
type
ImageRequest
struct
{
Model
string
`json:"model"`
Quality
string
`json:"quality"`
Prompt
string
`json:"prompt"`
N
int
`json:"n"`
Size
string
`json:"size"`
Model
string
`json:"model"`
Prompt
string
`json:"prompt"`
N
int
`json:"n"`
Size
string
`json:"size"`
Quality
string
`json:"quality,omitempty"`
ResponseFormat
string
`json:"response_format,omitempty"`
Style
string
`json:"style,omitempty"`
}
type
AudioResponse
struct
{
...
...
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