From 98669d5d480e3c7eff45b4b5e5602440141d91a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=96=E6=A2=A6=E4=B8=BA=E9=A5=AE?= Date: Sat, 8 Jun 2024 13:26:26 +0800 Subject: [PATCH] feat: add support for bytedance's doubao (#1438) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 增加豆包大模型支持 * chore: update channel options & add prompt --------- Co-authored-by: 康龙彪 Co-authored-by: JustSong --- README.md | 2 +- relay/adaptor/doubao/constants.go | 13 +++++++++++++ relay/adaptor/doubao/main.go | 14 ++++++++++++++ relay/adaptor/openai/adaptor.go | 3 +++ relay/adaptor/openai/compatible.go | 4 ++++ relay/channeltype/define.go | 2 +- relay/channeltype/url.go | 1 + web/berry/src/constants/ChannelConstants.js | 6 ++++++ web/default/src/constants/channel.constants.js | 1 + web/default/src/pages/Channel/EditChannel.js | 7 +++++++ 10 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 relay/adaptor/doubao/constants.go create mode 100644 relay/adaptor/doubao/main.go diff --git a/README.md b/README.md index 167fe5ba..a1a24e0a 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ _✨ 通过标准的 OpenAI API 格式访问所有的大模型,开箱即用 + [x] [Anthropic Claude 系列模型](https://anthropic.com) (支持 AWS Claude) + [x] [Google PaLM2/Gemini 系列模型](https://developers.generativeai.google) + [x] [Mistral 系列模型](https://mistral.ai/) + + [x] [字节跳动豆包大模型](https://console.volcengine.com/ark/region:ark+cn-beijing/model) + [x] [百度文心一言系列模型](https://cloud.baidu.com/doc/WENXINWORKSHOP/index.html) + [x] [阿里通义千问系列模型](https://help.aliyun.com/document_detail/2400395.html) + [x] [讯飞星火认知大模型](https://www.xfyun.cn/doc/spark/Web.html) @@ -76,7 +77,6 @@ _✨ 通过标准的 OpenAI API 格式访问所有的大模型,开箱即用 + [x] [腾讯混元大模型](https://cloud.tencent.com/document/product/1729) + [x] [Moonshot AI](https://platform.moonshot.cn/) + [x] [百川大模型](https://platform.baichuan-ai.com) - + [ ] [字节云雀大模型](https://www.volcengine.com/product/ark) (WIP) + [x] [MINIMAX](https://api.minimax.chat/) + [x] [Groq](https://wow.groq.com/) + [x] [Ollama](https://github.com/ollama/ollama) diff --git a/relay/adaptor/doubao/constants.go b/relay/adaptor/doubao/constants.go new file mode 100644 index 00000000..dbe819dd --- /dev/null +++ b/relay/adaptor/doubao/constants.go @@ -0,0 +1,13 @@ +package doubao + +// https://console.volcengine.com/ark/region:ark+cn-beijing/model + +var ModelList = []string{ + "Doubao-pro-128k", + "Doubao-pro-32k", + "Doubao-pro-4k", + "Doubao-lite-128k", + "Doubao-lite-32k", + "Doubao-lite-4k", + "Doubao-embedding", +} diff --git a/relay/adaptor/doubao/main.go b/relay/adaptor/doubao/main.go new file mode 100644 index 00000000..ea26e6ba --- /dev/null +++ b/relay/adaptor/doubao/main.go @@ -0,0 +1,14 @@ +package doubao + +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/api/v3/chat/completions", meta.BaseURL), nil + } + return "", fmt.Errorf("unsupported relay mode %d for doubao", meta.Mode) +} diff --git a/relay/adaptor/openai/adaptor.go b/relay/adaptor/openai/adaptor.go index 2e2e4100..db569e4f 100644 --- a/relay/adaptor/openai/adaptor.go +++ b/relay/adaptor/openai/adaptor.go @@ -5,6 +5,7 @@ import ( "fmt" "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/channeltype" "github.com/songquanpeng/one-api/relay/meta" @@ -45,6 +46,8 @@ func (a *Adaptor) GetRequestURL(meta *meta.Meta) (string, error) { return GetFullRequestURL(meta.BaseURL, requestURL, meta.ChannelType), nil case channeltype.Minimax: return minimax.GetRequestURL(meta) + case channeltype.Doubao: + return doubao.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 0116a2eb..5d5b4008 100644 --- a/relay/adaptor/openai/compatible.go +++ b/relay/adaptor/openai/compatible.go @@ -4,6 +4,7 @@ import ( "github.com/songquanpeng/one-api/relay/adaptor/ai360" "github.com/songquanpeng/one-api/relay/adaptor/baichuan" "github.com/songquanpeng/one-api/relay/adaptor/deepseek" + "github.com/songquanpeng/one-api/relay/adaptor/doubao" "github.com/songquanpeng/one-api/relay/adaptor/groq" "github.com/songquanpeng/one-api/relay/adaptor/lingyiwanwu" "github.com/songquanpeng/one-api/relay/adaptor/minimax" @@ -20,6 +21,7 @@ var CompatibleChannels = []int{ channeltype.Moonshot, channeltype.Baichuan, channeltype.Minimax, + channeltype.Doubao, channeltype.Mistral, channeltype.Groq, channeltype.LingYiWanWu, @@ -52,6 +54,8 @@ func GetCompatibleChannelMeta(channelType int) (string, []string) { return "deepseek", deepseek.ModelList case channeltype.TogetherAI: return "together.ai", togetherai.ModelList + case channeltype.Doubao: + return "doubao", doubao.ModelList default: return "openai", ModelList } diff --git a/relay/channeltype/define.go b/relay/channeltype/define.go index 60964565..d8885ae9 100644 --- a/relay/channeltype/define.go +++ b/relay/channeltype/define.go @@ -41,6 +41,6 @@ const ( Cloudflare DeepL TogetherAI - + Doubao Dummy ) diff --git a/relay/channeltype/url.go b/relay/channeltype/url.go index f5767f47..489a21de 100644 --- a/relay/channeltype/url.go +++ b/relay/channeltype/url.go @@ -41,6 +41,7 @@ var ChannelBaseURLs = []string{ "https://api.cloudflare.com", // 37 "https://api-free.deepl.com", // 38 "https://api.together.xyz", // 39 + "https://ark.cn-beijing.volces.com", // 40 } func init() { diff --git a/web/berry/src/constants/ChannelConstants.js b/web/berry/src/constants/ChannelConstants.js index 589ef1fb..52d64083 100644 --- a/web/berry/src/constants/ChannelConstants.js +++ b/web/berry/src/constants/ChannelConstants.js @@ -47,6 +47,12 @@ export const CHANNEL_OPTIONS = { value: 28, color: 'warning' }, + 40: { + key: 40, + text: '字节跳动豆包', + value: 40, + color: 'primary' + }, 15: { key: 15, text: '百度文心千帆', diff --git a/web/default/src/constants/channel.constants.js b/web/default/src/constants/channel.constants.js index 43ee51b7..f9cf2fc5 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: 40, text: '字节跳动豆包', value: 40, color: 'blue'}, {key: 15, text: '百度文心千帆', value: 15, color: 'blue'}, {key: 17, text: '阿里通义千问', value: 17, color: 'orange'}, {key: 18, text: '讯飞星火认知', value: 18, color: 'blue'}, diff --git a/web/default/src/pages/Channel/EditChannel.js b/web/default/src/pages/Channel/EditChannel.js index 5c7f13ff..ac0fed60 100644 --- a/web/default/src/pages/Channel/EditChannel.js +++ b/web/default/src/pages/Channel/EditChannel.js @@ -362,6 +362,13 @@ const EditChannel = () => { ) } + { + inputs.type === 40 && ( + + 对于豆包而言,需要手动去 模型推理页面 创建推理接入点,以接入点名称作为模型名称,例如:`ep-20240608051426-tkxvl`。 + + ) + }