From e0df8bbbda4176b6027f0f5843a4dcc66997add7 Mon Sep 17 00:00:00 2001 From: CaIon <1808837298@qq.com> Date: Thu, 16 May 2024 19:03:42 +0800 Subject: [PATCH] feat: support minimax --- common/constants.go | 1 + relay/channel/lingyiwanwu/constrants.go | 20 ++++++++++-------- relay/channel/minimax/constants.go | 13 ++++++++++++ relay/channel/minimax/relay-minimax.go | 10 +++++++++ relay/channel/moonshot/constants.go | 2 ++ relay/channel/openai/adaptor.go | 28 ++++++++++++++++++++++--- 6 files changed, 62 insertions(+), 12 deletions(-) create mode 100644 relay/channel/minimax/constants.go create mode 100644 relay/channel/minimax/relay-minimax.go diff --git a/common/constants.go b/common/constants.go index cb58391..b231831 100644 --- a/common/constants.go +++ b/common/constants.go @@ -208,6 +208,7 @@ const ( ChannelTypeLingYiWanWu = 31 ChannelTypeAws = 33 ChannelTypeCohere = 34 + ChannelTypeMiniMax = 35 ChannelTypeDummy // this one is only for count, do not add any channel after this ) diff --git a/relay/channel/lingyiwanwu/constrants.go b/relay/channel/lingyiwanwu/constrants.go index 2cab505..8fa9cd9 100644 --- a/relay/channel/lingyiwanwu/constrants.go +++ b/relay/channel/lingyiwanwu/constrants.go @@ -1,9 +1,11 @@ -package lingyiwanwu - -// https://platform.lingyiwanwu.com/docs - -var ModelList = []string{ - "yi-34b-chat-0205", - "yi-34b-chat-200k", - "yi-vl-plus", -} +package lingyiwanwu + +// https://platform.lingyiwanwu.com/docs + +var ModelList = []string{ + "yi-34b-chat-0205", + "yi-34b-chat-200k", + "yi-vl-plus", +} + +var ChannelName = "lingyiwanwu" diff --git a/relay/channel/minimax/constants.go b/relay/channel/minimax/constants.go new file mode 100644 index 0000000..c480cac --- /dev/null +++ b/relay/channel/minimax/constants.go @@ -0,0 +1,13 @@ +package minimax + +// https://www.minimaxi.com/document/guides/chat-model/V2?id=65e0736ab2845de20908e2dd + +var ModelList = []string{ + "abab6.5-chat", + "abab6.5s-chat", + "abab6-chat", + "abab5.5-chat", + "abab5.5s-chat", +} + +var ChannelName = "minimax" diff --git a/relay/channel/minimax/relay-minimax.go b/relay/channel/minimax/relay-minimax.go new file mode 100644 index 0000000..d0a15b0 --- /dev/null +++ b/relay/channel/minimax/relay-minimax.go @@ -0,0 +1,10 @@ +package minimax + +import ( + "fmt" + relaycommon "one-api/relay/common" +) + +func GetRequestURL(info *relaycommon.RelayInfo) (string, error) { + return fmt.Sprintf("%s/v1/text/chatcompletion_v2", info.BaseUrl), nil +} diff --git a/relay/channel/moonshot/constants.go b/relay/channel/moonshot/constants.go index 1b86f0f..a7da54b 100644 --- a/relay/channel/moonshot/constants.go +++ b/relay/channel/moonshot/constants.go @@ -5,3 +5,5 @@ var ModelList = []string{ "moonshot-v1-32k", "moonshot-v1-128k", } + +var ChannelName = "moonshot" diff --git a/relay/channel/openai/adaptor.go b/relay/channel/openai/adaptor.go index a450c71..46d827a 100644 --- a/relay/channel/openai/adaptor.go +++ b/relay/channel/openai/adaptor.go @@ -11,6 +11,7 @@ import ( "one-api/relay/channel" "one-api/relay/channel/ai360" "one-api/relay/channel/lingyiwanwu" + "one-api/relay/channel/minimax" "one-api/relay/channel/moonshot" relaycommon "one-api/relay/common" "one-api/service" @@ -26,7 +27,8 @@ func (a *Adaptor) Init(info *relaycommon.RelayInfo, request dto.GeneralOpenAIReq } func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) { - if info.ChannelType == common.ChannelTypeAzure { + switch info.ChannelType { + case common.ChannelTypeAzure: // https://learn.microsoft.com/en-us/azure/cognitive-services/openai/chatgpt-quickstart?pivots=rest-api&tabs=command-line#rest-api requestURL := strings.Split(info.RequestURLPath, "?")[0] requestURL = fmt.Sprintf("%s?api-version=%s", requestURL, info.ApiVersion) @@ -37,8 +39,15 @@ func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) { requestURL = fmt.Sprintf("/openai/deployments/%s/%s", model_, task) return relaycommon.GetFullRequestURL(info.BaseUrl, requestURL, info.ChannelType), nil + case common.ChannelTypeMiniMax: + return minimax.GetRequestURL(info) + //case common.ChannelTypeCustom: + // url := info.BaseUrl + // url = strings.Replace(url, "{model}", info.UpstreamModelName, -1) + // return url, nil + default: + return relaycommon.GetFullRequestURL(info.BaseUrl, info.RequestURLPath, info.ChannelType), nil } - return relaycommon.GetFullRequestURL(info.BaseUrl, info.RequestURLPath, info.ChannelType), nil } func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Request, info *relaycommon.RelayInfo) error { @@ -90,11 +99,24 @@ func (a *Adaptor) GetModelList() []string { return moonshot.ModelList case common.ChannelTypeLingYiWanWu: return lingyiwanwu.ModelList + case common.ChannelTypeMiniMax: + return minimax.ModelList default: return ModelList } } func (a *Adaptor) GetChannelName() string { - return ChannelName + switch a.ChannelType { + case common.ChannelType360: + return ai360.ChannelName + case common.ChannelTypeMoonshot: + return moonshot.ChannelName + case common.ChannelTypeLingYiWanWu: + return lingyiwanwu.ChannelName + case common.ChannelTypeMiniMax: + return minimax.ChannelName + default: + return ChannelName + } }