chore: opt video channel and platform
This commit is contained in:
@@ -5,8 +5,6 @@ type TaskPlatform string
|
|||||||
const (
|
const (
|
||||||
TaskPlatformSuno TaskPlatform = "suno"
|
TaskPlatformSuno TaskPlatform = "suno"
|
||||||
TaskPlatformMidjourney = "mj"
|
TaskPlatformMidjourney = "mj"
|
||||||
TaskPlatformKling TaskPlatform = "kling"
|
|
||||||
TaskPlatformJimeng TaskPlatform = "jimeng"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -428,7 +428,7 @@ func RelayTask(c *gin.Context) {
|
|||||||
func taskRelayHandler(c *gin.Context, relayMode int) *dto.TaskError {
|
func taskRelayHandler(c *gin.Context, relayMode int) *dto.TaskError {
|
||||||
var err *dto.TaskError
|
var err *dto.TaskError
|
||||||
switch relayMode {
|
switch relayMode {
|
||||||
case relayconstant.RelayModeSunoFetch, relayconstant.RelayModeSunoFetchByID, relayconstant.RelayModeKlingFetchByID:
|
case relayconstant.RelayModeSunoFetch, relayconstant.RelayModeSunoFetchByID, relayconstant.RelayModeVideoFetchByID:
|
||||||
err = relay.RelayTaskFetch(c, relayMode)
|
err = relay.RelayTaskFetch(c, relayMode)
|
||||||
default:
|
default:
|
||||||
err = relay.RelayTaskSubmit(c, relayMode)
|
err = relay.RelayTaskSubmit(c, relayMode)
|
||||||
|
|||||||
@@ -75,10 +75,10 @@ func UpdateTaskByPlatform(platform constant.TaskPlatform, taskChannelM map[int][
|
|||||||
//_ = UpdateMidjourneyTaskAll(context.Background(), tasks)
|
//_ = UpdateMidjourneyTaskAll(context.Background(), tasks)
|
||||||
case constant.TaskPlatformSuno:
|
case constant.TaskPlatformSuno:
|
||||||
_ = UpdateSunoTaskAll(context.Background(), taskChannelM, taskM)
|
_ = UpdateSunoTaskAll(context.Background(), taskChannelM, taskM)
|
||||||
case constant.TaskPlatformKling, constant.TaskPlatformJimeng:
|
|
||||||
_ = UpdateVideoTaskAll(context.Background(), platform, taskChannelM, taskM)
|
|
||||||
default:
|
default:
|
||||||
common.SysLog("未知平台")
|
if err := UpdateVideoTaskAll(context.Background(), platform, taskChannelM, taskM); err != nil {
|
||||||
|
common.SysLog(fmt.Sprintf("UpdateVideoTaskAll fail: %s", err))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -174,22 +174,13 @@ func getModelRequest(c *gin.Context) (*ModelRequest, bool, error) {
|
|||||||
c.Set("relay_mode", relayMode)
|
c.Set("relay_mode", relayMode)
|
||||||
} else if strings.Contains(c.Request.URL.Path, "/v1/video/generations") {
|
} else if strings.Contains(c.Request.URL.Path, "/v1/video/generations") {
|
||||||
err = common.UnmarshalBodyReusable(c, &modelRequest)
|
err = common.UnmarshalBodyReusable(c, &modelRequest)
|
||||||
var platform string
|
relayMode := relayconstant.RelayModeUnknown
|
||||||
var relayMode int
|
if c.Request.Method == http.MethodPost {
|
||||||
if strings.HasPrefix(modelRequest.Model, "jimeng") {
|
relayMode = relayconstant.RelayModeVideoSubmit
|
||||||
platform = string(constant.TaskPlatformJimeng)
|
} else if c.Request.Method == http.MethodGet {
|
||||||
relayMode = relayconstant.Path2RelayJimeng(c.Request.Method, c.Request.URL.Path)
|
relayMode = relayconstant.RelayModeVideoFetchByID
|
||||||
if relayMode == relayconstant.RelayModeJimengFetchByID {
|
shouldSelectChannel = false
|
||||||
shouldSelectChannel = false
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
platform = string(constant.TaskPlatformKling)
|
|
||||||
relayMode = relayconstant.Path2RelayKling(c.Request.Method, c.Request.URL.Path)
|
|
||||||
if relayMode == relayconstant.RelayModeKlingFetchByID {
|
|
||||||
shouldSelectChannel = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
c.Set("platform", platform)
|
|
||||||
c.Set("relay_mode", relayMode)
|
c.Set("relay_mode", relayMode)
|
||||||
} else if strings.HasPrefix(c.Request.URL.Path, "/v1beta/models/") || strings.HasPrefix(c.Request.URL.Path, "/v1/models/") {
|
} else if strings.HasPrefix(c.Request.URL.Path, "/v1beta/models/") || strings.HasPrefix(c.Request.URL.Path, "/v1/models/") {
|
||||||
// Gemini API 路径处理: /v1beta/models/gemini-2.0-flash:generateContent
|
// Gemini API 路径处理: /v1beta/models/gemini-2.0-flash:generateContent
|
||||||
|
|||||||
@@ -40,11 +40,8 @@ const (
|
|||||||
RelayModeSunoFetchByID
|
RelayModeSunoFetchByID
|
||||||
RelayModeSunoSubmit
|
RelayModeSunoSubmit
|
||||||
|
|
||||||
RelayModeKlingFetchByID
|
RelayModeVideoFetchByID
|
||||||
RelayModeKlingSubmit
|
RelayModeVideoSubmit
|
||||||
|
|
||||||
RelayModeJimengFetchByID
|
|
||||||
RelayModeJimengSubmit
|
|
||||||
|
|
||||||
RelayModeRerank
|
RelayModeRerank
|
||||||
|
|
||||||
@@ -145,23 +142,3 @@ func Path2RelaySuno(method, path string) int {
|
|||||||
}
|
}
|
||||||
return relayMode
|
return relayMode
|
||||||
}
|
}
|
||||||
|
|
||||||
func Path2RelayKling(method, path string) int {
|
|
||||||
relayMode := RelayModeUnknown
|
|
||||||
if method == http.MethodPost && strings.HasSuffix(path, "/video/generations") {
|
|
||||||
relayMode = RelayModeKlingSubmit
|
|
||||||
} else if method == http.MethodGet && (strings.Contains(path, "/video/generations")) {
|
|
||||||
relayMode = RelayModeKlingFetchByID
|
|
||||||
}
|
|
||||||
return relayMode
|
|
||||||
}
|
|
||||||
|
|
||||||
func Path2RelayJimeng(method, path string) int {
|
|
||||||
relayMode := RelayModeUnknown
|
|
||||||
if method == http.MethodPost && strings.HasSuffix(path, "/video/generations") {
|
|
||||||
relayMode = RelayModeJimengSubmit
|
|
||||||
} else if method == http.MethodGet && strings.Contains(path, "/video/generations/") {
|
|
||||||
relayMode = RelayModeJimengFetchByID
|
|
||||||
}
|
|
||||||
return relayMode
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package relay
|
package relay
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
"one-api/constant"
|
"one-api/constant"
|
||||||
commonconstant "one-api/constant"
|
|
||||||
"one-api/relay/channel"
|
"one-api/relay/channel"
|
||||||
"one-api/relay/channel/ali"
|
"one-api/relay/channel/ali"
|
||||||
"one-api/relay/channel/aws"
|
"one-api/relay/channel/aws"
|
||||||
@@ -34,6 +34,7 @@ import (
|
|||||||
"one-api/relay/channel/xunfei"
|
"one-api/relay/channel/xunfei"
|
||||||
"one-api/relay/channel/zhipu"
|
"one-api/relay/channel/zhipu"
|
||||||
"one-api/relay/channel/zhipu_4v"
|
"one-api/relay/channel/zhipu_4v"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetAdaptor(apiType int) channel.Adaptor {
|
func GetAdaptor(apiType int) channel.Adaptor {
|
||||||
@@ -100,16 +101,28 @@ func GetAdaptor(apiType int) channel.Adaptor {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTaskAdaptor(platform commonconstant.TaskPlatform) channel.TaskAdaptor {
|
func GetTaskPlatform(c *gin.Context) constant.TaskPlatform {
|
||||||
|
channelType := c.GetInt("channel_type")
|
||||||
|
if channelType > 0 {
|
||||||
|
return constant.TaskPlatform(strconv.Itoa(channelType))
|
||||||
|
}
|
||||||
|
return constant.TaskPlatform(c.GetString("platform"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetTaskAdaptor(platform constant.TaskPlatform) channel.TaskAdaptor {
|
||||||
switch platform {
|
switch platform {
|
||||||
//case constant.APITypeAIProxyLibrary:
|
//case constant.APITypeAIProxyLibrary:
|
||||||
// return &aiproxy.Adaptor{}
|
// return &aiproxy.Adaptor{}
|
||||||
case commonconstant.TaskPlatformSuno:
|
case constant.TaskPlatformSuno:
|
||||||
return &suno.TaskAdaptor{}
|
return &suno.TaskAdaptor{}
|
||||||
case commonconstant.TaskPlatformKling:
|
}
|
||||||
return &kling.TaskAdaptor{}
|
if channelType, err := strconv.ParseInt(string(platform), 10, 64); err == nil {
|
||||||
case commonconstant.TaskPlatformJimeng:
|
switch channelType {
|
||||||
return &taskjimeng.TaskAdaptor{}
|
case constant.ChannelTypeKling:
|
||||||
|
return &kling.TaskAdaptor{}
|
||||||
|
case constant.ChannelTypeJimeng:
|
||||||
|
return &taskjimeng.TaskAdaptor{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ Task 任务通过平台、Action 区分任务
|
|||||||
*/
|
*/
|
||||||
func RelayTaskSubmit(c *gin.Context, relayMode int) (taskErr *dto.TaskError) {
|
func RelayTaskSubmit(c *gin.Context, relayMode int) (taskErr *dto.TaskError) {
|
||||||
platform := constant.TaskPlatform(c.GetString("platform"))
|
platform := constant.TaskPlatform(c.GetString("platform"))
|
||||||
|
if platform == "" {
|
||||||
|
platform = GetTaskPlatform(c)
|
||||||
|
}
|
||||||
relayInfo := relaycommon.GenTaskRelayInfo(c)
|
relayInfo := relaycommon.GenTaskRelayInfo(c)
|
||||||
|
|
||||||
adaptor := GetTaskAdaptor(platform)
|
adaptor := GetTaskAdaptor(platform)
|
||||||
@@ -178,7 +181,7 @@ func RelayTaskSubmit(c *gin.Context, relayMode int) (taskErr *dto.TaskError) {
|
|||||||
var fetchRespBuilders = map[int]func(c *gin.Context) (respBody []byte, taskResp *dto.TaskError){
|
var fetchRespBuilders = map[int]func(c *gin.Context) (respBody []byte, taskResp *dto.TaskError){
|
||||||
relayconstant.RelayModeSunoFetchByID: sunoFetchByIDRespBodyBuilder,
|
relayconstant.RelayModeSunoFetchByID: sunoFetchByIDRespBodyBuilder,
|
||||||
relayconstant.RelayModeSunoFetch: sunoFetchRespBodyBuilder,
|
relayconstant.RelayModeSunoFetch: sunoFetchRespBodyBuilder,
|
||||||
relayconstant.RelayModeKlingFetchByID: videoFetchByIDRespBodyBuilder,
|
relayconstant.RelayModeVideoFetchByID: videoFetchByIDRespBodyBuilder,
|
||||||
}
|
}
|
||||||
|
|
||||||
func RelayTaskFetch(c *gin.Context, relayMode int) (taskResp *dto.TaskError) {
|
func RelayTaskFetch(c *gin.Context, relayMode int) (taskResp *dto.TaskError) {
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import {
|
|||||||
Sparkles
|
Sparkles
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { TASK_ACTION_GENERATE, TASK_ACTION_TEXT_GENERATE } from '../../../constants/common.constant';
|
import { TASK_ACTION_GENERATE, TASK_ACTION_TEXT_GENERATE } from '../../../constants/common.constant';
|
||||||
|
import { CHANNEL_OPTIONS } from '../../../constants/channel.constants';
|
||||||
|
|
||||||
const colors = [
|
const colors = [
|
||||||
'amber',
|
'amber',
|
||||||
@@ -121,6 +122,14 @@ const renderType = (type, t) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const renderPlatform = (platform, t) => {
|
const renderPlatform = (platform, t) => {
|
||||||
|
let option = CHANNEL_OPTIONS.find(opt => String(opt.value) === String(platform));
|
||||||
|
if (option) {
|
||||||
|
return (
|
||||||
|
<Tag color={option.color} shape='circle' prefixIcon={<Video size={14} />}>
|
||||||
|
{option.label}
|
||||||
|
</Tag>
|
||||||
|
);
|
||||||
|
}
|
||||||
switch (platform) {
|
switch (platform) {
|
||||||
case 'suno':
|
case 'suno':
|
||||||
return (
|
return (
|
||||||
@@ -128,18 +137,6 @@ const renderPlatform = (platform, t) => {
|
|||||||
Suno
|
Suno
|
||||||
</Tag>
|
</Tag>
|
||||||
);
|
);
|
||||||
case 'kling':
|
|
||||||
return (
|
|
||||||
<Tag color='orange' shape='circle' prefixIcon={<Video size={14} />}>
|
|
||||||
Kling
|
|
||||||
</Tag>
|
|
||||||
);
|
|
||||||
case 'jimeng':
|
|
||||||
return (
|
|
||||||
<Tag color='purple' shape='circle' prefixIcon={<Video size={14} />}>
|
|
||||||
Jimeng
|
|
||||||
</Tag>
|
|
||||||
);
|
|
||||||
default:
|
default:
|
||||||
return (
|
return (
|
||||||
<Tag color='white' shape='circle' prefixIcon={<HelpCircle size={14} />}>
|
<Tag color='white' shape='circle' prefixIcon={<HelpCircle size={14} />}>
|
||||||
|
|||||||
Reference in New Issue
Block a user