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
b5d644d5
authored
Mar 13, 2025
by
Calcium-Ion
Committed by
GitHub
Mar 13, 2025
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #857 from asjfoajs/main
Refactor: Optimize the ImageHandler under the Alibaba large model to …
parents
47c29779
63aa548c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
7 deletions
+5
-7
relay/channel/ali/image.go
+5
-7
No files found.
relay/channel/ali/image.go
View file @
b5d644d5
...
...
@@ -26,7 +26,7 @@ func oaiImage2Ali(request dto.ImageRequest) *AliImageRequest {
return
&
imageRequest
}
func
updateTask
(
info
*
relaycommon
.
RelayInfo
,
taskID
string
,
key
string
)
(
*
AliResponse
,
error
,
[]
byte
)
{
func
updateTask
(
info
*
relaycommon
.
RelayInfo
,
taskID
string
)
(
*
AliResponse
,
error
,
[]
byte
)
{
url
:=
fmt
.
Sprintf
(
"%s/api/v1/tasks/%s"
,
info
.
BaseUrl
,
taskID
)
var
aliResponse
AliResponse
...
...
@@ -36,7 +36,7 @@ func updateTask(info *relaycommon.RelayInfo, taskID string, key string) (*AliRes
return
&
aliResponse
,
err
,
nil
}
req
.
Header
.
Set
(
"Authorization"
,
"Bearer "
+
k
ey
)
req
.
Header
.
Set
(
"Authorization"
,
"Bearer "
+
info
.
ApiK
ey
)
client
:=
&
http
.
Client
{}
resp
,
err
:=
client
.
Do
(
req
)
...
...
@@ -58,7 +58,7 @@ func updateTask(info *relaycommon.RelayInfo, taskID string, key string) (*AliRes
return
&
response
,
nil
,
responseBody
}
func
asyncTaskWait
(
info
*
relaycommon
.
RelayInfo
,
taskID
string
,
key
string
)
(
*
AliResponse
,
[]
byte
,
error
)
{
func
asyncTaskWait
(
info
*
relaycommon
.
RelayInfo
,
taskID
string
)
(
*
AliResponse
,
[]
byte
,
error
)
{
waitSeconds
:=
3
step
:=
0
maxStep
:=
20
...
...
@@ -68,7 +68,7 @@ func asyncTaskWait(info *relaycommon.RelayInfo, taskID string, key string) (*Ali
for
{
step
++
rsp
,
err
,
body
:=
updateTask
(
info
,
taskID
,
key
)
rsp
,
err
,
body
:=
updateTask
(
info
,
taskID
)
responseBody
=
body
if
err
!=
nil
{
return
&
taskResponse
,
responseBody
,
err
...
...
@@ -125,8 +125,6 @@ func responseAli2OpenAIImage(c *gin.Context, response *AliResponse, info *relayc
}
func
aliImageHandler
(
c
*
gin
.
Context
,
resp
*
http
.
Response
,
info
*
relaycommon
.
RelayInfo
)
(
*
dto
.
OpenAIErrorWithStatusCode
,
*
dto
.
Usage
)
{
apiKey
:=
c
.
Request
.
Header
.
Get
(
"Authorization"
)
apiKey
=
strings
.
TrimPrefix
(
apiKey
,
"Bearer "
)
responseFormat
:=
c
.
GetString
(
"response_format"
)
var
aliTaskResponse
AliResponse
...
...
@@ -148,7 +146,7 @@ func aliImageHandler(c *gin.Context, resp *http.Response, info *relaycommon.Rela
return
service
.
OpenAIErrorWrapper
(
errors
.
New
(
aliTaskResponse
.
Message
),
"ali_async_task_failed"
,
http
.
StatusInternalServerError
),
nil
}
aliResponse
,
_
,
err
:=
asyncTaskWait
(
info
,
aliTaskResponse
.
Output
.
TaskId
,
apiKey
)
aliResponse
,
_
,
err
:=
asyncTaskWait
(
info
,
aliTaskResponse
.
Output
.
TaskId
)
if
err
!=
nil
{
return
service
.
OpenAIErrorWrapper
(
err
,
"ali_async_task_wait_failed"
,
http
.
StatusInternalServerError
),
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