feat: add openai sdk create
This commit is contained in:
parent
c0859c056f
commit
06ae3efa19
@ -174,14 +174,22 @@ 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
|
||||||
form, err := common.ParseMultipartFormReusable(c)
|
contentType := c.Request.Header.Get("Content-Type")
|
||||||
if err != nil {
|
if strings.HasPrefix(contentType, "multipart/form-data") {
|
||||||
return nil, false, errors.New("无效的video请求, " + err.Error())
|
form, err := common.ParseMultipartFormReusable(c)
|
||||||
}
|
if err != nil {
|
||||||
defer form.RemoveAll()
|
return nil, false, errors.New("无效的video请求, " + err.Error())
|
||||||
if form != nil {
|
}
|
||||||
if values, ok := form.Value["model"]; ok && len(values) > 0 {
|
defer form.RemoveAll()
|
||||||
modelRequest.Model = values[0]
|
if form != nil {
|
||||||
|
if values, ok := form.Value["model"]; ok && len(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 {
|
||||||
|
|||||||
@ -106,25 +106,53 @@ 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 {
|
||||||
form, err := common.ParseMultipartFormReusable(c)
|
contentType := c.GetHeader("Content-Type")
|
||||||
if err != nil {
|
var prompt string
|
||||||
return createTaskError(err, "invalid_multipart_form", http.StatusBadRequest, true)
|
var hasInputReference bool
|
||||||
}
|
|
||||||
defer form.RemoveAll()
|
|
||||||
|
|
||||||
prompts, ok := form.Value["prompt"]
|
if strings.HasPrefix(contentType, "multipart/form-data") {
|
||||||
if !ok || len(prompts) == 0 {
|
form, err := common.ParseMultipartFormReusable(c)
|
||||||
return createTaskError(fmt.Errorf("prompt field is required"), "missing_prompt", http.StatusBadRequest, true)
|
if err != nil {
|
||||||
|
return createTaskError(err, "invalid_multipart_form", http.StatusBadRequest, true)
|
||||||
|
}
|
||||||
|
defer form.RemoveAll()
|
||||||
|
|
||||||
|
prompts, ok := form.Value["prompt"]
|
||||||
|
if !ok || len(prompts) == 0 {
|
||||||
|
return createTaskError(fmt.Errorf("prompt field is required"), "missing_prompt", http.StatusBadRequest, true)
|
||||||
|
}
|
||||||
|
prompt = prompts[0]
|
||||||
|
|
||||||
|
if _, ok := form.Value["model"]; !ok {
|
||||||
|
return createTaskError(fmt.Errorf("model field is required"), "missing_model", http.StatusBadRequest, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
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(prompts[0]); taskErr != nil {
|
|
||||||
|
if taskErr := validatePrompt(prompt); taskErr != nil {
|
||||||
return taskErr
|
return taskErr
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := form.Value["model"]; !ok {
|
|
||||||
return createTaskError(fmt.Errorf("model field is required"), "missing_model", http.StatusBadRequest, true)
|
|
||||||
}
|
|
||||||
action := constant.TaskActionTextGenerate
|
action := constant.TaskActionTextGenerate
|
||||||
if _, ok := form.File["input_reference"]; ok {
|
if hasInputReference {
|
||||||
action = constant.TaskActionGenerate
|
action = constant.TaskActionGenerate
|
||||||
}
|
}
|
||||||
info.Action = action
|
info.Action = action
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user