From 323f3d263a44a7fcae8ab8db5af23a95f529bc91 Mon Sep 17 00:00:00 2001 From: JustSong Date: Wed, 14 Jun 2023 09:12:14 +0800 Subject: [PATCH 1/4] feat: add new released models --- common/model-ratio.go | 5 +++++ controller/model.go | 45 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/common/model-ratio.go b/common/model-ratio.go index fc982491..4bdb6fec 100644 --- a/common/model-ratio.go +++ b/common/model-ratio.go @@ -8,10 +8,15 @@ import "encoding/json" var ModelRatio = map[string]float64{ "gpt-4": 15, "gpt-4-0314": 15, + "gpt-4-0613": 15, "gpt-4-32k": 30, "gpt-4-32k-0314": 30, + "gpt-4-32k-0613": 30, "gpt-3.5-turbo": 1, // $0.002 / 1K tokens "gpt-3.5-turbo-0301": 1, + "gpt-3.5-turbo-0613": 1, + "gpt-3.5-turbo-16k": 2, // $0.004 / 1K tokens + "gpt-3.5-turbo-16k-0613": 2, "text-ada-001": 0.2, "text-babbage-001": 0.25, "text-curie-001": 1, diff --git a/controller/model.go b/controller/model.go index dd3777f7..08819c72 100644 --- a/controller/model.go +++ b/controller/model.go @@ -71,6 +71,33 @@ func init() { Root: "gpt-3.5-turbo-0301", Parent: nil, }, + { + Id: "gpt-3.5-turbo-0613", + Object: "model", + Created: 1677649963, + OwnedBy: "openai", + Permission: permission, + Root: "gpt-3.5-turbo-0613", + Parent: nil, + }, + { + Id: "gpt-3.5-turbo-16k", + Object: "model", + Created: 1677649963, + OwnedBy: "openai", + Permission: permission, + Root: "gpt-3.5-turbo-16k", + Parent: nil, + }, + { + Id: "gpt-3.5-turbo-16k-0613", + Object: "model", + Created: 1677649963, + OwnedBy: "openai", + Permission: permission, + Root: "gpt-3.5-turbo-16k-0613", + Parent: nil, + }, { Id: "gpt-4", Object: "model", @@ -89,6 +116,15 @@ func init() { Root: "gpt-4-0314", Parent: nil, }, + { + Id: "gpt-4-0613", + Object: "model", + Created: 1677649963, + OwnedBy: "openai", + Permission: permission, + Root: "gpt-4-0613", + Parent: nil, + }, { Id: "gpt-4-32k", Object: "model", @@ -107,6 +143,15 @@ func init() { Root: "gpt-4-32k-0314", Parent: nil, }, + { + Id: "gpt-4-32k-0613", + Object: "model", + Created: 1677649963, + OwnedBy: "openai", + Permission: permission, + Root: "gpt-4-32k-0613", + Parent: nil, + }, { Id: "text-embedding-ada-002", Object: "model", From 38668e73311f0bb85a1080b7dad0565eac56f27e Mon Sep 17 00:00:00 2001 From: JustSong Date: Wed, 14 Jun 2023 09:41:06 +0800 Subject: [PATCH 2/4] chore: update gpt3.5 completion ratio --- common/model-ratio.go | 12 +++++++----- controller/relay.go | 11 +++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/common/model-ratio.go b/common/model-ratio.go index 4bdb6fec..5aa8f2d8 100644 --- a/common/model-ratio.go +++ b/common/model-ratio.go @@ -2,9 +2,11 @@ package common import "encoding/json" +// ModelRatio // https://platform.openai.com/docs/models/model-endpoint-compatibility // https://openai.com/pricing // TODO: when a new api is enabled, check the pricing here +// 1 === $0.002 / 1K tokens var ModelRatio = map[string]float64{ "gpt-4": 15, "gpt-4-0314": 15, @@ -12,11 +14,11 @@ var ModelRatio = map[string]float64{ "gpt-4-32k": 30, "gpt-4-32k-0314": 30, "gpt-4-32k-0613": 30, - "gpt-3.5-turbo": 1, // $0.002 / 1K tokens - "gpt-3.5-turbo-0301": 1, - "gpt-3.5-turbo-0613": 1, - "gpt-3.5-turbo-16k": 2, // $0.004 / 1K tokens - "gpt-3.5-turbo-16k-0613": 2, + "gpt-3.5-turbo": 0.75, // $0.0015 / 1K tokens + "gpt-3.5-turbo-0301": 0.75, + "gpt-3.5-turbo-0613": 0.75, + "gpt-3.5-turbo-16k": 1.5, // $0.003 / 1K tokens + "gpt-3.5-turbo-16k-0613": 1.5, "text-ada-001": 0.2, "text-babbage-001": 0.25, "text-curie-001": 1, diff --git a/controller/relay.go b/controller/relay.go index 35897909..cf357104 100644 --- a/controller/relay.go +++ b/controller/relay.go @@ -239,16 +239,15 @@ func relayHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode { defer func() { if consumeQuota { quota := 0 - usingGPT4 := strings.HasPrefix(textRequest.Model, "gpt-4") - completionRatio := 1 - if usingGPT4 { + completionRatio := 1.34 // default for gpt-3 + if strings.HasPrefix(textRequest.Model, "gpt-4") { completionRatio = 2 } if isStream { responseTokens := countTokenText(streamResponseText, textRequest.Model) - quota = promptTokens + responseTokens*completionRatio + quota = promptTokens + int(float64(responseTokens)*completionRatio) } else { - quota = textResponse.Usage.PromptTokens + textResponse.Usage.CompletionTokens*completionRatio + quota = textResponse.Usage.PromptTokens + int(float64(textResponse.Usage.CompletionTokens)*completionRatio) } quota = int(float64(quota) * ratio) if ratio != 0 && quota <= 0 { @@ -260,7 +259,7 @@ func relayHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode { common.SysError("Error consuming token remain quota: " + err.Error()) } userId := c.GetInt("id") - model.RecordLog(userId, model.LogTypeConsume, fmt.Sprintf("使用模型 %s 消耗 %d 点额度(模型倍率 %.2f,分组倍率 %.2f)", textRequest.Model, quota, modelRatio, groupRatio)) + model.RecordLog(userId, model.LogTypeConsume, fmt.Sprintf("使用模型 %s 消耗 %d 点额度(模型倍率 %.2f,分组倍率 %.2f,补全倍率 %.2f)", textRequest.Model, quota, modelRatio, groupRatio, completionRatio)) } }() From 7f9577a3862b4d93eb4bd85badd6928e0c07d66a Mon Sep 17 00:00:00 2001 From: JustSong Date: Wed, 14 Jun 2023 12:14:08 +0800 Subject: [PATCH 3/4] feat: now one channel can belong to multiple groups (close #153) --- model/ability.go | 15 +++++++++------ web/src/pages/Channel/EditChannel.js | 14 ++++++++++---- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/model/ability.go b/model/ability.go index 26ff65d2..1b33916c 100644 --- a/model/ability.go +++ b/model/ability.go @@ -30,15 +30,18 @@ func GetRandomSatisfiedChannel(group string, model string) (*Channel, error) { func (channel *Channel) AddAbilities() error { models_ := strings.Split(channel.Models, ",") + groups_ := strings.Split(channel.Group, ",") abilities := make([]Ability, 0, len(models_)) for _, model := range models_ { - ability := Ability{ - Group: channel.Group, - Model: model, - ChannelId: channel.Id, - Enabled: channel.Status == common.ChannelStatusEnabled, + for _, group := range groups_ { + ability := Ability{ + Group: group, + Model: model, + ChannelId: channel.Id, + Enabled: channel.Status == common.ChannelStatusEnabled, + } + abilities = append(abilities, ability) } - abilities = append(abilities, ability) } return DB.Create(&abilities).Error } diff --git a/web/src/pages/Channel/EditChannel.js b/web/src/pages/Channel/EditChannel.js index 9bce5d9a..e25ab2de 100644 --- a/web/src/pages/Channel/EditChannel.js +++ b/web/src/pages/Channel/EditChannel.js @@ -15,8 +15,8 @@ const EditChannel = () => { key: '', base_url: '', other: '', - group: 'default', models: [], + groups: ['default'] }; const [batch, setBatch] = useState(false); const [inputs, setInputs] = useState(originInputs); @@ -37,6 +37,11 @@ const EditChannel = () => { } else { data.models = data.models.split(",") } + if (data.group === "") { + data.groups = [] + } else { + data.groups = data.group.split(",") + } setInputs(data); } else { showError(message); @@ -94,6 +99,7 @@ const EditChannel = () => { } let res; localInputs.models = localInputs.models.join(",") + localInputs.group = localInputs.groups.join(",") if (isEdit) { res = await API.put(`/api/channel/`, { ...localInputs, id: parseInt(channelId) }); } else { @@ -185,14 +191,14 @@ const EditChannel = () => { From d6dbaff3c2704192ef66065d471dcd1223975870 Mon Sep 17 00:00:00 2001 From: JustSong Date: Wed, 14 Jun 2023 12:52:56 +0800 Subject: [PATCH 4/4] fix: fix file not committed --- web/src/helpers/render.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/web/src/helpers/render.js b/web/src/helpers/render.js index 506de16f..c09a79ad 100644 --- a/web/src/helpers/render.js +++ b/web/src/helpers/render.js @@ -10,10 +10,17 @@ export function renderText(text, limit) { export function renderGroup(group) { if (group === "") { return - } else if (group === "vip" || group === "pro") { - return - } else if (group === "svip" || group === "premium") { - return } - return + let groups = group.split(","); + groups.sort(); + return <> + {groups.map((group) => { + if (group === "vip" || group === "pro") { + return + } else if (group === "svip" || group === "premium") { + return + } + return + })} + } \ No newline at end of file