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
da0f19d0
authored
Jul 18, 2024
by
Calcium-Ion
Committed by
GitHub
Jul 18, 2024
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #372 from Calcium-Ion/image
refactor: image relay
parents
dc58ff04
dd91799c
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 @
da0f19d0
...
@@ -22,13 +22,13 @@ func relayHandler(c *gin.Context, relayMode int) *dto.OpenAIErrorWithStatusCode
...
@@ -22,13 +22,13 @@ func relayHandler(c *gin.Context, relayMode int) *dto.OpenAIErrorWithStatusCode
var
err
*
dto
.
OpenAIErrorWithStatusCode
var
err
*
dto
.
OpenAIErrorWithStatusCode
switch
relayMode
{
switch
relayMode
{
case
relayconstant
.
RelayModeImagesGenerations
:
case
relayconstant
.
RelayModeImagesGenerations
:
err
=
relay
.
Relay
ImageHelper
(
c
,
relayMode
)
err
=
relay
.
ImageHelper
(
c
,
relayMode
)
case
relayconstant
.
RelayModeAudioSpeech
:
case
relayconstant
.
RelayModeAudioSpeech
:
fallthrough
fallthrough
case
relayconstant
.
RelayModeAudioTranslation
:
case
relayconstant
.
RelayModeAudioTranslation
:
fallthrough
fallthrough
case
relayconstant
.
RelayModeAudioTranscription
:
case
relayconstant
.
RelayModeAudioTranscription
:
err
=
relay
.
AudioHelper
(
c
,
relayMode
)
err
=
relay
.
AudioHelper
(
c
)
case
relayconstant
.
RelayModeRerank
:
case
relayconstant
.
RelayModeRerank
:
err
=
relay
.
RerankHelper
(
c
,
relayMode
)
err
=
relay
.
RerankHelper
(
c
,
relayMode
)
default
:
default
:
...
...
relay/channel/openai/adaptor.go
View file @
da0f19d0
...
@@ -122,8 +122,7 @@ func (a *Adaptor) ConvertAudioRequest(c *gin.Context, info *relaycommon.RelayInf
...
@@ -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
)
{
func
(
a
*
Adaptor
)
ConvertImageRequest
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
,
request
dto
.
ImageRequest
)
(
any
,
error
)
{
//TODO implement me
return
request
,
nil
return
nil
,
errors
.
New
(
"not implemented"
)
}
}
func
(
a
*
Adaptor
)
DoRequest
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
,
requestBody
io
.
Reader
)
(
*
http
.
Response
,
error
)
{
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
...
@@ -142,6 +141,8 @@ func (a *Adaptor) DoResponse(c *gin.Context, resp *http.Response, info *relaycom
fallthrough
fallthrough
case
constant
.
RelayModeAudioTranscription
:
case
constant
.
RelayModeAudioTranscription
:
err
,
usage
=
OpenaiSTTHandler
(
c
,
resp
,
info
,
a
.
ResponseFormat
)
err
,
usage
=
OpenaiSTTHandler
(
c
,
resp
,
info
,
a
.
ResponseFormat
)
case
constant
.
RelayModeImagesGenerations
:
err
,
usage
=
OpenaiTTSHandler
(
c
,
resp
,
info
)
default
:
default
:
if
info
.
IsStream
{
if
info
.
IsStream
{
err
,
usage
=
OpenaiStreamHandler
(
c
,
resp
,
info
)
err
,
usage
=
OpenaiStreamHandler
(
c
,
resp
,
info
)
...
...
relay/relay-audio.go
View file @
da0f19d0
...
@@ -46,7 +46,7 @@ func getAndValidAudioRequest(c *gin.Context, info *relaycommon.RelayInfo) (*dto.
...
@@ -46,7 +46,7 @@ func getAndValidAudioRequest(c *gin.Context, info *relaycommon.RelayInfo) (*dto.
return
audioRequest
,
nil
return
audioRequest
,
nil
}
}
func
AudioHelper
(
c
*
gin
.
Context
,
relayMode
int
)
*
dto
.
OpenAIErrorWithStatusCode
{
func
AudioHelper
(
c
*
gin
.
Context
)
*
dto
.
OpenAIErrorWithStatusCode
{
relayInfo
:=
relaycommon
.
GenRelayInfo
(
c
)
relayInfo
:=
relaycommon
.
GenRelayInfo
(
c
)
audioRequest
,
err
:=
getAndValidAudioRequest
(
c
,
relayInfo
)
audioRequest
,
err
:=
getAndValidAudioRequest
(
c
,
relayInfo
)
...
@@ -142,7 +142,7 @@ func AudioHelper(c *gin.Context, relayMode int) *dto.OpenAIErrorWithStatusCode {
...
@@ -142,7 +142,7 @@ func AudioHelper(c *gin.Context, relayMode int) *dto.OpenAIErrorWithStatusCode {
return
openaiErr
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
return
nil
}
}
relay/relay-image.go
View file @
da0f19d0
This diff is collapsed.
Click to expand it.
relay/relay-text.go
View file @
da0f19d0
...
@@ -187,7 +187,7 @@ func TextHelper(c *gin.Context) *dto.OpenAIErrorWithStatusCode {
...
@@ -187,7 +187,7 @@ func TextHelper(c *gin.Context) *dto.OpenAIErrorWithStatusCode {
service
.
ResetStatusCode
(
openaiErr
,
statusCodeMappingStr
)
service
.
ResetStatusCode
(
openaiErr
,
statusCodeMappingStr
)
return
openaiErr
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
return
nil
}
}
...
@@ -279,7 +279,7 @@ func returnPreConsumedQuota(c *gin.Context, tokenId int, userQuota int, preConsu
...
@@ -279,7 +279,7 @@ func returnPreConsumedQuota(c *gin.Context, tokenId int, userQuota int, preConsu
func
postConsumeQuota
(
ctx
*
gin
.
Context
,
relayInfo
*
relaycommon
.
RelayInfo
,
modelName
string
,
func
postConsumeQuota
(
ctx
*
gin
.
Context
,
relayInfo
*
relaycommon
.
RelayInfo
,
modelName
string
,
usage
*
dto
.
Usage
,
ratio
float64
,
preConsumedQuota
int
,
userQuota
int
,
modelRatio
float64
,
groupRatio
float64
,
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
()
useTimeSeconds
:=
time
.
Now
()
.
Unix
()
-
relayInfo
.
StartTime
.
Unix
()
promptTokens
:=
usage
.
PromptTokens
promptTokens
:=
usage
.
PromptTokens
...
@@ -338,6 +338,9 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, modelN
...
@@ -338,6 +338,9 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, modelN
logModel
=
"gpt-4-gizmo-*"
logModel
=
"gpt-4-gizmo-*"
logContent
+=
fmt
.
Sprintf
(
",模型 %s"
,
modelName
)
logContent
+=
fmt
.
Sprintf
(
",模型 %s"
,
modelName
)
}
}
if
extraContent
!=
""
{
logContent
+=
", "
+
extraContent
}
other
:=
service
.
GenerateTextOtherInfo
(
ctx
,
relayInfo
,
modelRatio
,
groupRatio
,
completionRatio
,
modelPrice
)
other
:=
service
.
GenerateTextOtherInfo
(
ctx
,
relayInfo
,
modelRatio
,
groupRatio
,
completionRatio
,
modelPrice
)
model
.
RecordConsumeLog
(
ctx
,
relayInfo
.
UserId
,
relayInfo
.
ChannelId
,
promptTokens
,
completionTokens
,
logModel
,
model
.
RecordConsumeLog
(
ctx
,
relayInfo
.
UserId
,
relayInfo
.
ChannelId
,
promptTokens
,
completionTokens
,
logModel
,
tokenName
,
quota
,
logContent
,
relayInfo
.
TokenId
,
userQuota
,
int
(
useTimeSeconds
),
relayInfo
.
IsStream
,
other
)
tokenName
,
quota
,
logContent
,
relayInfo
.
TokenId
,
userQuota
,
int
(
useTimeSeconds
),
relayInfo
.
IsStream
,
other
)
...
...
relay/relay_rerank.go
View file @
da0f19d0
...
@@ -99,6 +99,6 @@ func RerankHelper(c *gin.Context, relayMode int) *dto.OpenAIErrorWithStatusCode
...
@@ -99,6 +99,6 @@ func RerankHelper(c *gin.Context, relayMode int) *dto.OpenAIErrorWithStatusCode
service
.
ResetStatusCode
(
openaiErr
,
statusCodeMappingStr
)
service
.
ResetStatusCode
(
openaiErr
,
statusCodeMappingStr
)
return
openaiErr
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
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