feat: support minimax

This commit is contained in:
CaIon 2024-05-16 19:03:42 +08:00
parent 5e07ff85eb
commit e0df8bbbda
6 changed files with 62 additions and 12 deletions

View File

@ -208,6 +208,7 @@ const (
ChannelTypeLingYiWanWu = 31 ChannelTypeLingYiWanWu = 31
ChannelTypeAws = 33 ChannelTypeAws = 33
ChannelTypeCohere = 34 ChannelTypeCohere = 34
ChannelTypeMiniMax = 35
ChannelTypeDummy // this one is only for count, do not add any channel after this ChannelTypeDummy // this one is only for count, do not add any channel after this
) )

View File

@ -7,3 +7,5 @@ var ModelList = []string{
"yi-34b-chat-200k", "yi-34b-chat-200k",
"yi-vl-plus", "yi-vl-plus",
} }
var ChannelName = "lingyiwanwu"

View File

@ -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"

View File

@ -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
}

View File

@ -5,3 +5,5 @@ var ModelList = []string{
"moonshot-v1-32k", "moonshot-v1-32k",
"moonshot-v1-128k", "moonshot-v1-128k",
} }
var ChannelName = "moonshot"

View File

@ -11,6 +11,7 @@ import (
"one-api/relay/channel" "one-api/relay/channel"
"one-api/relay/channel/ai360" "one-api/relay/channel/ai360"
"one-api/relay/channel/lingyiwanwu" "one-api/relay/channel/lingyiwanwu"
"one-api/relay/channel/minimax"
"one-api/relay/channel/moonshot" "one-api/relay/channel/moonshot"
relaycommon "one-api/relay/common" relaycommon "one-api/relay/common"
"one-api/service" "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) { 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 // 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 := strings.Split(info.RequestURLPath, "?")[0]
requestURL = fmt.Sprintf("%s?api-version=%s", requestURL, info.ApiVersion) 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) requestURL = fmt.Sprintf("/openai/deployments/%s/%s", model_, task)
return relaycommon.GetFullRequestURL(info.BaseUrl, requestURL, info.ChannelType), nil 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 { 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 return moonshot.ModelList
case common.ChannelTypeLingYiWanWu: case common.ChannelTypeLingYiWanWu:
return lingyiwanwu.ModelList return lingyiwanwu.ModelList
case common.ChannelTypeMiniMax:
return minimax.ModelList
default: default:
return ModelList return ModelList
} }
} }
func (a *Adaptor) GetChannelName() string { 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
}
} }