(c *gin.Context)
| 18 | ) |
| 19 | |
| 20 | func ChatCompletions(c *gin.Context) { |
| 21 | err := checkChatConfig() |
| 22 | if err != nil { |
| 23 | common.ReturnOpenAIError(c, err, "config_invalid", http.StatusInternalServerError) |
| 24 | return |
| 25 | } |
| 26 | |
| 27 | chatSubmitTemp := common.Templates["chat_stream_submit"] |
| 28 | chatTickTemp := common.Templates["chat_stream_tick"] |
| 29 | chatRespTemp := common.Templates["chat_resp"] |
| 30 | |
| 31 | var requestData common.GeneralOpenAIRequest |
| 32 | err = c.ShouldBindJSON(&requestData) |
| 33 | if err != nil { |
| 34 | common.ReturnOpenAIError(c, err, "parse_body_failed", http.StatusBadRequest) |
| 35 | return |
| 36 | } |
| 37 | isStream := requestData.Stream |
| 38 | model := ModelLuma |
| 39 | |
| 40 | chatID := "chatcmpl-" + c.GetString(middleware.RequestIdKey) |
| 41 | |
| 42 | prompt := requestData.Messages[len(requestData.Messages)-1].Content |
| 43 | |
| 44 | // do openai tools get params |
| 45 | params := make(map[string]any) |
| 46 | params["aspect_ratio"] = "16:9" |
| 47 | params["expand_prompt"] = "true" |
| 48 | params["user_prompt"] = prompt |
| 49 | |
| 50 | reqData, _ := json.Marshal(params) |
| 51 | |
| 52 | resp, err := DoRequest("POST", fmt.Sprintf(common.BaseUrl+SubmitEndpoint), bytes.NewBuffer(reqData), nil) |
| 53 | if err != nil { |
| 54 | common.ReturnOpenAIError(c, err, "parse_body_failed", http.StatusBadRequest) |
| 55 | return |
| 56 | } |
| 57 | if resp.StatusCode >= 400 { |
| 58 | // for error |
| 59 | common.ReturnOpenAIError(c, err, "parse_body_failed", http.StatusBadRequest) |
| 60 | return |
| 61 | } |
| 62 | data, err := io.ReadAll(resp.Body) |
| 63 | |
| 64 | var genTasks []VideoTask |
| 65 | err = json.Unmarshal(data, &genTasks) |
| 66 | |
| 67 | if len(genTasks) == 0 { |
| 68 | common.ReturnOpenAIError(c, err, "parse_body_failed", http.StatusBadRequest) |
| 69 | return |
| 70 | } |
| 71 | taskID := genTasks[0].ID |
| 72 | |
| 73 | timeout := time.After(time.Duration(common.ChatTimeOut) * time.Second) |
| 74 | tick := time.Tick(5 * time.Second) |
| 75 | |
| 76 | if isStream { |
| 77 | setSSEHeaders(c) |
nothing calls this directly
no test coverage detected