feat: support minimax's models now (close #354)

This commit is contained in:
JustSong 2024-03-02 01:24:28 +08:00
parent 614c2e0442
commit df1fd9aa81
10 changed files with 71 additions and 3 deletions

View File

@ -65,6 +65,7 @@ const (
ChannelTypeGemini = 24 ChannelTypeGemini = 24
ChannelTypeMoonshot = 25 ChannelTypeMoonshot = 25
ChannelTypeBaichuan = 26 ChannelTypeBaichuan = 26
ChannelTypeMinimax = 27
) )
var ChannelBaseURLs = []string{ var ChannelBaseURLs = []string{
@ -95,6 +96,7 @@ var ChannelBaseURLs = []string{
"https://generativelanguage.googleapis.com", // 24 "https://generativelanguage.googleapis.com", // 24
"https://api.moonshot.cn", // 25 "https://api.moonshot.cn", // 25
"https://api.baichuan-ai.com", // 26 "https://api.baichuan-ai.com", // 26
"https://api.minimax.chat", // 27
} }
const ( const (

View File

@ -127,6 +127,14 @@ var ModelRatio = map[string]float64{
"moonshot-v1-8k": 0.012 * RMB, "moonshot-v1-8k": 0.012 * RMB,
"moonshot-v1-32k": 0.024 * RMB, "moonshot-v1-32k": 0.024 * RMB,
"moonshot-v1-128k": 0.06 * RMB, "moonshot-v1-128k": 0.06 * RMB,
// https://platform.baichuan-ai.com/price
"Baichuan2-Turbo": 0.008 * RMB,
"Baichuan2-Turbo-192k": 0.016 * RMB,
"Baichuan2-53B": 0.02 * RMB,
// https://api.minimax.chat/document/price
"abab6": 0.1 * RMB,
"abab5.5": 0.015 * RMB,
"abab5.5s": 0.005 * RMB,
} }
func ModelRatio2JSONString() string { func ModelRatio2JSONString() string {

View File

@ -5,6 +5,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/songquanpeng/one-api/relay/channel/ai360" "github.com/songquanpeng/one-api/relay/channel/ai360"
"github.com/songquanpeng/one-api/relay/channel/baichuan" "github.com/songquanpeng/one-api/relay/channel/baichuan"
"github.com/songquanpeng/one-api/relay/channel/minimax"
"github.com/songquanpeng/one-api/relay/channel/moonshot" "github.com/songquanpeng/one-api/relay/channel/moonshot"
"github.com/songquanpeng/one-api/relay/constant" "github.com/songquanpeng/one-api/relay/constant"
"github.com/songquanpeng/one-api/relay/helper" "github.com/songquanpeng/one-api/relay/helper"
@ -110,6 +111,17 @@ func init() {
Parent: nil, Parent: nil,
}) })
} }
for _, modelName := range minimax.ModelList {
openAIModels = append(openAIModels, OpenAIModels{
Id: modelName,
Object: "model",
Created: 1626777600,
OwnedBy: "minimax",
Permission: permission,
Root: modelName,
Parent: nil,
})
}
openAIModelsMap = make(map[string]OpenAIModels) openAIModelsMap = make(map[string]OpenAIModels)
for _, model := range openAIModels { for _, model := range openAIModels {
openAIModelsMap[model.Id] = model openAIModelsMap[model.Id] = model

View File

@ -0,0 +1,7 @@
package minimax
var ModelList = []string{
"abab5.5s-chat",
"abab5.5-chat",
"abab6-chat",
}

View File

@ -0,0 +1,14 @@
package minimax
import (
"fmt"
"github.com/songquanpeng/one-api/relay/constant"
"github.com/songquanpeng/one-api/relay/util"
)
func GetRequestURL(meta *util.RelayMeta) (string, error) {
if meta.Mode == constant.RelayModeChatCompletions {
return fmt.Sprintf("%s/v1/text/chatcompletion_v2", meta.BaseURL), nil
}
return "", fmt.Errorf("unsupported relay mode %d for minimax", meta.Mode)
}

View File

@ -8,6 +8,7 @@ import (
"github.com/songquanpeng/one-api/relay/channel" "github.com/songquanpeng/one-api/relay/channel"
"github.com/songquanpeng/one-api/relay/channel/ai360" "github.com/songquanpeng/one-api/relay/channel/ai360"
"github.com/songquanpeng/one-api/relay/channel/baichuan" "github.com/songquanpeng/one-api/relay/channel/baichuan"
"github.com/songquanpeng/one-api/relay/channel/minimax"
"github.com/songquanpeng/one-api/relay/channel/moonshot" "github.com/songquanpeng/one-api/relay/channel/moonshot"
"github.com/songquanpeng/one-api/relay/model" "github.com/songquanpeng/one-api/relay/model"
"github.com/songquanpeng/one-api/relay/util" "github.com/songquanpeng/one-api/relay/util"
@ -25,7 +26,8 @@ func (a *Adaptor) Init(meta *util.RelayMeta) {
} }
func (a *Adaptor) GetRequestURL(meta *util.RelayMeta) (string, error) { func (a *Adaptor) GetRequestURL(meta *util.RelayMeta) (string, error) {
if meta.ChannelType == common.ChannelTypeAzure { switch meta.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(meta.RequestURLPath, "?")[0] requestURL := strings.Split(meta.RequestURLPath, "?")[0]
requestURL = fmt.Sprintf("%s?api-version=%s", requestURL, meta.APIVersion) requestURL = fmt.Sprintf("%s?api-version=%s", requestURL, meta.APIVersion)
@ -39,8 +41,11 @@ func (a *Adaptor) GetRequestURL(meta *util.RelayMeta) (string, error) {
requestURL = fmt.Sprintf("/openai/deployments/%s/%s", model_, task) requestURL = fmt.Sprintf("/openai/deployments/%s/%s", model_, task)
return util.GetFullRequestURL(meta.BaseURL, requestURL, meta.ChannelType), nil return util.GetFullRequestURL(meta.BaseURL, requestURL, meta.ChannelType), nil
case common.ChannelTypeMinimax:
return minimax.GetRequestURL(meta)
default:
return util.GetFullRequestURL(meta.BaseURL, meta.RequestURLPath, meta.ChannelType), nil
} }
return util.GetFullRequestURL(meta.BaseURL, meta.RequestURLPath, meta.ChannelType), nil
} }
func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Request, meta *util.RelayMeta) error { func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Request, meta *util.RelayMeta) error {
@ -87,6 +92,8 @@ func (a *Adaptor) GetModelList() []string {
return moonshot.ModelList return moonshot.ModelList
case common.ChannelTypeBaichuan: case common.ChannelTypeBaichuan:
return baichuan.ModelList return baichuan.ModelList
case common.ChannelTypeMinimax:
return minimax.ModelList
default: default:
return ModelList return ModelList
} }
@ -102,6 +109,8 @@ func (a *Adaptor) GetChannelName() string {
return "moonshot" return "moonshot"
case common.ChannelTypeBaichuan: case common.ChannelTypeBaichuan:
return "baichuan" return "baichuan"
case common.ChannelTypeMinimax:
return "minimax"
default: default:
return "openai" return "openai"
} }

