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
6eda56bd
authored
May 07, 2025
by
creamlike1024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 添加 built in tools 计费前端显示
parent
8cebbde4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
156 additions
and
50 deletions
+156
-50
relay/relay-text.go
+8
-4
web/src/components/LogsTable.js
+13
-1
web/src/helpers/render.js
+135
-45
No files found.
relay/relay-text.go
View file @
6eda56bd
...
...
@@ -361,11 +361,12 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo,
// openai web search 工具计费
var
dWebSearchQuota
decimal
.
Decimal
var
webSearchPrice
float64
if
relayInfo
.
ResponsesUsageInfo
!=
nil
{
if
webSearchTool
,
exists
:=
relayInfo
.
ResponsesUsageInfo
.
BuiltInTools
[
dto
.
BuildInToolWebSearchPreview
];
exists
&&
webSearchTool
.
CallCount
>
0
{
priceWebSearchPerThousandCalls
:=
operation_setting
.
GetWebSearchPricePerThousand
(
modelName
,
webSearchTool
.
SearchContextSize
)
// 计算 web search 调用的配额 (配额 = 价格 * 调用次数 / 1000)
dWebSearchQuota
=
decimal
.
NewFromFloat
(
priceWebSearchPerThousandCalls
)
.
webSearchPrice
=
operation_setting
.
GetWebSearchPricePerThousand
(
modelName
,
webSearchTool
.
SearchContextSize
)
dWebSearchQuota
=
decimal
.
NewFromFloat
(
webSearchPrice
)
.
Mul
(
decimal
.
NewFromInt
(
int64
(
webSearchTool
.
CallCount
)))
.
Div
(
decimal
.
NewFromInt
(
1000
))
extraContent
+=
fmt
.
Sprintf
(
"Web Search 调用 %d 次,上下文大小 %s,调用花费 $%s"
,
...
...
@@ -374,9 +375,11 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo,
}
// file search tool 计费
var
dFileSearchQuota
decimal
.
Decimal
var
fileSearchPrice
float64
if
relayInfo
.
ResponsesUsageInfo
!=
nil
{
if
fileSearchTool
,
exists
:=
relayInfo
.
ResponsesUsageInfo
.
BuiltInTools
[
dto
.
BuildInToolFileSearch
];
exists
&&
fileSearchTool
.
CallCount
>
0
{
dFileSearchQuota
=
decimal
.
NewFromFloat
(
operation_setting
.
GetFileSearchPricePerThousand
())
.
fileSearchPrice
=
operation_setting
.
GetFileSearchPricePerThousand
()
dFileSearchQuota
=
decimal
.
NewFromFloat
(
fileSearchPrice
)
.
Mul
(
decimal
.
NewFromInt
(
int64
(
fileSearchTool
.
CallCount
)))
.
Div
(
decimal
.
NewFromInt
(
1000
))
extraContent
+=
fmt
.
Sprintf
(
"File Search 调用 %d 次,调用花费 $%s"
,
...
...
@@ -463,13 +466,14 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo,
if
webSearchTool
,
exists
:=
relayInfo
.
ResponsesUsageInfo
.
BuiltInTools
[
dto
.
BuildInToolWebSearchPreview
];
exists
{
other
[
"web_search"
]
=
true
other
[
"web_search_call_count"
]
=
webSearchTool
.
CallCount
other
[
"web_search_
context_size"
]
=
webSearchTool
.
SearchContextSiz
e
other
[
"web_search_
price"
]
=
webSearchPric
e
}
}
if
!
dFileSearchQuota
.
IsZero
()
&&
relayInfo
.
ResponsesUsageInfo
!=
nil
{
if
fileSearchTool
,
exists
:=
relayInfo
.
ResponsesUsageInfo
.
BuiltInTools
[
dto
.
BuildInToolFileSearch
];
exists
{
other
[
"file_search"
]
=
true
other
[
"file_search_call_count"
]
=
fileSearchTool
.
CallCount
other
[
"file_search_price"
]
=
fileSearchPrice
}
}
model
.
RecordConsumeLog
(
ctx
,
relayInfo
.
UserId
,
relayInfo
.
ChannelId
,
promptTokens
,
completionTokens
,
logModel
,
...
...
web/src/components/LogsTable.js
View file @
6eda56bd
...
...
@@ -618,7 +618,6 @@ const LogsTable = () => {
<
/Paragraph
>
);
}
let
content
=
other
?.
claude
?
renderClaudeModelPriceSimple
(
other
.
model_ratio
,
...
...
@@ -935,6 +934,13 @@ const LogsTable = () => {
other
.
model_price
,
other
.
group_ratio
,
other
?.
user_group_ratio
,
false
,
1.0
,
undefined
,
other
.
web_search
||
false
,
other
.
web_search_call_count
||
0
,
other
.
file_search
||
false
,
other
.
file_search_call_count
||
0
,
),
});
}
...
...
@@ -995,6 +1001,12 @@ const LogsTable = () => {
other
?.
image
||
false
,
other
?.
image_ratio
||
0
,
other
?.
image_output
||
0
,
other
?.
web_search
||
false
,
other
?.
web_search_call_count
||
0
,
other
?.
web_search_price
||
0
,
other
?.
file_search
||
false
,
other
?.
file_search_call_count
||
0
,
other
?.
file_search_price
||
0
,
);
}
expandDataLocal
.
push
({
...
...
web/src/helpers/render.js
View file @
6eda56bd
This diff is collapsed.
Click to expand it.
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