From aec343dc387111eee9728c10d733da84b832d3cc Mon Sep 17 00:00:00 2001 From: MaricoHan <92877246+MaricoHan@users.noreply.github.com> Date: Sun, 29 Oct 2023 22:03:01 +0800 Subject: [PATCH 1/5] feat: support xunfei v3 (#637) --- controller/relay-xunfei.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controller/relay-xunfei.go b/controller/relay-xunfei.go index cbaf38feeb34d..91fb6042bb080 100644 --- a/controller/relay-xunfei.go +++ b/controller/relay-xunfei.go @@ -298,8 +298,8 @@ func getXunfeiAuthUrl(c *gin.Context, apiKey string, apiSecret string) (string, common.SysLog("api_version not found, use default: " + apiVersion) } domain := "general" - if apiVersion == "v2.1" { - domain = "generalv2" + if apiVersion != "v1.1" { + domain += strings.Split(apiVersion, ".")[0] } authUrl := buildXunfeiAuthUrl(fmt.Sprintf("wss://spark-api.xf-yun.com/%s/chat", apiVersion), apiKey, apiSecret) return domain, authUrl From 0d87de697c53b921da75d86aeeaff36130dd75a4 Mon Sep 17 00:00:00 2001 From: Baksi Date: Thu, 2 Nov 2023 22:24:22 +0800 Subject: [PATCH 2/5] fix: fix typo (#651) --- controller/model.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controller/model.go b/controller/model.go index e5f3fdbeead72..ed35b7a694b60 100644 --- a/controller/model.go +++ b/controller/model.go @@ -274,7 +274,7 @@ func init() { Id: "claude-instant-1", Object: "model", Created: 1677649963, - OwnedBy: "anturopic", + OwnedBy: "anthropic", Permission: permission, Root: "claude-instant-1", Parent: nil, @@ -283,7 +283,7 @@ func init() { Id: "claude-2", Object: "model", Created: 1677649963, - OwnedBy: "anturopic", + OwnedBy: "anthropic", Permission: permission, Root: "claude-2", Parent: nil, From c70c614018a5992890564cba28d3d6172c8f71b3 Mon Sep 17 00:00:00 2001 From: papersnake Date: Sun, 5 Nov 2023 17:59:38 +0800 Subject: [PATCH 3/5] feat: support chatglm_turbo (#648) * feat: support chatglm_turbo * fix: remove characterglm --- common/model-ratio.go | 1 + controller/model.go | 9 +++++++++ web/src/pages/Channel/EditChannel.js | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/common/model-ratio.go b/common/model-ratio.go index f52e1101229bc..8f4be8c3ca182 100644 --- a/common/model-ratio.go +++ b/common/model-ratio.go @@ -49,6 +49,7 @@ var ModelRatio = map[string]float64{ "ERNIE-Bot-4": 8.572, // ¥0.12 / 1k tokens "Embedding-V1": 0.1429, // ¥0.002 / 1k tokens "PaLM-2": 1, + "chatglm_turbo": 0.3572, // ¥0.005 / 1k tokens "chatglm_pro": 0.7143, // ¥0.01 / 1k tokens "chatglm_std": 0.3572, // ¥0.005 / 1k tokens "chatglm_lite": 0.1429, // ¥0.002 / 1k tokens diff --git a/controller/model.go b/controller/model.go index ed35b7a694b60..2a7dc538c1b9e 100644 --- a/controller/model.go +++ b/controller/model.go @@ -333,6 +333,15 @@ func init() { Root: "PaLM-2", Parent: nil, }, + { + Id: "chatglm_turbo", + Object: "model", + Created: 1677649963, + OwnedBy: "zhipu", + Permission: permission, + Root: "chatglm_turbo", + Parent: nil, + }, { Id: "chatglm_pro", Object: "model", diff --git a/web/src/pages/Channel/EditChannel.js b/web/src/pages/Channel/EditChannel.js index 3b059d7b5fb06..654a5d51c2378 100644 --- a/web/src/pages/Channel/EditChannel.js +++ b/web/src/pages/Channel/EditChannel.js @@ -72,7 +72,7 @@ const EditChannel = () => { localModels = ['qwen-turbo', 'qwen-plus', 'text-embedding-v1']; break; case 16: - localModels = ['chatglm_pro', 'chatglm_std', 'chatglm_lite']; + localModels = ['chatglm_turbo', 'chatglm_pro', 'chatglm_std', 'chatglm_lite']; break; case 18: localModels = ['SparkDesk']; From 3fe76c8af7c11b8afd8893ed2621ecc200abcb12 Mon Sep 17 00:00:00 2001 From: wood chen <95951386+woodchen-ink@users.noreply.github.com> Date: Sun, 5 Nov 2023 05:08:25 -0600 Subject: [PATCH 4/5] fix: fix Cloudflare AI Gateway channel test support (#639) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 当使用Cloudflare AI Gateway时,支持openai渠道测试 * refactor: change logic --------- Co-authored-by: JustSong --- controller/channel-test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/controller/channel-test.go b/controller/channel-test.go index ae4ab7d5fc17f..3c6c8f43788b3 100644 --- a/controller/channel-test.go +++ b/controller/channel-test.go @@ -5,14 +5,14 @@ import ( "encoding/json" "errors" "fmt" + "github.com/gin-gonic/gin" "net/http" "one-api/common" "one-api/model" "strconv" + "strings" "sync" "time" - - "github.com/gin-gonic/gin" ) func testChannel(channel *model.Channel, request ChatRequest) (err error, openaiErr *OpenAIError) { @@ -50,6 +50,8 @@ func testChannel(channel *model.Channel, request ChatRequest) (err error, openai } requestURL += "/v1/chat/completions" } + // for Cloudflare AI gateway: https://github.com/songquanpeng/one-api/pull/639 + requestURL = strings.Replace(requestURL, "/v1/v1", "/v1", 1) jsonData, err := json.Marshal(request) if err != nil { From bc7c9105f4b6cb18d7302415567d502e5681381e Mon Sep 17 00:00:00 2001 From: wzxjohn Date: Sun, 5 Nov 2023 19:15:06 +0800 Subject: [PATCH 5/5] chore: update quota calc logic (close #599) (#627) * fix: change quota calc code (close #599) Use float64 during calc and do math.Ceil after calc. This will result in the quota being used slightly more than the official standard, but it will be guaranteed that it will not be less. * chore: remove blank line --------- Co-authored-by: JustSong --- controller/relay-text.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/controller/relay-text.go b/controller/relay-text.go index 25b8bc0642c3f..a61c6f7c498c7 100644 --- a/controller/relay-text.go +++ b/controller/relay-text.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "io" + "math" "net/http" "one-api/common" "one-api/model" @@ -414,9 +415,7 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode { completionRatio := common.GetCompletionRatio(textRequest.Model) promptTokens = textResponse.Usage.PromptTokens completionTokens = textResponse.Usage.CompletionTokens - - quota = promptTokens + int(float64(completionTokens)*completionRatio) - quota = int(float64(quota) * ratio) + quota = int(math.Ceil((float64(promptTokens) + float64(completionTokens)*completionRatio) * ratio)) if ratio != 0 && quota <= 0 { quota = 1 }