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
1db30c55
authored
May 06, 2025
by
creamlike1024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: move web search tool price to operation_setting
parent
a3fe8877
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
35 deletions
+52
-35
relay/relay-text.go
+2
-35
setting/operation_setting/tools.go
+50
-0
No files found.
relay/relay-text.go
View file @
1db30c55
...
@@ -18,6 +18,7 @@ import (
...
@@ -18,6 +18,7 @@ import (
"one-api/service"
"one-api/service"
"one-api/setting"
"one-api/setting"
"one-api/setting/model_setting"
"one-api/setting/model_setting"
"one-api/setting/operation_setting"
"strings"
"strings"
"time"
"time"
...
@@ -362,41 +363,7 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo,
...
@@ -362,41 +363,7 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo,
var
dWebSearchQuota
decimal
.
Decimal
var
dWebSearchQuota
decimal
.
Decimal
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
{
// 确定模型类型
priceWebSearchPerThousandCalls
:=
operation_setting
.
GetWebSearchPricePerThousand
(
modelName
,
webSearchTool
.
SearchContextSize
)
// https://platform.openai.com/docs/pricing Web search 价格按模型类型和 search context size 收费
// gpt-4.1, gpt-4o, or gpt-4o-search-preview 更贵,gpt-4.1-mini, gpt-4o-mini, gpt-4o-mini-search-preview 更便宜
isHighTierModel
:=
(
strings
.
HasPrefix
(
modelName
,
"gpt-4.1"
)
||
strings
.
HasPrefix
(
modelName
,
"gpt-4o"
))
&&
!
strings
.
Contains
(
modelName
,
"mini"
)
// 确定 search context size 对应的价格
var
priceWebSearchPerThousandCalls
float64
switch
webSearchTool
.
SearchContextSize
{
case
"low"
:
if
isHighTierModel
{
priceWebSearchPerThousandCalls
=
30.0
}
else
{
priceWebSearchPerThousandCalls
=
25.0
}
case
"medium"
:
if
isHighTierModel
{
priceWebSearchPerThousandCalls
=
35.0
}
else
{
priceWebSearchPerThousandCalls
=
27.5
}
case
"high"
:
if
isHighTierModel
{
priceWebSearchPerThousandCalls
=
50.0
}
else
{
priceWebSearchPerThousandCalls
=
30.0
}
default
:
// search context size 默认为 medium
if
isHighTierModel
{
priceWebSearchPerThousandCalls
=
35.0
}
else
{
priceWebSearchPerThousandCalls
=
27.5
}
}
// 计算 web search 调用的配额 (配额 = 价格 * 调用次数 / 1000)
// 计算 web search 调用的配额 (配额 = 价格 * 调用次数 / 1000)
dWebSearchQuota
=
decimal
.
NewFromFloat
(
priceWebSearchPerThousandCalls
)
.
dWebSearchQuota
=
decimal
.
NewFromFloat
(
priceWebSearchPerThousandCalls
)
.
Mul
(
decimal
.
NewFromInt
(
int64
(
webSearchTool
.
CallCount
)))
.
Mul
(
decimal
.
NewFromInt
(
int64
(
webSearchTool
.
CallCount
)))
.
...
...
setting/operation_setting/tools.go
0 → 100644
View file @
1db30c55
package
operation_setting
import
"strings"
const
(
WebSearchHighTierModelPriceLow
=
30.00
WebSearchHighTierModelPriceMedium
=
35.00
WebSearchHighTierModelPriceHigh
=
50.00
WebSearchPriceLow
=
25.00
WebSearchPriceMedium
=
27.50
WebSearchPriceHigh
=
30.00
)
func
GetWebSearchPricePerThousand
(
modelName
string
,
contextSize
string
)
float64
{
// 确定模型类型
// https://platform.openai.com/docs/pricing Web search 价格按模型类型和 search context size 收费
// gpt-4.1, gpt-4o, or gpt-4o-search-preview 更贵,gpt-4.1-mini, gpt-4o-mini, gpt-4o-mini-search-preview 更便宜
isHighTierModel
:=
(
strings
.
HasPrefix
(
modelName
,
"gpt-4.1"
)
||
strings
.
HasPrefix
(
modelName
,
"gpt-4o"
))
&&
!
strings
.
Contains
(
modelName
,
"mini"
)
// 确定 search context size 对应的价格
var
priceWebSearchPerThousandCalls
float64
switch
contextSize
{
case
"low"
:
if
isHighTierModel
{
priceWebSearchPerThousandCalls
=
WebSearchHighTierModelPriceLow
}
else
{
priceWebSearchPerThousandCalls
=
WebSearchPriceLow
}
case
"medium"
:
if
isHighTierModel
{
priceWebSearchPerThousandCalls
=
WebSearchHighTierModelPriceMedium
}
else
{
priceWebSearchPerThousandCalls
=
WebSearchPriceMedium
}
case
"high"
:
if
isHighTierModel
{
priceWebSearchPerThousandCalls
=
WebSearchHighTierModelPriceHigh
}
else
{
priceWebSearchPerThousandCalls
=
WebSearchPriceHigh
}
default
:
// search context size 默认为 medium
if
isHighTierModel
{
priceWebSearchPerThousandCalls
=
WebSearchHighTierModelPriceMedium
}
else
{
priceWebSearchPerThousandCalls
=
WebSearchPriceMedium
}
}
return
priceWebSearchPerThousandCalls
}
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