From 39f6812a2baf2e405a4757bf24698dbfbbe12a19 Mon Sep 17 00:00:00 2001 From: CaIon <1808837298@qq.com> Date: Mon, 13 May 2024 15:08:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- relay/relay-text.go | 4 ++-- web/src/components/LogsTable.js | 6 ++---- web/src/helpers/render.js | 27 +++++++++++++++++++-------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/relay/relay-text.go b/relay/relay-text.go index 9010381..bf3cba0 100644 --- a/relay/relay-text.go +++ b/relay/relay-text.go @@ -268,8 +268,8 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, textRe quota := 0 if modelPrice == -1 { - quota = promptTokens + int(float64(completionTokens)*completionRatio) - quota = int(float64(quota) * ratio) + quota = promptTokens + int(math.Round(float64(completionTokens)*completionRatio)) + quota = int(math.Round(float64(quota) * ratio)) if ratio != 0 && quota <= 0 { quota = 1 } diff --git a/web/src/components/LogsTable.js b/web/src/components/LogsTable.js index 0de3632..8efb9db 100644 --- a/web/src/components/LogsTable.js +++ b/web/src/components/LogsTable.js @@ -316,6 +316,8 @@ const LogsTable = () => { } let other = JSON.parse(record.other); let content = renderModelPrice( + record.prompt_tokens, + record.completion_tokens, other.model_ratio, other.model_price, other.completion_ratio, @@ -326,10 +328,6 @@ const LogsTable = () => { diff --git a/web/src/helpers/render.js b/web/src/helpers/render.js index 44bc004..f0cbd81 100644 --- a/web/src/helpers/render.js +++ b/web/src/helpers/render.js @@ -135,6 +135,8 @@ export function renderQuota(quota, digits = 2) { } export function renderModelPrice( + inputTokens, + completionTokens, modelRatio, modelPrice = -1, completionRatio, @@ -147,15 +149,24 @@ export function renderModelPrice( if (completionRatio === undefined) { completionRatio = 0; } - let inputRatioPrice = modelRatio * 0.002 * groupRatio; - let completionRatioPrice = - modelRatio * completionRatio * 0.002 * groupRatio; + let inputRatioPrice = modelRatio * 2.0 * groupRatio; + let completionRatioPrice = modelRatio * completionRatio * 2.0 * groupRatio; + let price = + (inputTokens / 1000000) * inputRatioPrice + + (completionTokens / 1000000) * completionRatioPrice; return ( - '输入 $' + - inputRatioPrice.toFixed(3) + - '/1K tokens,补全 $' + - completionRatioPrice.toFixed(3) + - '/1K tokens' + <> +
+

提示 ${inputRatioPrice} / 1M tokens

+

补全 ${completionRatioPrice} / 1M tokens

+

计算过程:

+

+ 提示 {inputTokens} tokens / 1M tokens * ${inputRatioPrice} + 补全{' '} + {completionTokens} tokens / 1M tokens * ${completionRatioPrice} = $ + {price.toFixed(6)} +

+
+ ); } }