From 3789c30154eb6bdac918d88c98c094c9459465ce Mon Sep 17 00:00:00 2001 From: Buer <42402987+MartialBE@users.noreply.github.com> Date: Wed, 7 Feb 2024 23:30:36 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20support=20moonshot=20(#63)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/constants.go | 2 ++ common/model-ratio.go | 7 ++++-- providers/moonshot/base.go | 36 +++++++++++++++++++++++++++ web/src/constants/ChannelConstants.js | 6 +++++ web/src/views/Channel/type/Config.js | 6 +++++ 5 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 providers/moonshot/base.go diff --git a/common/constants.go b/common/constants.go index 3a1698dc..93d35b77 100644 --- a/common/constants.go +++ b/common/constants.go @@ -192,6 +192,7 @@ const ( ChannelTypeBaichuan = 26 ChannelTypeMiniMax = 27 ChannelTypeDeepseek = 28 + ChannelTypeMoonshot = 29 ) var ChannelBaseURLs = []string{ @@ -224,6 +225,7 @@ var ChannelBaseURLs = []string{ "https://api.baichuan-ai.com", //26 "https://api.minimax.chat/v1", //27 "https://api.deepseek.com", //28 + "https://api.moonshot.cn", //29 } const ( diff --git a/common/model-ratio.go b/common/model-ratio.go index 0f4044ca..91d8043e 100644 --- a/common/model-ratio.go +++ b/common/model-ratio.go @@ -84,8 +84,8 @@ func init() { "chatglm_std": {0.3572, ChannelTypeZhipu}, // ¥0.005 / 1k tokens "chatglm_lite": {0.1429, ChannelTypeZhipu}, // ¥0.002 / 1k tokens "glm-3-turbo": {0.3572, ChannelTypeZhipu}, // ¥0.005 / 1k tokens - "glm-4": {7.143, ChannelTypeZhipu}, // ¥0.1 / 1k tokens - "glm-4v": {7.143, ChannelTypeZhipu}, // ¥0.1 / 1k tokens + "glm-4": {7.143, ChannelTypeZhipu}, // ¥0.1 / 1k tokens + "glm-4v": {7.143, ChannelTypeZhipu}, // ¥0.1 / 1k tokens "embedding-2": {0.0357, ChannelTypeZhipu}, // ¥0.0005 / 1k tokens "cogview-3": {17.8571, ChannelTypeZhipu}, // ¥0.25 / 1张图片 "qwen-turbo": {0.5715, ChannelTypeAli}, // ¥0.008 / 1k tokens // https://help.aliyun.com/zh/dashscope/developer-reference/tongyi-thousand-questions-metering-and-billing @@ -110,6 +110,9 @@ func init() { "embo-01": {0.0357, ChannelTypeMiniMax}, // ¥0.0005 / 1k tokens "deepseek-coder": {0.75, ChannelTypeDeepseek}, // 暂定 $0.0015 / 1K tokens "deepseek-chat": {0.75, ChannelTypeDeepseek}, // 暂定 $0.0015 / 1K tokens + "moonshot-v1-8k": {0.8572, ChannelTypeMoonshot}, // ¥0.012 / 1K tokens + "moonshot-v1-32k": {1.7143, ChannelTypeMoonshot}, // ¥0.024 / 1K tokens + "moonshot-v1-128k": {4.2857, ChannelTypeMoonshot}, // ¥0.06 / 1K tokens } ModelRatio = make(map[string]float64) diff --git a/providers/moonshot/base.go b/providers/moonshot/base.go new file mode 100644 index 00000000..27ec7c64 --- /dev/null +++ b/providers/moonshot/base.go @@ -0,0 +1,36 @@ +package moonshot + +import ( + "one-api/common/requester" + "one-api/model" + "one-api/providers/base" + "one-api/providers/openai" +) + +type MoonshotProviderFactory struct{} + +// 创建 MoonshotProvider +func (f MoonshotProviderFactory) Create(channel *model.Channel) base.ProviderInterface { + config := getMoonshotConfig() + return &MoonshotProvider{ + OpenAIProvider: openai.OpenAIProvider{ + BaseProvider: base.BaseProvider{ + Config: config, + Channel: channel, + Requester: requester.NewHTTPRequester(*channel.Proxy, openai.RequestErrorHandle), + }, + BalanceAction: false, + }, + } +} + +func getMoonshotConfig() base.ProviderConfig { + return base.ProviderConfig{ + BaseURL: "https://api.moonshot.cn", + ChatCompletions: "/v1/chat/completions", + } +} + +type MoonshotProvider struct { + openai.OpenAIProvider +} diff --git a/web/src/constants/ChannelConstants.js b/web/src/constants/ChannelConstants.js index 926ca9c6..16831428 100644 --- a/web/src/constants/ChannelConstants.js +++ b/web/src/constants/ChannelConstants.js @@ -83,6 +83,12 @@ export const CHANNEL_OPTIONS = { value: 28, color: 'default' }, + 29: { + key: 29, + text: 'Moonshot', + value: 29, + color: 'default' + }, 24: { key: 24, text: 'Azure Speech', diff --git a/web/src/views/Channel/type/Config.js b/web/src/views/Channel/type/Config.js index b04e0597..c9facb8d 100644 --- a/web/src/views/Channel/type/Config.js +++ b/web/src/views/Channel/type/Config.js @@ -181,6 +181,12 @@ const typeConfig = { models: ['deepseek-coder', 'deepseek-chat'], test_model: 'deepseek-chat' } + }, + 29: { + input: { + models: ['moonshot-v1-8k', 'moonshot-v1-16k', 'moonshot-v1-128k'], + test_model: 'moonshot-v1-8k' + } } };