View File

@ -74,7 +74,13 @@ export const CHANNEL_OPTIONS = {
26: { 26: {
key: 26, key: 26,
text: '百川大模型', text: '百川大模型',
value: 23, value: 26,
color: 'default'
},
27: {
key: 27,
text: 'MiniMax',
value: 27,
color: 'default' color: 'default'
}, },
8: { 8: {

View File

@ -157,6 +157,12 @@ const typeConfig = {
}, },
modelGroup: "baichuan", modelGroup: "baichuan",
}, },
27: {
input: {
models: ['abab5.5s-chat', 'abab5.5-chat', 'abab6-chat'],
},
modelGroup: "minimax",
},
}; };
export { defaultConfig, typeConfig }; export { defaultConfig, typeConfig };

View File

@ -12,6 +12,7 @@ export const CHANNEL_OPTIONS = [
{ key: 25, text: 'Moonshot AI', value: 25, color: 'black' }, { key: 25, text: 'Moonshot AI', value: 25, color: 'black' },
{ key: 23, text: '腾讯混元', value: 23, color: 'teal' }, { key: 23, text: '腾讯混元', value: 23, color: 'teal' },
{ key: 26, text: '百川大模型', value: 26, color: 'orange' }, { key: 26, text: '百川大模型', value: 26, color: 'orange' },
{ key: 27, text: 'MiniMax', value: 27, color: 'red' },
{ key: 8, text: '自定义渠道', value: 8, color: 'pink' }, { key: 8, text: '自定义渠道', value: 8, color: 'pink' },
{ key: 22, text: '知识库FastGPT', value: 22, color: 'blue' }, { key: 22, text: '知识库FastGPT', value: 22, color: 'blue' },
{ key: 21, text: '知识库AI Proxy', value: 21, color: 'purple' }, { key: 21, text: '知识库AI Proxy', value: 21, color: 'purple' },

View File

@ -105,6 +105,9 @@ const EditChannel = () => {
case 26: case 26:
localModels = ['Baichuan2-Turbo', 'Baichuan2-Turbo-192k', 'Baichuan-Text-Embedding']; localModels = ['Baichuan2-Turbo', 'Baichuan2-Turbo-192k', 'Baichuan-Text-Embedding'];
break; break;
case 27:
localModels = ['abab5.5s-chat', 'abab5.5-chat', 'abab6-chat'];
break;
} }
setInputs((inputs) => ({ ...inputs, models: localModels })); setInputs((inputs) => ({ ...inputs, models: localModels }));
} }