From b0b88a79ff8c2a3da8f01f9e2fed96d4a6ea4534 Mon Sep 17 00:00:00 2001 From: shaoyun Date: Thu, 7 Nov 2024 23:51:17 +0800 Subject: [PATCH 1/2] feat: added support for Claude 3.5 Haiku (#1912) --- relay/adaptor/anthropic/constants.go | 1 + relay/adaptor/aws/claude/main.go | 1 + relay/billing/ratio/model.go | 1 + web/air/src/pages/Channel/EditChannel.js | 2 +- 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/relay/adaptor/anthropic/constants.go b/relay/adaptor/anthropic/constants.go index 9b4469b29..393264433 100644 --- a/relay/adaptor/anthropic/constants.go +++ b/relay/adaptor/anthropic/constants.go @@ -3,6 +3,7 @@ package anthropic var ModelList = []string{ "claude-instant-1.2", "claude-2.0", "claude-2.1", "claude-3-haiku-20240307", + "claude-3-5-haiku-20241022", "claude-3-sonnet-20240229", "claude-3-opus-20240229", "claude-3-5-sonnet-20240620", diff --git a/relay/adaptor/aws/claude/main.go b/relay/adaptor/aws/claude/main.go index f1a49ec3a..20de7038a 100644 --- a/relay/adaptor/aws/claude/main.go +++ b/relay/adaptor/aws/claude/main.go @@ -34,6 +34,7 @@ var AwsModelIDMap = map[string]string{ "claude-3-5-sonnet-20241022": "anthropic.claude-3-5-sonnet-20241022-v2:0", "claude-3-opus-20240229": "anthropic.claude-3-opus-20240229-v1:0", "claude-3-haiku-20240307": "anthropic.claude-3-haiku-20240307-v1:0", + "claude-3-5-haiku-20241022": "anthropic.claude-3-5-haiku-20241022-v1:0", } func awsModelID(requestModel string) (string, error) { diff --git a/relay/billing/ratio/model.go b/relay/billing/ratio/model.go index 00f5bd0a0..789f31718 100644 --- a/relay/billing/ratio/model.go +++ b/relay/billing/ratio/model.go @@ -79,6 +79,7 @@ var ModelRatio = map[string]float64{ "claude-2.0": 8.0 / 1000 * USD, "claude-2.1": 8.0 / 1000 * USD, "claude-3-haiku-20240307": 0.25 / 1000 * USD, + "claude-3-5-haiku-20241022": 1.0 / 1000 * USD, "claude-3-sonnet-20240229": 3.0 / 1000 * USD, "claude-3-5-sonnet-20240620": 3.0 / 1000 * USD, "claude-3-5-sonnet-20241022": 3.0 / 1000 * USD, diff --git a/web/air/src/pages/Channel/EditChannel.js b/web/air/src/pages/Channel/EditChannel.js index fa1ab2768..ffed94a0d 100644 --- a/web/air/src/pages/Channel/EditChannel.js +++ b/web/air/src/pages/Channel/EditChannel.js @@ -63,7 +63,7 @@ const EditChannel = (props) => { let localModels = []; switch (value) { case 14: - localModels = ["claude-instant-1.2", "claude-2", "claude-2.0", "claude-2.1", "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-haiku-20240307", "claude-3-5-sonnet-20240620", "claude-3-5-sonnet-20241022"]; + localModels = ["claude-instant-1.2", "claude-2", "claude-2.0", "claude-2.1", "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-haiku-20240307", "claude-3-5-haiku-20241022", "claude-3-5-sonnet-20240620", "claude-3-5-sonnet-20241022"]; break; case 11: localModels = ['PaLM-2']; From 8ec092ba44b15c5c7f4e41264d596c207886791c Mon Sep 17 00:00:00 2001 From: Ryo Shen <5581972+lwshen@users.noreply.github.com> Date: Thu, 7 Nov 2024 23:52:38 +0800 Subject: [PATCH 2/2] feat: add support for xAI (#1915) --- README.md | 1 + relay/adaptor/openai/compatible.go | 6 +++++- relay/adaptor/xai/constants.go | 5 +++++ relay/billing/ratio/model.go | 4 ++++ relay/channeltype/define.go | 1 + relay/channeltype/url.go | 3 ++- web/air/src/constants/channel.constants.js | 1 + web/berry/src/constants/ChannelConstants.js | 6 ++++++ web/berry/src/views/Channel/type/Config.js | 3 +++ web/default/src/constants/channel.constants.js | 1 + 10 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 relay/adaptor/xai/constants.go diff --git a/README.md b/README.md index 5f9947b0a..f27a67944 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,7 @@ _✨ 通过标准的 OpenAI API 格式访问所有的大模型,开箱即用 + [x] [together.ai](https://www.together.ai/) + [x] [novita.ai](https://www.novita.ai/) + [x] [硅基流动 SiliconCloud](https://siliconflow.cn/siliconcloud) + + [x] [xAI](https://x.ai/) 2. 支持配置镜像以及众多[第三方代理服务](https://iamazing.cn/page/openai-api-third-party-services)。 3. 支持通过**负载均衡**的方式访问多个渠道。 4. 支持 **stream 模式**,可以通过流式传输实现打字机效果。 diff --git a/relay/adaptor/openai/compatible.go b/relay/adaptor/openai/compatible.go index 0512f05ca..15b4dcc03 100644 --- a/relay/adaptor/openai/compatible.go +++ b/relay/adaptor/openai/compatible.go @@ -11,9 +11,10 @@ import ( "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/siliconflow" "github.com/songquanpeng/one-api/relay/adaptor/stepfun" "github.com/songquanpeng/one-api/relay/adaptor/togetherai" - "github.com/songquanpeng/one-api/relay/adaptor/siliconflow" + "github.com/songquanpeng/one-api/relay/adaptor/xai" "github.com/songquanpeng/one-api/relay/channeltype" ) @@ -32,6 +33,7 @@ var CompatibleChannels = []int{ channeltype.TogetherAI, channeltype.Novita, channeltype.SiliconFlow, + channeltype.XAI, } func GetCompatibleChannelMeta(channelType int) (string, []string) { @@ -64,6 +66,8 @@ func GetCompatibleChannelMeta(channelType int) (string, []string) { return "novita", novita.ModelList case channeltype.SiliconFlow: return "siliconflow", siliconflow.ModelList + case channeltype.XAI: + return "xai", xai.ModelList default: return "openai", ModelList } diff --git a/relay/adaptor/xai/constants.go b/relay/adaptor/xai/constants.go new file mode 100644 index 000000000..9082b999a --- /dev/null +++ b/relay/adaptor/xai/constants.go @@ -0,0 +1,5 @@ +package xai + +var ModelList = []string{ + "grok-beta", +} diff --git a/relay/billing/ratio/model.go b/relay/billing/ratio/model.go index 789f31718..1b58ec090 100644 --- a/relay/billing/ratio/model.go +++ b/relay/billing/ratio/model.go @@ -209,6 +209,8 @@ var ModelRatio = map[string]float64{ "deepl-zh": 25.0 / 1000 * USD, "deepl-en": 25.0 / 1000 * USD, "deepl-ja": 25.0 / 1000 * USD, + // https://console.x.ai/ + "grok-beta": 5.0 / 1000 * USD, } var CompletionRatio = map[string]float64{ @@ -373,6 +375,8 @@ func GetCompletionRatio(name string, channelType int) float64 { return 3 case "command-r-plus": return 5 + case "grok-beta": + return 3 } return 1 } diff --git a/relay/channeltype/define.go b/relay/channeltype/define.go index a261cff85..98316959a 100644 --- a/relay/channeltype/define.go +++ b/relay/channeltype/define.go @@ -46,5 +46,6 @@ const ( VertextAI Proxy SiliconFlow + XAI Dummy ) diff --git a/relay/channeltype/url.go b/relay/channeltype/url.go index 8727faea1..b8bd61f89 100644 --- a/relay/channeltype/url.go +++ b/relay/channeltype/url.go @@ -45,7 +45,8 @@ var ChannelBaseURLs = []string{ "https://api.novita.ai/v3/openai", // 41 "", // 42 "", // 43 - "https://api.siliconflow.cn", // 44 + "https://api.siliconflow.cn", // 44 + "https://api.x.ai", // 45 } func init() { diff --git a/web/air/src/constants/channel.constants.js b/web/air/src/constants/channel.constants.js index 04fe94f17..a7e984ecf 100644 --- a/web/air/src/constants/channel.constants.js +++ b/web/air/src/constants/channel.constants.js @@ -30,6 +30,7 @@ export const CHANNEL_OPTIONS = [ { key: 42, text: 'VertexAI', value: 42, color: 'blue' }, { key: 43, text: 'Proxy', value: 43, color: 'blue' }, { key: 44, text: 'SiliconFlow', value: 44, color: 'blue' }, + { key: 45, text: 'xAI', value: 45, 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' }, diff --git a/web/berry/src/constants/ChannelConstants.js b/web/berry/src/constants/ChannelConstants.js index 98ea7ca57..353988752 100644 --- a/web/berry/src/constants/ChannelConstants.js +++ b/web/berry/src/constants/ChannelConstants.js @@ -179,6 +179,12 @@ export const CHANNEL_OPTIONS = { value: 44, color: 'primary' }, + 45: { + key: 45, + text: 'xAI', + value: 45, + color: 'primary' + }, 41: { key: 41, text: 'Novita', diff --git a/web/berry/src/views/Channel/type/Config.js b/web/berry/src/views/Channel/type/Config.js index 1fa67364b..32ffec321 100644 --- a/web/berry/src/views/Channel/type/Config.js +++ b/web/berry/src/views/Channel/type/Config.js @@ -223,6 +223,9 @@ const typeConfig = { }, modelGroup: 'anthropic' }, + 45: { + modelGroup: 'xai' + }, }; export { defaultConfig, typeConfig }; diff --git a/web/default/src/constants/channel.constants.js b/web/default/src/constants/channel.constants.js index 04e361a1f..5b25577d4 100644 --- a/web/default/src/constants/channel.constants.js +++ b/web/default/src/constants/channel.constants.js @@ -30,6 +30,7 @@ export const CHANNEL_OPTIONS = [ { key: 42, text: 'VertexAI', value: 42, color: 'blue' }, { key: 43, text: 'Proxy', value: 43, color: 'blue' }, { key: 44, text: 'SiliconFlow', value: 44, color: 'blue' }, + { key: 45, text: 'xAI', value: 45, 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' },