From 117c000fc99723c5b0ff38729c9a734d88ea7dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=B7=E9=BE=99=E5=BD=AA?= Date: Thu, 16 May 2024 11:23:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B1=86=E5=8C=85=E5=A4=A7?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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/default/src/constants/channel.constants.js | 1 + 7 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 relay/adaptor/doubao/constants.go create mode 100644 relay/adaptor/doubao/main.go 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/default/src/constants/channel.constants.js b/web/default/src/constants/channel.constants.js index 43ee51b7..6a773055 100644 --- a/web/default/src/constants/channel.constants.js +++ b/web/default/src/constants/channel.constants.js @@ -25,6 +25,7 @@ export const CHANNEL_OPTIONS = [ {key: 37, text: 'Cloudflare', value: 37, color: 'orange'}, {key: 38, text: 'DeepL', value: 38, color: 'black'}, {key: 39, text: 'together.ai', value: 39, color: 'blue'}, + {key: 40, text: '豆包', value: 40, color: 'blue'}, {key: 8, text: '自定义渠道', value: 8, color: 'pink'}, {key: 22, text: '知识库:FastGPT', value: 22, color: 'blue'}, {key: 21, text: '知识库:AI Proxy', value: 21, color: 'purple'},