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
06ae3efa
authored
Oct 11, 2025
by
feitianbubu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add openai sdk create
parent
c0859c05
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
4 deletions
+40
-4
middleware/distributor.go
+8
-0
relay/common/relay_utils.go
+32
-4
No files found.
middleware/distributor.go
View file @
06ae3efa
...
@@ -174,6 +174,8 @@ func getModelRequest(c *gin.Context) (*ModelRequest, bool, error) {
...
@@ -174,6 +174,8 @@ func getModelRequest(c *gin.Context) (*ModelRequest, bool, error) {
relayMode
:=
relayconstant
.
RelayModeUnknown
relayMode
:=
relayconstant
.
RelayModeUnknown
if
c
.
Request
.
Method
==
http
.
MethodPost
{
if
c
.
Request
.
Method
==
http
.
MethodPost
{
relayMode
=
relayconstant
.
RelayModeVideoSubmit
relayMode
=
relayconstant
.
RelayModeVideoSubmit
contentType
:=
c
.
Request
.
Header
.
Get
(
"Content-Type"
)
if
strings
.
HasPrefix
(
contentType
,
"multipart/form-data"
)
{
form
,
err
:=
common
.
ParseMultipartFormReusable
(
c
)
form
,
err
:=
common
.
ParseMultipartFormReusable
(
c
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
false
,
errors
.
New
(
"无效的video请求, "
+
err
.
Error
())
return
nil
,
false
,
errors
.
New
(
"无效的video请求, "
+
err
.
Error
())
...
@@ -184,6 +186,12 @@ func getModelRequest(c *gin.Context) (*ModelRequest, bool, error) {
...
@@ -184,6 +186,12 @@ func getModelRequest(c *gin.Context) (*ModelRequest, bool, error) {
modelRequest
.
Model
=
values
[
0
]
modelRequest
.
Model
=
values
[
0
]
}
}
}
}
}
else
if
strings
.
HasPrefix
(
contentType
,
"application/json"
)
{
err
=
common
.
UnmarshalBodyReusable
(
c
,
&
modelRequest
)
if
err
!=
nil
{
return
nil
,
false
,
errors
.
New
(
"无效的video请求, "
+
err
.
Error
())
}
}
}
else
if
c
.
Request
.
Method
==
http
.
MethodGet
{
}
else
if
c
.
Request
.
Method
==
http
.
MethodGet
{
relayMode
=
relayconstant
.
RelayModeVideoFetchByID
relayMode
=
relayconstant
.
RelayModeVideoFetchByID
shouldSelectChannel
=
false
shouldSelectChannel
=
false
...
...
relay/common/relay_utils.go
View file @
06ae3efa
...
@@ -106,6 +106,11 @@ func validateMultipartTaskRequest(c *gin.Context, info *RelayInfo, action string
...
@@ -106,6 +106,11 @@ func validateMultipartTaskRequest(c *gin.Context, info *RelayInfo, action string
}
}
func
ValidateMultipartDirect
(
c
*
gin
.
Context
,
info
*
RelayInfo
)
*
dto
.
TaskError
{
func
ValidateMultipartDirect
(
c
*
gin
.
Context
,
info
*
RelayInfo
)
*
dto
.
TaskError
{
contentType
:=
c
.
GetHeader
(
"Content-Type"
)
var
prompt
string
var
hasInputReference
bool
if
strings
.
HasPrefix
(
contentType
,
"multipart/form-data"
)
{
form
,
err
:=
common
.
ParseMultipartFormReusable
(
c
)
form
,
err
:=
common
.
ParseMultipartFormReusable
(
c
)
if
err
!=
nil
{
if
err
!=
nil
{
return
createTaskError
(
err
,
"invalid_multipart_form"
,
http
.
StatusBadRequest
,
true
)
return
createTaskError
(
err
,
"invalid_multipart_form"
,
http
.
StatusBadRequest
,
true
)
...
@@ -116,15 +121,38 @@ func ValidateMultipartDirect(c *gin.Context, info *RelayInfo) *dto.TaskError {
...
@@ -116,15 +121,38 @@ func ValidateMultipartDirect(c *gin.Context, info *RelayInfo) *dto.TaskError {
if
!
ok
||
len
(
prompts
)
==
0
{
if
!
ok
||
len
(
prompts
)
==
0
{
return
createTaskError
(
fmt
.
Errorf
(
"prompt field is required"
),
"missing_prompt"
,
http
.
StatusBadRequest
,
true
)
return
createTaskError
(
fmt
.
Errorf
(
"prompt field is required"
),
"missing_prompt"
,
http
.
StatusBadRequest
,
true
)
}
}
if
taskErr
:=
validatePrompt
(
prompts
[
0
]);
taskErr
!=
nil
{
prompt
=
prompts
[
0
]
return
taskErr
}
if
_
,
ok
:=
form
.
Value
[
"model"
];
!
ok
{
if
_
,
ok
:=
form
.
Value
[
"model"
];
!
ok
{
return
createTaskError
(
fmt
.
Errorf
(
"model field is required"
),
"missing_model"
,
http
.
StatusBadRequest
,
true
)
return
createTaskError
(
fmt
.
Errorf
(
"model field is required"
),
"missing_model"
,
http
.
StatusBadRequest
,
true
)
}
}
action
:=
constant
.
TaskActionTextGenerate
if
_
,
ok
:=
form
.
File
[
"input_reference"
];
ok
{
if
_
,
ok
:=
form
.
File
[
"input_reference"
];
ok
{
hasInputReference
=
true
}
}
else
{
var
req
TaskSubmitReq
if
err
:=
common
.
UnmarshalBodyReusable
(
c
,
&
req
);
err
!=
nil
{
return
createTaskError
(
err
,
"invalid_json"
,
http
.
StatusBadRequest
,
true
)
}
prompt
=
req
.
Prompt
if
strings
.
TrimSpace
(
req
.
Model
)
==
""
{
return
createTaskError
(
fmt
.
Errorf
(
"model field is required"
),
"missing_model"
,
http
.
StatusBadRequest
,
true
)
}
if
req
.
HasImage
()
{
hasInputReference
=
true
}
}
if
taskErr
:=
validatePrompt
(
prompt
);
taskErr
!=
nil
{
return
taskErr
}
action
:=
constant
.
TaskActionTextGenerate
if
hasInputReference
{
action
=
constant
.
TaskActionGenerate
action
=
constant
.
TaskActionGenerate
}
}
info
.
Action
=
action
info
.
Action
=
action
...
...
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