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
ae788c8a
authored
May 08, 2025
by
Calcium-Ion
Committed by
GitHub
May 08, 2025
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1040 from QuantumNous/responses-quota
fix: tool quota calculate
parents
a63b2e77
5002f7c4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
10 deletions
+17
-10
relay/relay-text.go
+3
-3
web/src/helpers/render.js
+14
-7
No files found.
relay/relay-text.go
View file @
ae788c8a
...
@@ -364,11 +364,11 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo,
...
@@ -364,11 +364,11 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo,
var
webSearchPrice
float64
var
webSearchPrice
float64
if
relayInfo
.
ResponsesUsageInfo
!=
nil
{
if
relayInfo
.
ResponsesUsageInfo
!=
nil
{
if
webSearchTool
,
exists
:=
relayInfo
.
ResponsesUsageInfo
.
BuiltInTools
[
dto
.
BuildInToolWebSearchPreview
];
exists
&&
webSearchTool
.
CallCount
>
0
{
if
webSearchTool
,
exists
:=
relayInfo
.
ResponsesUsageInfo
.
BuiltInTools
[
dto
.
BuildInToolWebSearchPreview
];
exists
&&
webSearchTool
.
CallCount
>
0
{
// 计算 web search 调用的配额 (配额 = 价格 * 调用次数 / 1000)
// 计算 web search 调用的配额 (配额 = 价格 * 调用次数 / 1000
* 分组倍率
)
webSearchPrice
=
operation_setting
.
GetWebSearchPricePerThousand
(
modelName
,
webSearchTool
.
SearchContextSize
)
webSearchPrice
=
operation_setting
.
GetWebSearchPricePerThousand
(
modelName
,
webSearchTool
.
SearchContextSize
)
dWebSearchQuota
=
decimal
.
NewFromFloat
(
webSearchPrice
)
.
dWebSearchQuota
=
decimal
.
NewFromFloat
(
webSearchPrice
)
.
Mul
(
decimal
.
NewFromInt
(
int64
(
webSearchTool
.
CallCount
)))
.
Mul
(
decimal
.
NewFromInt
(
int64
(
webSearchTool
.
CallCount
)))
.
Div
(
decimal
.
NewFromInt
(
1000
))
Div
(
decimal
.
NewFromInt
(
1000
))
.
Mul
(
dGroupRatio
)
.
Mul
(
dQuotaPerUnit
)
extraContent
+=
fmt
.
Sprintf
(
"Web Search 调用 %d 次,上下文大小 %s,调用花费 $%s"
,
extraContent
+=
fmt
.
Sprintf
(
"Web Search 调用 %d 次,上下文大小 %s,调用花费 $%s"
,
webSearchTool
.
CallCount
,
webSearchTool
.
SearchContextSize
,
dWebSearchQuota
.
String
())
webSearchTool
.
CallCount
,
webSearchTool
.
SearchContextSize
,
dWebSearchQuota
.
String
())
}
}
...
@@ -381,7 +381,7 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo,
...
@@ -381,7 +381,7 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo,
fileSearchPrice
=
operation_setting
.
GetFileSearchPricePerThousand
()
fileSearchPrice
=
operation_setting
.
GetFileSearchPricePerThousand
()
dFileSearchQuota
=
decimal
.
NewFromFloat
(
fileSearchPrice
)
.
dFileSearchQuota
=
decimal
.
NewFromFloat
(
fileSearchPrice
)
.
Mul
(
decimal
.
NewFromInt
(
int64
(
fileSearchTool
.
CallCount
)))
.
Mul
(
decimal
.
NewFromInt
(
int64
(
fileSearchTool
.
CallCount
)))
.
Div
(
decimal
.
NewFromInt
(
1000
))
Div
(
decimal
.
NewFromInt
(
1000
))
.
Mul
(
dGroupRatio
)
.
Mul
(
dQuotaPerUnit
)
extraContent
+=
fmt
.
Sprintf
(
"File Search 调用 %d 次,调用花费 $%s"
,
extraContent
+=
fmt
.
Sprintf
(
"File Search 调用 %d 次,调用花费 $%s"
,
fileSearchTool
.
CallCount
,
dFileSearchQuota
.
String
())
fileSearchTool
.
CallCount
,
dFileSearchQuota
.
String
())
}
}
...
...
web/src/helpers/render.js
View file @
ae788c8a
...
@@ -354,8 +354,8 @@ export function renderModelPrice(
...
@@ -354,8 +354,8 @@ export function renderModelPrice(
let
price
=
let
price
=
(
effectiveInputTokens
/
1000000
)
*
inputRatioPrice
*
groupRatio
+
(
effectiveInputTokens
/
1000000
)
*
inputRatioPrice
*
groupRatio
+
(
completionTokens
/
1000000
)
*
completionRatioPrice
*
groupRatio
+
(
completionTokens
/
1000000
)
*
completionRatioPrice
*
groupRatio
+
(
webSearchCallCount
/
1000
)
*
webSearchPrice
+
(
webSearchCallCount
/
1000
)
*
webSearchPrice
*
groupRatio
+
(
fileSearchCallCount
/
1000
)
*
fileSearchPrice
;
(
fileSearchCallCount
/
1000
)
*
fileSearchPrice
*
groupRatio
;
return
(
return
(
<>
<>
...
@@ -446,7 +446,7 @@ export function renderModelPrice(
...
@@ -446,7 +446,7 @@ export function renderModelPrice(
)
)
:
webSearch
&&
webSearchCallCount
>
0
&&
!
image
&&
!
fileSearch
:
webSearch
&&
webSearchCallCount
>
0
&&
!
image
&&
!
fileSearch
?
i18next
.
t
(
?
i18next
.
t
(
'输入 {{input}} tokens / 1M tokens * ${{price}} + 输出 {{completion}} tokens / 1M tokens * ${{compPrice}} * 分组 {{ratio}} + Web搜索 {{webSearchCallCount}}次 / 1K 次 * ${{webSearchPrice}} = ${{total}}'
,
'输入 {{input}} tokens / 1M tokens * ${{price}} + 输出 {{completion}} tokens / 1M tokens * ${{compPrice}} * 分组 {{ratio}} + Web搜索 {{webSearchCallCount}}次 / 1K 次 * ${{webSearchPrice}}
* {{ratio}}
= ${{total}}'
,
{
{
input
:
inputTokens
,
input
:
inputTokens
,
price
:
inputRatioPrice
,
price
:
inputRatioPrice
,
...
@@ -458,9 +458,12 @@ export function renderModelPrice(
...
@@ -458,9 +458,12 @@ export function renderModelPrice(
total
:
price
.
toFixed
(
6
),
total
:
price
.
toFixed
(
6
),
},
},
)
)
:
fileSearch
&&
fileSearchCallCount
>
0
&&
!
image
&&
!
webSearch
:
fileSearch
&&
fileSearchCallCount
>
0
&&
!
image
&&
!
webSearch
?
i18next
.
t
(
?
i18next
.
t
(
'输入 {{input}} tokens / 1M tokens * ${{price}} + 输出 {{completion}} tokens / 1M tokens * ${{compPrice}} * 分组 {{ratio}} + 文件搜索 {{fileSearchCallCount}}次 / 1K 次 * ${{fileSearchPrice}} = ${{total}}'
,
'输入 {{input}} tokens / 1M tokens * ${{price}} + 输出 {{completion}} tokens / 1M tokens * ${{compPrice}} * 分组 {{ratio}} + 文件搜索 {{fileSearchCallCount}}次 / 1K 次 * ${{fileSearchPrice}}
* {{ratio}}
= ${{total}}'
,
{
{
input
:
inputTokens
,
input
:
inputTokens
,
price
:
inputRatioPrice
,
price
:
inputRatioPrice
,
...
@@ -472,9 +475,13 @@ export function renderModelPrice(
...
@@ -472,9 +475,13 @@ export function renderModelPrice(
total
:
price
.
toFixed
(
6
),
total
:
price
.
toFixed
(
6
),
},
},
)
)
:
webSearch
&&
webSearchCallCount
>
0
&&
fileSearch
&&
fileSearchCallCount
>
0
&&
!
image
:
webSearch
&&
webSearchCallCount
>
0
&&
fileSearch
&&
fileSearchCallCount
>
0
&&
!
image
?
i18next
.
t
(
?
i18next
.
t
(
'输入 {{input}} tokens / 1M tokens * ${{price}} + 输出 {{completion}} tokens / 1M tokens * ${{compPrice}} * 分组 {{ratio}} + Web搜索 {{webSearchCallCount}}次 / 1K 次 * ${{webSearchPrice}}
+ 文件搜索 {{fileSearchCallCount}}次 / 1K 次 * ${{fileSearchPrice}}
= ${{total}}'
,
'输入 {{input}} tokens / 1M tokens * ${{price}} + 输出 {{completion}} tokens / 1M tokens * ${{compPrice}} * 分组 {{ratio}} + Web搜索 {{webSearchCallCount}}次 / 1K 次 * ${{webSearchPrice}}
* {{ratio}}+ 文件搜索 {{fileSearchCallCount}}次 / 1K 次 * ${{fileSearchPrice}} * {{ratio}}
= ${{total}}'
,
{
{
input
:
inputTokens
,
input
:
inputTokens
,
price
:
inputRatioPrice
,
price
:
inputRatioPrice
,
...
...
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