From 3c147e1e46b22d515816986a07f2bc22597e4abc Mon Sep 17 00:00:00 2001 From: Jason Date: Sat, 6 Jul 2024 13:16:46 +0800 Subject: [PATCH] feat: add Novita AI as model provider (#1609) --- README.md | 1 + relay/adaptor/novita/constants.go | 19 +++++++++++++++++++ relay/adaptor/novita/main.go | 15 +++++++++++++++ relay/adaptor/openai/adaptor.go | 10 +++++++--- relay/adaptor/openai/compatible.go | 4 ++++ relay/channeltype/define.go | 1 + relay/channeltype/url.go | 1 + web/berry/src/constants/ChannelConstants.js | 6 ++++++ .../src/constants/channel.constants.js | 1 + 9 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 relay/adaptor/novita/constants.go create mode 100644 relay/adaptor/novita/main.go diff --git a/README.md b/README.md index e883077fc6..987fde7dac 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ _✨ 通过标准的 OpenAI API 格式访问所有的大模型,开箱即用 + [x] [Cloudflare Workers AI](https://developers.cloudflare.com/workers-ai/) + [x] [DeepL](https://www.deepl.com/) + [x] [together.ai](https://www.together.ai/) + + [x] [novita.ai](https://www.novita.ai/) 2. 支持配置镜像以及众多[第三方代理服务](https://iamazing.cn/page/openai-api-third-party-services)。 3. 支持通过**负载均衡**的方式访问多个渠道。 4. 支持 **stream 模式**,可以通过流式传输实现打字机效果。 diff --git a/relay/adaptor/novita/constants.go b/relay/adaptor/novita/constants.go new file mode 100644 index 0000000000..c6618308e2 --- /dev/null +++ b/relay/adaptor/novita/constants.go @@ -0,0 +1,19 @@ +package novita + +// https://novita.ai/llm-api + +var ModelList = []string{ + "meta-llama/llama-3-8b-instruct", + "meta-llama/llama-3-70b-instruct", + "nousresearch/hermes-2-pro-llama-3-8b", + "nousresearch/nous-hermes-llama2-13b", + "mistralai/mistral-7b-instruct", + "cognitivecomputations/dolphin-mixtral-8x22b", + "sao10k/l3-70b-euryale-v2.1", + "sophosympatheia/midnight-rose-70b", + "gryphe/mythomax-l2-13b", + "Nous-Hermes-2-Mixtral-8x7B-DPO", + "lzlv_70b", + "teknium/openhermes-2.5-mistral-7b", + "microsoft/wizardlm-2-8x22b", +} diff --git a/relay/adaptor/novita/main.go b/relay/adaptor/novita/main.go new file mode 100644 index 0000000000..80efa41286 --- /dev/null +++ b/relay/adaptor/novita/main.go @@ -0,0 +1,15 @@ +package novita + +import ( + "fmt" + + "github.com/songquanpeng/one-api/relay/meta" + "github.com/songquanpeng/one-api/relay/relaymode" +) + +func GetRequestURL(meta *meta.Meta) (string, error) { + if meta.Mode == relaymode.ChatCompletions { + return fmt.Sprintf("%s/chat/completions", meta.BaseURL), nil + } + return "", fmt.Errorf("unsupported relay mode %d for novita", meta.Mode) +} diff --git a/relay/adaptor/openai/adaptor.go b/relay/adaptor/openai/adaptor.go index db569e4f5b..5dc395adfa 100644 --- a/relay/adaptor/openai/adaptor.go +++ b/relay/adaptor/openai/adaptor.go @@ -3,17 +3,19 @@ package openai import ( "errors" "fmt" + "io" + "net/http" + "strings" + "github.com/gin-gonic/gin" "github.com/songquanpeng/one-api/relay/adaptor" "github.com/songquanpeng/one-api/relay/adaptor/doubao" "github.com/songquanpeng/one-api/relay/adaptor/minimax" + "github.com/songquanpeng/one-api/relay/adaptor/novita" "github.com/songquanpeng/one-api/relay/channeltype" "github.com/songquanpeng/one-api/relay/meta" "github.com/songquanpeng/one-api/relay/model" "github.com/songquanpeng/one-api/relay/relaymode" - "io" - "net/http" - "strings" ) type Adaptor struct { @@ -48,6 +50,8 @@ func (a *Adaptor) GetRequestURL(meta *meta.Meta) (string, error) { return minimax.GetRequestURL(meta) case channeltype.Doubao: return doubao.GetRequestURL(meta) + case channeltype.Novita: + return novita.GetRequestURL(meta) default: return GetFullRequestURL(meta.BaseURL, meta.RequestURLPath, meta.ChannelType), nil } diff --git a/relay/adaptor/openai/compatible.go b/relay/adaptor/openai/compatible.go index 5d5b40087e..3445249c2d 100644 --- a/relay/adaptor/openai/compatible.go +++ b/relay/adaptor/openai/compatible.go @@ -10,6 +10,7 @@ import ( "github.com/songquanpeng/one-api/relay/adaptor/minimax" "github.com/songquanpeng/one-api/relay/adaptor/mistral" "github.com/songquanpeng/one-api/relay/adaptor/moonshot" + "github.com/songquanpeng/one-api/relay/adaptor/novita" "github.com/songquanpeng/one-api/relay/adaptor/stepfun" "github.com/songquanpeng/one-api/relay/adaptor/togetherai" "github.com/songquanpeng/one-api/relay/channeltype" @@ -28,6 +29,7 @@ var CompatibleChannels = []int{ channeltype.StepFun, channeltype.DeepSeek, channeltype.TogetherAI, + channeltype.Novita, } func GetCompatibleChannelMeta(channelType int) (string, []string) { @@ -56,6 +58,8 @@ func GetCompatibleChannelMeta(channelType int) (string, []string) { return "together.ai", togetherai.ModelList case channeltype.Doubao: return "doubao", doubao.ModelList + case channeltype.Novita: + return "novita", novita.ModelList default: return "openai", ModelList } diff --git a/relay/channeltype/define.go b/relay/channeltype/define.go index d8885ae981..d3891c1682 100644 --- a/relay/channeltype/define.go +++ b/relay/channeltype/define.go @@ -42,5 +42,6 @@ const ( DeepL TogetherAI Doubao + Novita Dummy ) diff --git a/relay/channeltype/url.go b/relay/channeltype/url.go index 513d183bcc..5177333b6c 100644 --- a/relay/channeltype/url.go +++ b/relay/channeltype/url.go @@ -42,6 +42,7 @@ var ChannelBaseURLs = []string{ "https://api-free.deepl.com", // 38 "https://api.together.xyz", // 39 "https://ark.cn-beijing.volces.com", // 40 + "https://api.novita.ai/v3/openai", // 41 } func init() { diff --git a/web/berry/src/constants/ChannelConstants.js b/web/berry/src/constants/ChannelConstants.js index 52d64083fd..aacc8d473c 100644 --- a/web/berry/src/constants/ChannelConstants.js +++ b/web/berry/src/constants/ChannelConstants.js @@ -161,6 +161,12 @@ export const CHANNEL_OPTIONS = { value: 39, color: 'primary' }, + 41: { + key: 41, + text: 'Novita', + value: 41, + color: 'purple' + }, 8: { key: 8, text: '自定义渠道', diff --git a/web/default/src/constants/channel.constants.js b/web/default/src/constants/channel.constants.js index f9cf2fc5a7..adf50a40f0 100644 --- a/web/default/src/constants/channel.constants.js +++ b/web/default/src/constants/channel.constants.js @@ -6,6 +6,7 @@ export const CHANNEL_OPTIONS = [ {key: 11, text: 'Google PaLM2', value: 11, color: 'orange'}, {key: 24, text: 'Google Gemini', value: 24, color: 'orange'}, {key: 28, text: 'Mistral AI', value: 28, color: 'orange'}, + {key: 41, text: 'Novita', value: 41, color: 'purple'}, {key: 40, text: '字节跳动豆包', value: 40, color: 'blue'}, {key: 15, text: '百度文心千帆', value: 15, color: 'blue'}, {key: 17, text: '阿里通义千问', value: 17, color: 'orange'},