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
d7b34f08
authored
Jul 17, 2024
by
CalciumIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: image relay
parent
363ae951
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
13 additions
and
9 deletions
+13
-9
controller/relay.go
+2
-2
relay/channel/openai/adaptor.go
+3
-2
relay/relay-audio.go
+2
-2
relay/relay-image.go
+0
-0
relay/relay-text.go
+5
-2
relay/relay_rerank.go
+1
-1
No files found.
controller/relay.go
View file @
d7b34f08
...
...
@@ -22,13 +22,13 @@ func relayHandler(c *gin.Context, relayMode int) *dto.OpenAIErrorWithStatusCode
var
err
*
dto
.
OpenAIErrorWithStatusCode
switch
relayMode
{
case
relayconstant
.
RelayModeImagesGenerations
:
err
=
relay
.
Relay
ImageHelper
(
c
,
relayMode
)
err
=
relay
.
ImageHelper
(
c
,
relayMode
)
case
relayconstant
.
RelayModeAudioSpeech
:
fallthrough
case
relayconstant
.
RelayModeAudioTranslation
:
fallthrough
case
relayconstant
.
RelayModeAudioTranscription
:
err
=
relay
.
AudioHelper
(
c
,
relayMode
)
err
=
relay
.
AudioHelper
(
c
)
case
relayconstant
.
RelayModeRerank
:
err
=
relay
.
RerankHelper
(
c
,
relayMode
)
default
:
...
...
relay/channel/openai/adaptor.go
View file @
d7b34f08
...
...
@@ -122,8 +122,7 @@ func (a *Adaptor) ConvertAudioRequest(c *gin.Context, info *relaycommon.RelayInf
}
func
(
a
*
Adaptor
)
ConvertImageRequest
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
,
request
dto
.
ImageRequest
)
(
any
,
error
)
{
//TODO implement me
return
nil
,
errors
.
New
(
"not implemented"
)
return
request
,
nil
}
func
(
a
*
Adaptor
)
DoRequest
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
,
requestBody
io
.
Reader
)
(
*
http
.
Response
,
error
)
{
...
...
@@ -142,6 +141,8 @@ func (a *Adaptor) DoResponse(c *gin.Context, resp *http.Response, info *relaycom
fallthrough
case
constant
.
RelayModeAudioTranscription
:
err
,
usage
=
OpenaiSTTHandler
(
c
,
resp
,
info
,
a
.
ResponseFormat
)
case
constant
.
RelayModeImagesGenerations
:
err
,
usage
=
OpenaiTTSHandler
(
c
,
resp
,
info
)
default
:
if
info
.
IsStream
{
err
,
usage
=
OpenaiStreamHandler
(
c
,
resp
,
info
)
...
...
relay/relay-audio.go
View file @
d7b34f08
...
...
@@ -46,7 +46,7 @@ func getAndValidAudioRequest(c *gin.Context, info *relaycommon.RelayInfo) (*dto.
return
audioRequest
,
nil
}
func
AudioHelper
(
c
*
gin
.
Context
,
relayMode
int
)
*
dto
.
OpenAIErrorWithStatusCode
{
func
AudioHelper
(
c
*
gin
.
Context
)
*
dto
.
OpenAIErrorWithStatusCode
{
relayInfo
:=
relaycommon
.
GenRelayInfo
(
c
)
audioRequest
,
err
:=
getAndValidAudioRequest
(
c
,
relayInfo
)
...
...
@@ -142,7 +142,7 @@ func AudioHelper(c *gin.Context, relayMode int) *dto.OpenAIErrorWithStatusCode {
return
openaiErr
}
postConsumeQuota
(
c
,
relayInfo
,
audioRequest
.
Model
,
usage
,
ratio
,
preConsumedQuota
,
userQuota
,
modelRatio
,
groupRatio
,
0
,
false
)
postConsumeQuota
(
c
,
relayInfo
,
audioRequest
.
Model
,
usage
,
ratio
,
preConsumedQuota
,
userQuota
,
modelRatio
,
groupRatio
,
0
,
false
,
""
)
return
nil
}
relay/relay-image.go
View file @
d7b34f08
This diff is collapsed.
Click to expand it.
relay/relay-text.go
View file @
d7b34f08
...
...
@@ -187,7 +187,7 @@ func TextHelper(c *gin.Context) *dto.OpenAIErrorWithStatusCode {
service
.
ResetStatusCode
(
openaiErr
,
statusCodeMappingStr
)
return
openaiErr
}
postConsumeQuota
(
c
,
relayInfo
,
textRequest
.
Model
,
usage
,
ratio
,
preConsumedQuota
,
userQuota
,
modelRatio
,
groupRatio
,
modelPrice
,
getModelPriceSuccess
)
postConsumeQuota
(
c
,
relayInfo
,
textRequest
.
Model
,
usage
,
ratio
,
preConsumedQuota
,
userQuota
,
modelRatio
,
groupRatio
,
modelPrice
,
getModelPriceSuccess
,
""
)
return
nil
}
...
...
@@ -279,7 +279,7 @@ func returnPreConsumedQuota(c *gin.Context, tokenId int, userQuota int, preConsu
func
postConsumeQuota
(
ctx
*
gin
.
Context
,
relayInfo
*
relaycommon
.
RelayInfo
,
modelName
string
,
usage
*
dto
.
Usage
,
ratio
float64
,
preConsumedQuota
int
,
userQuota
int
,
modelRatio
float64
,
groupRatio
float64
,
modelPrice
float64
,
usePrice
bool
)
{
modelPrice
float64
,
usePrice
bool
,
extraContent
string
)
{
useTimeSeconds
:=
time
.
Now
()
.
Unix
()
-
relayInfo
.
StartTime
.
Unix
()
promptTokens
:=
usage
.
PromptTokens
...
...
@@ -338,6 +338,9 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, modelN
logModel
=
"gpt-4-gizmo-*"
logContent
+=
fmt
.
Sprintf
(
",模型 %s"
,
modelName
)
}
if
extraContent
!=
""
{
logContent
+=
extraContent
}
other
:=
service
.
GenerateTextOtherInfo
(
ctx
,
relayInfo
,
modelRatio
,
groupRatio
,
completionRatio
,
modelPrice
)
model
.
RecordConsumeLog
(
ctx
,
relayInfo
.
UserId
,
relayInfo
.
ChannelId
,
promptTokens
,
completionTokens
,
logModel
,
tokenName
,
quota
,
logContent
,
relayInfo
.
TokenId
,
userQuota
,
int
(
useTimeSeconds
),
relayInfo
.
IsStream
,
other
)
...
...
relay/relay_rerank.go
View file @
d7b34f08
...
...
@@ -99,6 +99,6 @@ func RerankHelper(c *gin.Context, relayMode int) *dto.OpenAIErrorWithStatusCode
service
.
ResetStatusCode
(
openaiErr
,
statusCodeMappingStr
)
return
openaiErr
}
postConsumeQuota
(
c
,
relayInfo
,
rerankRequest
.
Model
,
usage
,
ratio
,
preConsumedQuota
,
userQuota
,
modelRatio
,
groupRatio
,
modelPrice
,
success
)
postConsumeQuota
(
c
,
relayInfo
,
rerankRequest
.
Model
,
usage
,
ratio
,
preConsumedQuota
,
userQuota
,
modelRatio
,
groupRatio
,
modelPrice
,
success
,
""
)
return
nil
}
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