Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
98e24435
authored
Mar 08, 2025
by
1808837298@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: Improve price rendering with clearer token and price calculations
parent
47646487
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
49 deletions
+52
-49
web/src/helpers/render.js
+52
-49
No files found.
web/src/helpers/render.js
View file @
98e24435
...
@@ -325,31 +325,29 @@ export function renderModelPrice(
...
@@ -325,31 +325,29 @@ export function renderModelPrice(
return
(
return
(
<>
<>
<
article
>
<
article
>
<
p
>
{
i18next
.
t
(
'提示
:${{price}} * {{ratio
}} = ${{total}} / 1M tokens'
,
{
<
p
>
{
i18next
.
t
(
'提示
价格:${{price
}} = ${{total}} / 1M tokens'
,
{
price
:
inputRatioPrice
,
price
:
inputRatioPrice
,
ratio
:
groupRatio
,
total
:
inputRatioPrice
total
:
inputRatioPrice
*
groupRatio
})}
<
/p
>
})}
<
/p
>
<
p
>
{
i18next
.
t
(
'补全
:${{price}} * {{ratio}} = ${{total}} / 1M tokens
'
,
{
<
p
>
{
i18next
.
t
(
'补全
价格:${{price}} * {{completionRatio}} = ${{total}} / 1M tokens (补全倍率: {{completionRatio}})
'
,
{
price
:
completion
RatioPrice
,
price
:
input
RatioPrice
,
ratio
:
groupRatio
,
total
:
completionRatioPrice
,
total
:
completionRatioPrice
*
group
Ratio
completionRatio
:
completion
Ratio
})}
<
/p
>
})}
<
/p
>
{
cacheTokens
>
0
&&
(
{
cacheTokens
>
0
&&
(
<
p
>
{
i18next
.
t
(
'缓存:${{price}} * {{ratio}} = ${{total}} / 1M tokens (缓存倍率: {{cacheRatio}})'
,
{
<
p
>
{
i18next
.
t
(
'缓存价格:${{price}} * {{cacheRatio}} = ${{total}} / 1M tokens (缓存倍率: {{cacheRatio}})'
,
{
price
:
cacheRatioPrice
,
price
:
inputRatioPrice
,
ratio
:
groupRatio
,
total
:
inputRatioPrice
*
cacheRatio
,
total
:
cacheRatioPrice
*
groupRatio
,
cacheRatio
:
cacheRatio
cacheRatio
:
cacheRatio
})}
<
/p
>
})}
<
/p
>
)}
)}
<
p
><
/p
>
<
p
><
/p
>
<
p
>
<
p
>
{
cacheTokens
>
0
?
{
cacheTokens
>
0
?
i18next
.
t
(
'提示 {{nonCacheInput}} tokens
+ 缓存 {{cacheInput}} tokens * {{cacheRatio}} / 1M tokens * ${{p
rice}} + 补全 {{completion}} tokens / 1M tokens * ${{compPrice}} * 分组 {{ratio}} = ${{total}}'
,
{
i18next
.
t
(
'提示 {{nonCacheInput}} tokens
/ 1M tokens * ${{price}} + 缓存 {{cacheInput}} tokens / 1M tokens * ${{cacheP
rice}} + 补全 {{completion}} tokens / 1M tokens * ${{compPrice}} * 分组 {{ratio}} = ${{total}}'
,
{
nonCacheInput
:
inputTokens
-
cacheTokens
,
nonCacheInput
:
inputTokens
-
cacheTokens
,
cacheInput
:
cacheTokens
,
cacheInput
:
cacheTokens
,
cache
Ratio
:
cacheRatio
,
cache
Price
:
inputRatioPrice
*
cacheRatio
,
price
:
inputRatioPrice
,
price
:
inputRatioPrice
,
completion
:
completionTokens
,
completion
:
completionTokens
,
compPrice
:
completionRatioPrice
,
compPrice
:
completionRatioPrice
,
...
@@ -387,7 +385,7 @@ export function renderModelPriceSimple(
...
@@ -387,7 +385,7 @@ export function renderModelPriceSimple(
});
});
}
else
{
}
else
{
if
(
cacheTokens
!==
0
)
{
if
(
cacheTokens
!==
0
)
{
return
i18next
.
t
(
'模型: {{ratio}} * 分组: {{groupRatio}} * 缓存
倍率
: {{cacheRatio}}'
,
{
return
i18next
.
t
(
'模型: {{ratio}} * 分组: {{groupRatio}} * 缓存: {{cacheRatio}}'
,
{
ratio
:
modelRatio
,
ratio
:
modelRatio
,
groupRatio
:
groupRatio
,
groupRatio
:
groupRatio
,
cacheRatio
:
cacheRatio
cacheRatio
:
cacheRatio
...
@@ -417,7 +415,11 @@ export function renderAudioModelPrice(
...
@@ -417,7 +415,11 @@ export function renderAudioModelPrice(
)
{
)
{
// 1 ratio = $0.002 / 1K tokens
// 1 ratio = $0.002 / 1K tokens
if
(
modelPrice
!==
-
1
)
{
if
(
modelPrice
!==
-
1
)
{
return
'模型价格:$'
+
modelPrice
+
' * 分组倍率:'
+
groupRatio
+
' = $'
+
modelPrice
*
groupRatio
;
return
i18next
.
t
(
'模型价格:${{price}} * 分组倍率:{{ratio}} = ${{total}}'
,
{
price
:
modelPrice
,
ratio
:
groupRatio
,
total
:
modelPrice
*
groupRatio
});
}
else
{
}
else
{
if
(
completionRatio
===
undefined
)
{
if
(
completionRatio
===
undefined
)
{
completionRatio
=
0
;
completionRatio
=
0
;
...
@@ -433,76 +435,77 @@ export function renderAudioModelPrice(
...
@@ -433,76 +435,77 @@ export function renderAudioModelPrice(
// Calculate effective input tokens (non-cached + cached with ratio applied)
// Calculate effective input tokens (non-cached + cached with ratio applied)
const
effectiveInputTokens
=
(
inputTokens
-
cacheTokens
)
+
(
cacheTokens
*
cacheRatio
);
const
effectiveInputTokens
=
(
inputTokens
-
cacheTokens
)
+
(
cacheTokens
*
cacheRatio
);
let
p
rice
=
let
textP
rice
=
(
effectiveInputTokens
/
1000000
)
*
inputRatioPrice
*
groupRatio
+
(
effectiveInputTokens
/
1000000
)
*
inputRatioPrice
*
groupRatio
+
(
completionTokens
/
1000000
)
*
completionRatioPrice
*
groupRatio
+
(
completionTokens
/
1000000
)
*
completionRatioPrice
*
groupRatio
let
audioPrice
=
(
audioInputTokens
/
1000000
)
*
inputRatioPrice
*
audioRatio
*
groupRatio
+
(
audioInputTokens
/
1000000
)
*
inputRatioPrice
*
audioRatio
*
groupRatio
+
(
audioCompletionTokens
/
1000000
)
*
inputRatioPrice
*
audioRatio
*
audioCompletionRatio
*
groupRatio
;
(
audioCompletionTokens
/
1000000
)
*
inputRatioPrice
*
audioRatio
*
audioCompletionRatio
*
groupRatio
;
let
price
=
textPrice
+
audioPrice
;
return
(
return
(
<>
<>
<
article
>
<
article
>
<
p
>
{
i18next
.
t
(
'提示
:${{price}} * {{ratio
}} = ${{total}} / 1M tokens'
,
{
<
p
>
{
i18next
.
t
(
'提示
价格:${{price
}} = ${{total}} / 1M tokens'
,
{
price
:
inputRatioPrice
,
price
:
inputRatioPrice
,
ratio
:
groupRatio
,
total
:
inputRatioPrice
total
:
inputRatioPrice
*
groupRatio
})}
<
/p
>
})}
<
/p
>
<
p
>
{
i18next
.
t
(
'补全
:${{price}} * {{ratio}} = ${{total}} / 1M tokens
'
,
{
<
p
>
{
i18next
.
t
(
'补全
价格:${{price}} * {{completionRatio}} = ${{total}} / 1M tokens (补全倍率: {{completionRatio}})
'
,
{
price
:
completion
RatioPrice
,
price
:
input
RatioPrice
,
ratio
:
groupRatio
,
total
:
completionRatioPrice
,
total
:
completionRatioPrice
*
group
Ratio
completionRatio
:
completion
Ratio
})}
<
/p
>
})}
<
/p
>
{
cacheTokens
>
0
&&
(
{
cacheTokens
>
0
&&
(
<
p
>
{
i18next
.
t
(
'缓存:${{price}} * {{ratio}} = ${{total}} / 1M tokens (缓存倍率: {{cacheRatio}})'
,
{
<
p
>
{
i18next
.
t
(
'缓存价格:${{price}} * {{cacheRatio}} = ${{total}} / 1M tokens (缓存倍率: {{cacheRatio}})'
,
{
price
:
cacheRatioPrice
,
price
:
inputRatioPrice
,
ratio
:
groupRatio
,
total
:
inputRatioPrice
*
cacheRatio
,
total
:
cacheRatioPrice
*
groupRatio
,
cacheRatio
:
cacheRatio
cacheRatio
:
cacheRatio
})}
<
/p
>
})}
<
/p
>
)}
)}
<
p
>
{
i18next
.
t
(
'音频提示
:${{price}} * {{ratio}} * {{audioRatio}} = ${{total}} / 1M tokens
'
,
{
<
p
>
{
i18next
.
t
(
'音频提示
价格:${{price}} * {{audioRatio}} = ${{total}} / 1M tokens (音频倍率: {{audioRatio}})
'
,
{
price
:
inputRatioPrice
,
price
:
inputRatioPrice
,
ratio
:
groupRatio
,
total
:
inputRatioPrice
*
audioRatio
,
audioRatio
,
audioRatio
:
audioRatio
total
:
inputRatioPrice
*
audioRatio
*
groupRatio
})}
<
/p
>
})}
<
/p
>
<
p
>
{
i18next
.
t
(
'音频补全
:${{price}} * {{ratio}} * {{audioRatio}} * {{audioCompRatio}} = ${{total}} / 1M tokens
'
,
{
<
p
>
{
i18next
.
t
(
'音频补全
价格:${{price}} * {{audioRatio}} * {{audioCompRatio}} = ${{total}} / 1M tokens (音频补全倍率: {{audioCompRatio}})
'
,
{
price
:
inputRatioPrice
,
price
:
inputRatioPrice
,
ratio
:
groupRatio
,
total
:
inputRatioPrice
*
audioRatio
*
audioCompletionRatio
,
audioRatio
,
audioRatio
:
audioRatio
,
audioCompRatio
:
audioCompletionRatio
,
audioCompRatio
:
audioCompletionRatio
total
:
inputRatioPrice
*
audioRatio
*
audioCompletionRatio
*
groupRatio
})}
<
/p
>
})}
<
/p
>
<
p
>
<
p
>
{
cacheTokens
>
0
?
{
cacheTokens
>
0
?
i18next
.
t
(
'文字提示 {{nonCacheInput}} tokens
+ 文字缓存 {{cacheInput}} tokens * {{cacheRatio}} / 1M tokens * ${{price}} + 文字补全 {{completion}} tokens / 1M tokens * ${{compPrice}} +
'
,
{
i18next
.
t
(
'文字提示 {{nonCacheInput}} tokens
/ 1M tokens * ${{price}} + 缓存 {{cacheInput}} tokens / 1M tokens * ${{cachePrice}} + 文字补全 {{completion}} tokens / 1M tokens * ${{compPrice}} = ${{total}}
'
,
{
nonCacheInput
:
inputTokens
-
cacheTokens
,
nonCacheInput
:
inputTokens
-
cacheTokens
,
cacheInput
:
cacheTokens
,
cacheInput
:
cacheTokens
,
cache
Ratio
:
cacheRatio
,
cache
Price
:
inputRatioPrice
*
cacheRatio
,
price
:
inputRatioPrice
,
price
:
inputRatioPrice
,
completion
:
completionTokens
,
completion
:
completionTokens
,
compPrice
:
completionRatioPrice
compPrice
:
completionRatioPrice
,
total
:
textPrice
.
toFixed
(
6
)
})
:
})
:
i18next
.
t
(
'文字提示 {{input}} tokens / 1M tokens * ${{price}} + 文字补全 {{completion}} tokens / 1M tokens * ${{compPrice}}
+
'
,
{
i18next
.
t
(
'文字提示 {{input}} tokens / 1M tokens * ${{price}} + 文字补全 {{completion}} tokens / 1M tokens * ${{compPrice}}
= ${{total}}
'
,
{
input
:
inputTokens
,
input
:
inputTokens
,
price
:
inputRatioPrice
,
price
:
inputRatioPrice
,
completion
:
completionTokens
,
completion
:
completionTokens
,
compPrice
:
completionRatioPrice
compPrice
:
completionRatioPrice
,
total
:
textPrice
.
toFixed
(
6
)
})
})
}
}
<
/p
>
<
/p
>
<
p
>
<
p
>
{
i18next
.
t
(
'音频提示 {{input}} tokens / 1M tokens * ${{
price}} * {{audioRatio}} + 音频补全 {{completion}} tokens / 1M tokens * ${{price}} * {{audioRatio}} * {{audioCompRatio
}}'
,
{
{
i18next
.
t
(
'音频提示 {{input}} tokens / 1M tokens * ${{
audioInputPrice}} + 音频补全 {{completion}} tokens / 1M tokens * ${{audioCompPrice}} = ${{total
}}'
,
{
input
:
audioInputTokens
,
input
:
audioInputTokens
,
completion
:
audioCompletionTokens
,
completion
:
audioCompletionTokens
,
price
:
inputRatioPrice
,
audioInputPrice
:
audioRatio
*
inputRatioPrice
,
audio
Ratio
,
audio
CompPrice
:
audioRatio
*
audioCompletionRatio
*
inputRatioPrice
,
audioCompRatio
:
audioCompletionRatio
total
:
audioPrice
.
toFixed
(
6
)
})}
})}
<
/p
>
<
/p
>
<
p
>
<
p
>
{
i18next
.
t
(
'(文字 + 音频)* 分组倍率 {{ratio}} = ${{total}}'
,
{
{
i18next
.
t
(
'总价:文字价格 {{textPrice}} + 音频价格 {{audioPrice}} = ${{total}}'
,
{
ratio
:
groupRatio
,
total
:
price
.
toFixed
(
6
),
total
:
price
.
toFixed
(
6
)
textPrice
:
textPrice
.
toFixed
(
6
),
audioPrice
:
audioPrice
.
toFixed
(
6
)
})}
})}
<
/p
>
<
/p
>
<
p
>
{
i18next
.
t
(
'仅供参考,以实际扣费为准'
)}
<
/p
>
<
p
>
{
i18next
.
t
(
'仅供参考,以实际扣费为准'
)}
<
/p
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment