From 30f373b62344614198e97dc9c5da9664a07c1d30 Mon Sep 17 00:00:00 2001 From: JustSong Date: Mon, 29 Apr 2024 22:29:13 +0800 Subject: [PATCH 1/5] fix: fix usage is empty (close #1391) --- relay/adaptor/openai/adaptor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/relay/adaptor/openai/adaptor.go b/relay/adaptor/openai/adaptor.go index 57940558..55c05e0c 100644 --- a/relay/adaptor/openai/adaptor.go +++ b/relay/adaptor/openai/adaptor.go @@ -86,7 +86,7 @@ func (a *Adaptor) DoResponse(c *gin.Context, resp *http.Response, meta *meta.Met if meta.IsStream { var responseText string err, responseText, usage = StreamHandler(c, resp, meta.Mode) - if usage == nil { + if usage == nil || usage.TotalTokens == 0 { usage = ResponseText2Usage(responseText, meta.ActualModelName, meta.PromptTokens) } } else { From 7e027d2bd04759b69b49ea17aa20d2a764abdb2a Mon Sep 17 00:00:00 2001 From: JustSong Date: Mon, 29 Apr 2024 22:35:47 +0800 Subject: [PATCH 2/5] fix: fix minimax prompt & completion tokens is empty (#1391) --- relay/adaptor/openai/adaptor.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/relay/adaptor/openai/adaptor.go b/relay/adaptor/openai/adaptor.go index 55c05e0c..2e2e4100 100644 --- a/relay/adaptor/openai/adaptor.go +++ b/relay/adaptor/openai/adaptor.go @@ -89,6 +89,10 @@ func (a *Adaptor) DoResponse(c *gin.Context, resp *http.Response, meta *meta.Met if usage == nil || usage.TotalTokens == 0 { usage = ResponseText2Usage(responseText, meta.ActualModelName, meta.PromptTokens) } + if usage.TotalTokens != 0 && usage.PromptTokens == 0 { // some channels don't return prompt tokens & completion tokens + usage.PromptTokens = meta.PromptTokens + usage.CompletionTokens = usage.TotalTokens - meta.PromptTokens + } } else { switch meta.Mode { case relaymode.ImagesGenerations: From 1f76c8055310e79cb54c85ff9665c685f3596f16 Mon Sep 17 00:00:00 2001 From: JustSong Date: Mon, 29 Apr 2024 22:49:06 +0800 Subject: [PATCH 3/5] fix: fix aws claude panic (#1384) --- relay/controller/error.go | 10 ++++++++++ relay/controller/helper.go | 3 +++ 2 files changed, 13 insertions(+) diff --git a/relay/controller/error.go b/relay/controller/error.go index 69ece3ec..29d4f125 100644 --- a/relay/controller/error.go +++ b/relay/controller/error.go @@ -53,6 +53,16 @@ func (e GeneralErrorResponse) ToMessage() string { } func RelayErrorHandler(resp *http.Response) (ErrorWithStatusCode *model.ErrorWithStatusCode) { + if resp == nil { + return &model.ErrorWithStatusCode{ + StatusCode: 500, + Error: model.Error{ + Message: "resp is nil", + Type: "upstream_error", + Code: "bad_response", + }, + } + } ErrorWithStatusCode = &model.ErrorWithStatusCode{ StatusCode: resp.StatusCode, Error: model.Error{ diff --git a/relay/controller/helper.go b/relay/controller/helper.go index 2489652c..dccff486 100644 --- a/relay/controller/helper.go +++ b/relay/controller/helper.go @@ -208,6 +208,9 @@ func getMappedModelName(modelName string, mapping map[string]string) (string, bo func isErrorHappened(meta *meta.Meta, resp *http.Response) bool { if resp == nil { + if meta.ChannelType == channeltype.AwsClaude { + return false + } return true } if resp.StatusCode != http.StatusOK { From 71f4403fd51d0a83cb6e8fb792fcaee562173199 Mon Sep 17 00:00:00 2001 From: JustSong Date: Tue, 30 Apr 2024 02:16:53 +0800 Subject: [PATCH 4/5] feat: add together.ai support (#1298) --- README.md | 1 + relay/adaptor/openai/compatible.go | 4 ++++ relay/adaptor/togetherai/constants.go | 10 ++++++++++ relay/channeltype/define.go | 1 + relay/channeltype/url.go | 1 + web/berry/src/constants/ChannelConstants.js | 6 ++++++ web/default/src/constants/channel.constants.js | 1 + 7 files changed, 24 insertions(+) create mode 100644 relay/adaptor/togetherai/constants.go diff --git a/README.md b/README.md index e57dd11b..40f6e4e0 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,7 @@ _✨ 通过标准的 OpenAI API 格式访问所有的大模型,开箱即用 + [x] [DeepSeek](https://www.deepseek.com/) + [x] [Cloudflare Workers AI](https://developers.cloudflare.com/workers-ai/) + [x] [DeepL](https://www.deepl.com/) + + [x] [together.ai](https://www.together.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 ae8449db..0116a2eb 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/mistral" "github.com/songquanpeng/one-api/relay/adaptor/moonshot" "github.com/songquanpeng/one-api/relay/adaptor/stepfun" + "github.com/songquanpeng/one-api/relay/adaptor/togetherai" "github.com/songquanpeng/one-api/relay/channeltype" ) @@ -24,6 +25,7 @@ var CompatibleChannels = []int{ channeltype.LingYiWanWu, channeltype.StepFun, channeltype.DeepSeek, + channeltype.TogetherAI, } func GetCompatibleChannelMeta(channelType int) (string, []string) { @@ -48,6 +50,8 @@ func GetCompatibleChannelMeta(channelType int) (string, []string) { return "stepfun", stepfun.ModelList case channeltype.DeepSeek: return "deepseek", deepseek.ModelList + case channeltype.TogetherAI: + return "together.ai", togetherai.ModelList default: return "openai", ModelList } diff --git a/relay/adaptor/togetherai/constants.go b/relay/adaptor/togetherai/constants.go new file mode 100644 index 00000000..0a79fbdc --- /dev/null +++ b/relay/adaptor/togetherai/constants.go @@ -0,0 +1,10 @@ +package togetherai + +// https://docs.together.ai/docs/inference-models + +var ModelList = []string{ + "meta-llama/Llama-3-70b-chat-hf", + "deepseek-ai/deepseek-coder-33b-instruct", + "mistralai/Mixtral-8x22B-Instruct-v0.1", + "Qwen/Qwen1.5-72B-Chat", +} diff --git a/relay/channeltype/define.go b/relay/channeltype/define.go index 84d074a6..60964565 100644 --- a/relay/channeltype/define.go +++ b/relay/channeltype/define.go @@ -40,6 +40,7 @@ const ( DeepSeek Cloudflare DeepL + TogetherAI Dummy ) diff --git a/relay/channeltype/url.go b/relay/channeltype/url.go index e4d7fbc9..f5767f47 100644 --- a/relay/channeltype/url.go +++ b/relay/channeltype/url.go @@ -40,6 +40,7 @@ var ChannelBaseURLs = []string{ "https://api.deepseek.com", // 36 "https://api.cloudflare.com", // 37 "https://api-free.deepl.com", // 38 + "https://api.together.xyz", // 39 } func init() { diff --git a/web/berry/src/constants/ChannelConstants.js b/web/berry/src/constants/ChannelConstants.js index b7a720ef..e6b0aed5 100644 --- a/web/berry/src/constants/ChannelConstants.js +++ b/web/berry/src/constants/ChannelConstants.js @@ -143,6 +143,12 @@ export const CHANNEL_OPTIONS = { value: 38, color: 'primary' }, + 39: { + key: 39, + text: 'together.ai', + value: 39, + color: 'primary' + }, 8: { key: 8, text: '自定义渠道', diff --git a/web/default/src/constants/channel.constants.js b/web/default/src/constants/channel.constants.js index 9d7c7fa0..43ee51b7 100644 --- a/web/default/src/constants/channel.constants.js +++ b/web/default/src/constants/channel.constants.js @@ -24,6 +24,7 @@ export const CHANNEL_OPTIONS = [ {key: 36, text: 'DeepSeek', value: 36, color: 'black'}, {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: 8, text: '自定义渠道', value: 8, color: 'pink'}, {key: 22, text: '知识库:FastGPT', value: 22, color: 'blue'}, {key: 21, text: '知识库:AI Proxy', value: 21, color: 'purple'}, From 2720e1a3583219743a557610ca38d8f32592bc66 Mon Sep 17 00:00:00 2001 From: JustSong Date: Tue, 30 Apr 2024 02:23:14 +0800 Subject: [PATCH 5/5] feat: support minimax's 6.5 models (close #1395) --- relay/adaptor/minimax/constants.go | 8 ++++++-- relay/billing/ratio/model.go | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/relay/adaptor/minimax/constants.go b/relay/adaptor/minimax/constants.go index c3da5b2d..1b2fc104 100644 --- a/relay/adaptor/minimax/constants.go +++ b/relay/adaptor/minimax/constants.go @@ -1,7 +1,11 @@ package minimax +// https://www.minimaxi.com/document/guides/chat-model/V2?id=65e0736ab2845de20908e2dd + var ModelList = []string{ - "abab5.5s-chat", - "abab5.5-chat", + "abab6.5-chat", + "abab6.5s-chat", "abab6-chat", + "abab5.5-chat", + "abab5.5s-chat", } diff --git a/relay/billing/ratio/model.go b/relay/billing/ratio/model.go index fd9f2a4b..f87e7742 100644 --- a/relay/billing/ratio/model.go +++ b/relay/billing/ratio/model.go @@ -138,6 +138,8 @@ var ModelRatio = map[string]float64{ "Baichuan2-Turbo-192k": 0.016 * RMB, "Baichuan2-53B": 0.02 * RMB, // https://api.minimax.chat/document/price + "abab6.5-chat": 0.03 * RMB, + "abab6.5s-chat": 0.01 * RMB, "abab6-chat": 0.1 * RMB, "abab5.5-chat": 0.015 * RMB, "abab5.5s-chat": 0.005 * RMB,