fix: kling create video via openai sdk

This commit is contained in:
feitianbubu
2025-10-11 14:37:19 +08:00
parent d724f25db4
commit d733803c8a
2 changed files with 14 additions and 15 deletions

View File

@@ -163,7 +163,6 @@ func (a *TaskAdaptor) DoResponse(c *gin.Context, resp *http.Response, info *rela
ov.TaskID = jResp.Data.TaskID ov.TaskID = jResp.Data.TaskID
ov.CreatedAt = time.Now().Unix() ov.CreatedAt = time.Now().Unix()
ov.Model = info.OriginModelName ov.Model = info.OriginModelName
ov.Metadata = map[string]any{}
c.JSON(http.StatusOK, ov) c.JSON(http.StatusOK, ov)
return jResp.Data.TaskID, responseBody, nil return jResp.Data.TaskID, responseBody, nil
} }

View File

@@ -6,13 +6,11 @@ import (
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"strconv"
"strings" "strings"
"time" "time"
"github.com/QuantumNous/new-api/model" "github.com/QuantumNous/new-api/model"
"github.com/bytedance/gopkg/util/logger"
"github.com/samber/lo" "github.com/samber/lo"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@@ -190,8 +188,12 @@ func (a *TaskAdaptor) DoResponse(c *gin.Context, resp *http.Response, info *rela
taskErr = service.TaskErrorWrapperLocal(fmt.Errorf(kResp.Message), "task_failed", http.StatusBadRequest) taskErr = service.TaskErrorWrapperLocal(fmt.Errorf(kResp.Message), "task_failed", http.StatusBadRequest)
return return
} }
kResp.TaskId = kResp.Data.TaskId ov := relaycommon.NewOpenAIVideo()
c.JSON(http.StatusOK, kResp) ov.ID = kResp.Data.TaskId
ov.TaskID = kResp.Data.TaskId
ov.CreatedAt = time.Now().Unix()
ov.Model = info.OriginModelName
c.JSON(http.StatusOK, ov)
return kResp.Data.TaskId, responseBody, nil return kResp.Data.TaskId, responseBody, nil
} }
@@ -370,20 +372,18 @@ func (a *TaskAdaptor) ConvertToOpenAIVideo(originTask *model.Task) (*relaycommon
if err := json.Unmarshal(originTask.Data, &klingResp); err != nil { if err := json.Unmarshal(originTask.Data, &klingResp); err != nil {
return nil, errors.Wrap(err, "unmarshal kling task data failed") return nil, errors.Wrap(err, "unmarshal kling task data failed")
} }
openAIVideo := &relaycommon.OpenAIVideo{
ID: klingResp.Data.TaskId, openAIVideo := relaycommon.NewOpenAIVideo()
Object: "video", openAIVideo.ID = originTask.TaskID
//Model: "kling-v1", //todo save model openAIVideo.Status = originTask.Status.ToVideoStatus()
Status: string(originTask.Status),
CreatedAt: klingResp.Data.CreatedAt,
CompletedAt: klingResp.Data.UpdatedAt,
Metadata: make(map[string]any),
}
openAIVideo.SetProgressStr(originTask.Progress) openAIVideo.SetProgressStr(originTask.Progress)
openAIVideo.CreatedAt = klingResp.Data.CreatedAt
openAIVideo.CompletedAt = klingResp.Data.UpdatedAt
if len(klingResp.Data.TaskResult.Videos) > 0 { if len(klingResp.Data.TaskResult.Videos) > 0 {
video := klingResp.Data.TaskResult.Videos[0] video := klingResp.Data.TaskResult.Videos[0]
if video.Url != "" { if video.Url != "" {
openAIVideo.Metadata["url"] = video.Url openAIVideo.SetMetadata("url", video.Url)
} }
if video.Duration != "" { if video.Duration != "" {
openAIVideo.Seconds = video.Duration openAIVideo.Seconds = video.Duration