From daded5d5494cfdbe1e4c37ffb55eedae04130145 Mon Sep 17 00:00:00 2001 From: Zhang Minghan Date: Fri, 10 Nov 2023 20:28:46 +0800 Subject: [PATCH] add chatglm turbo model --- adapter/zhipuai/chat.go | 2 ++ adapter/zhipuai/types.go | 7 ++++--- app/src/admin/colors.ts | 1 + app/src/conf.ts | 28 +++++++++++++++------------- auth/rule.go | 4 ++-- globals/variables.go | 9 ++++++--- utils/tokenizer.go | 14 +++++++++----- 7 files changed, 39 insertions(+), 26 deletions(-) diff --git a/adapter/zhipuai/chat.go b/adapter/zhipuai/chat.go index 9edbe42..f6d9a87 100644 --- a/adapter/zhipuai/chat.go +++ b/adapter/zhipuai/chat.go @@ -18,6 +18,8 @@ func (c *ChatInstance) GetChatEndpoint(model string) string { func (c *ChatInstance) GetModel(model string) string { switch model { + case globals.ZhiPuChatGLMTurbo: + return ChatGLMTurbo case globals.ZhiPuChatGLMPro: return ChatGLMPro case globals.ZhiPuChatGLMStd: diff --git a/adapter/zhipuai/types.go b/adapter/zhipuai/types.go index 2e52def..7850e46 100644 --- a/adapter/zhipuai/types.go +++ b/adapter/zhipuai/types.go @@ -3,9 +3,10 @@ package zhipuai import "chat/globals" const ( - ChatGLMPro = "chatglm_pro" - ChatGLMStd = "chatglm_std" - ChatGLMLite = "chatglm_lite" + ChatGLMTurbo = "chatglm_turbo" + ChatGLMPro = "chatglm_pro" + ChatGLMStd = "chatglm_std" + ChatGLMLite = "chatglm_lite" ) type Payload struct { diff --git a/app/src/admin/colors.ts b/app/src/admin/colors.ts index 0969d7b..4f95329 100644 --- a/app/src/admin/colors.ts +++ b/app/src/admin/colors.ts @@ -38,6 +38,7 @@ export const modelColorMapper: Record = { "bing-balance": "#2673e7", "bing-precise": "#2673e7", + "zhipu-chatglm-turbo": "#008272", "zhipu-chatglm-pro": "#008272", "zhipu-chatglm-std": "#008272", "zhipu-chatglm-lite": "#008272", diff --git a/app/src/conf.ts b/app/src/conf.ts index d03d993..83d60bd 100644 --- a/app/src/conf.ts +++ b/app/src/conf.ts @@ -8,7 +8,7 @@ import { } from "@/utils/env.ts"; import { getMemory } from "@/utils/memory.ts"; -export const version = "3.6.16"; +export const version = "3.6.17"; export const dev: boolean = getDev(); export const deploy: boolean = true; export let rest_api: string = getRestApi(deploy); @@ -23,13 +23,10 @@ export const supportModels: Model[] = [ { id: "gpt-3.5-turbo-1106", name: "GPT-3.5 1106", free: true, auth: false }, { id: "gpt-4-0613", name: "GPT-4", free: false, auth: true }, { id: "gpt-4-1106-preview", name: "GPT-4 Turbo", free: false, auth: true }, - { id: "gpt-4-v", name: "GPT-4 Vision", free: false, auth: true }, - { id: "gpt-4-dalle", name: "GPT-4 DALLE", free: false, auth: true }, // anthropic models - { id: "claude-2", name: "Claude-2", free: true, auth: true }, - { id: "claude-1-100k", name: "Claude-1-100k", free: false, auth: true }, - { id: "claude-2-100k", name: "Claude-2-100k", free: false, auth: true }, + { id: "claude-1-100k", name: "Claude-2", free: true, auth: true }, + { id: "claude-2", name: "Claude-2-100k", free: false, auth: true }, // spark desk { id: "spark-desk-v3", name: "讯飞星火 V3", free: true, auth: true }, @@ -42,18 +39,21 @@ export const supportModels: Model[] = [ { id: "qwen-turbo-net", name: "通义千问 Turbo X", free: false, auth: true }, { id: "qwen-turbo", name: "通义千问 Turbo", free: false, auth: true }, - // google palm2 - { id: "chat-bison-001", name: "Palm2", free: true, auth: true }, - // new bing { id: "bing-creative", name: "New Bing", free: true, auth: true }, + // google palm2 + { id: "chat-bison-001", name: "Palm2", free: true, auth: true }, + // zhipu models - { id: "zhipu-chatglm-pro", name: "ChatGLM Pro", free: false, auth: true }, - { id: "zhipu-chatglm-std", name: "ChatGLM Std", free: false, auth: true }, - { id: "zhipu-chatglm-lite", name: "ChatGLM Lite", free: true, auth: true }, + { id: "zhipu-chatglm-turbo", name: "ChatGLM Turbo 32k", free: false, auth: true }, { id: "dalle", name: "DALLE2", free: true, auth: true }, + + // reverse models + { id: "gpt-4-v", name: "GPT-4 Vision", free: false, auth: true }, + { id: "gpt-4-dalle", name: "GPT-4 DALLE", free: false, auth: true }, + // high price models { id: "gpt-4-32k-0613", name: "GPT-4-32k", free: false, auth: true }, ]; @@ -67,9 +67,10 @@ export const largeContextModels = [ "claude-1-100k", "claude-2", "claude-2-100k", + "zhipu-chatglm-turbo", ]; -export const studentModels = ["claude-1-100k", "claude-2-100k"]; +export const studentModels = ["claude-1-100k", "claude-2-100k", "claude-2"]; export const planModels = [ "gpt-4-0613", @@ -77,6 +78,7 @@ export const planModels = [ "gpt-4-v", "gpt-4-all", "gpt-4-dalle", + "claude-2", "claude-1-100k", "claude-2-100k", ]; diff --git a/auth/rule.go b/auth/rule.go index 4b232d7..deea192 100644 --- a/auth/rule.go +++ b/auth/rule.go @@ -19,7 +19,7 @@ func CanEnableModel(db *sql.DB, user *User, model string) bool { return user != nil // && user.GetQuota(db) >= 1 free now case globals.Claude1100k, globals.Claude2100k: return user != nil && user.GetQuota(db) >= 1 - case globals.ZhiPuChatGLMPro, globals.ZhiPuChatGLMStd: + case globals.ZhiPuChatGLMTurbo, globals.ZhiPuChatGLMPro, globals.ZhiPuChatGLMStd: return user != nil && user.GetQuota(db) >= 1 case globals.QwenTurbo, globals.QwenPlus, globals.QwenPlusNet, globals.QwenTurboNet: return user != nil && user.GetQuota(db) >= 1 @@ -48,7 +48,7 @@ func HandleSubscriptionUsage(db *sql.DB, cache *redis.Client, user *User, model func RevertSubscriptionUsage(cache *redis.Client, user *User, model string, plan bool) { if globals.IsGPT4NativeModel(model) && plan { DecreaseSubscriptionUsage(cache, user, globals.GPT4) - } else if globals.IsClaude100KModel(model) && !plan { + } else if globals.IsClaude100KModel(model) && plan { DecreaseSubscriptionUsage(cache, user, globals.Claude2100k) } } diff --git a/globals/variables.go b/globals/variables.go index f02296b..602a57a 100644 --- a/globals/variables.go +++ b/globals/variables.go @@ -58,9 +58,9 @@ const ( GPT432k0613 = "gpt-4-32k-0613" Dalle2 = "dalle" Claude1 = "claude-1" - Claude1100k = "claude-1-100k" - Claude2 = "claude-2" - Claude2100k = "claude-2-100k" + Claude1100k = "claude-1.3" + Claude2 = "claude-1-100k" + Claude2100k = "claude-2" ClaudeSlack = "claude-slack" SparkDesk = "spark-desk-v1.5" SparkDeskV2 = "spark-desk-v2" @@ -69,6 +69,7 @@ const ( BingCreative = "bing-creative" BingBalanced = "bing-balanced" BingPrecise = "bing-precise" + ZhiPuChatGLMTurbo = "zhipu-chatglm-turbo" ZhiPuChatGLMPro = "zhipu-chatglm-pro" ZhiPuChatGLMStd = "zhipu-chatglm-std" ZhiPuChatGLMLite = "zhipu-chatglm-lite" @@ -115,6 +116,7 @@ var BingModelArray = []string{ } var ZhiPuModelArray = []string{ + ZhiPuChatGLMTurbo, ZhiPuChatGLMPro, ZhiPuChatGLMStd, ZhiPuChatGLMLite, @@ -196,6 +198,7 @@ var AllModels = []string{ BingCreative, BingBalanced, BingPrecise, + ZhiPuChatGLMTurbo, ZhiPuChatGLMPro, ZhiPuChatGLMStd, ZhiPuChatGLMLite, diff --git a/utils/tokenizer.go b/utils/tokenizer.go index caae4ed..50abe49 100644 --- a/utils/tokenizer.go +++ b/utils/tokenizer.go @@ -26,7 +26,7 @@ func GetWeightByModel(model string) int { globals.BingPrecise, globals.BingCreative, globals.BingBalanced: return 3 case globals.GPT3Turbo0301, globals.GPT3Turbo16k0301, - globals.ZhiPuChatGLMLite, globals.ZhiPuChatGLMStd, globals.ZhiPuChatGLMPro: + globals.ZhiPuChatGLMTurbo, globals.ZhiPuChatGLMLite, globals.ZhiPuChatGLMStd, globals.ZhiPuChatGLMPro: return 4 // every message follows <|start|>{role/name}\n{content}<|end|>\n default: if strings.Contains(model, globals.GPT3Turbo) { @@ -77,7 +77,9 @@ func CountInputToken(model string, v []globals.Message) float32 { case globals.GPT3Turbo, globals.GPT3Turbo0613, globals.GPT3Turbo0301, globals.GPT3TurboInstruct, globals.GPT3Turbo1106, globals.GPT3Turbo16k, globals.GPT3Turbo16k0613, globals.GPT3Turbo16k0301: return 0 - case globals.GPT4, globals.GPT4Vision, globals.GPT4All, globals.GPT4Dalle, globals.GPT40314, globals.GPT40613, globals.GPT41106Preview: + case globals.GPT41106Preview: + return float32(CountTokenPrice(v, model)) / 1000 * 0.7 * 0.6 + case globals.GPT4, globals.GPT4Vision, globals.GPT4All, globals.GPT4Dalle, globals.GPT40314, globals.GPT40613: return float32(CountTokenPrice(v, model)) / 1000 * 2.1 * 0.6 case globals.GPT432k, globals.GPT432k0613, globals.GPT432k0314: return float32(CountTokenPrice(v, model)) / 1000 * 4.2 @@ -91,7 +93,7 @@ func CountInputToken(model string, v []globals.Message) float32 { return float32(CountTokenPrice(v, model)) / 1000 * 0.8 * 0.6 case globals.ZhiPuChatGLMPro: return float32(CountTokenPrice(v, model)) / 1000 * 0.1 - case globals.ZhiPuChatGLMStd: + case globals.ZhiPuChatGLMTurbo, globals.ZhiPuChatGLMStd: return float32(CountTokenPrice(v, model)) / 1000 * 0.05 case globals.QwenTurbo, globals.QwenTurboNet: return float32(CountTokenPrice(v, model)) / 1000 * 0.08 @@ -107,7 +109,9 @@ func CountOutputToken(model string, t int) float32 { case globals.GPT3Turbo, globals.GPT3Turbo0613, globals.GPT3Turbo0301, globals.GPT3TurboInstruct, globals.GPT3Turbo1106, globals.GPT3Turbo16k, globals.GPT3Turbo16k0613, globals.GPT3Turbo16k0301: return 0 - case globals.GPT4, globals.GPT4Vision, globals.GPT4All, globals.GPT4Dalle, globals.GPT40314, globals.GPT40613, globals.GPT41106Preview: + case globals.GPT41106Preview: + return float32(t*GetWeightByModel(model)) / 1000 * 2.1 * 0.6 + case globals.GPT4, globals.GPT4Vision, globals.GPT4All, globals.GPT4Dalle, globals.GPT40314, globals.GPT40613: return float32(t*GetWeightByModel(model)) / 1000 * 4.3 * 0.6 case globals.GPT432k, globals.GPT432k0613, globals.GPT432k0314: return float32(t*GetWeightByModel(model)) / 1000 * 8.6 @@ -121,7 +125,7 @@ func CountOutputToken(model string, t int) float32 { return float32(t*GetWeightByModel(model)) / 1000 * 2.4 * 0.6 case globals.ZhiPuChatGLMPro: return float32(t*GetWeightByModel(model)) / 1000 * 0.1 - case globals.ZhiPuChatGLMStd: + case globals.ZhiPuChatGLMTurbo, globals.ZhiPuChatGLMStd: return float32(t*GetWeightByModel(model)) / 1000 * 0.05 case globals.QwenTurbo, globals.QwenTurboNet: return float32(t*GetWeightByModel(model)) / 1000 * 0.08