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
Unverified
Commit
3a2138ba
authored
Apr 24, 2026
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: rename and relocate HasModelBillingConfig function for clarity
parent
e3d64cb7
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
17 additions
and
41 deletions
+17
-41
controller/model.go
+3
-2
model/pricing.go
+0
-14
relay/gemini_handler.go
+1
-1
relay/helper/price.go
+13
-2
setting/ratio_setting/model_ratio_test.go
+0
-22
No files found.
controller/model.go
View file @
3a2138ba
...
@@ -15,6 +15,7 @@ import (
...
@@ -15,6 +15,7 @@ import (
"github.com/QuantumNous/new-api/relay/channel/minimax"
"github.com/QuantumNous/new-api/relay/channel/minimax"
"github.com/QuantumNous/new-api/relay/channel/moonshot"
"github.com/QuantumNous/new-api/relay/channel/moonshot"
relaycommon
"github.com/QuantumNous/new-api/relay/common"
relaycommon
"github.com/QuantumNous/new-api/relay/common"
"github.com/QuantumNous/new-api/relay/helper"
"github.com/QuantumNous/new-api/service"
"github.com/QuantumNous/new-api/service"
"github.com/QuantumNous/new-api/setting/operation_setting"
"github.com/QuantumNous/new-api/setting/operation_setting"
"github.com/QuantumNous/new-api/types"
"github.com/QuantumNous/new-api/types"
...
@@ -133,7 +134,7 @@ func ListModels(c *gin.Context, modelType int) {
...
@@ -133,7 +134,7 @@ func ListModels(c *gin.Context, modelType int) {
}
}
for
allowModel
,
_
:=
range
tokenModelLimit
{
for
allowModel
,
_
:=
range
tokenModelLimit
{
if
!
acceptUnsetRatioModel
{
if
!
acceptUnsetRatioModel
{
if
!
model
.
HasModelBillingConfig
(
allowModel
)
{
if
!
helper
.
HasModelBillingConfig
(
allowModel
)
{
continue
continue
}
}
}
}
...
@@ -180,7 +181,7 @@ func ListModels(c *gin.Context, modelType int) {
...
@@ -180,7 +181,7 @@ func ListModels(c *gin.Context, modelType int) {
}
}
for
_
,
modelName
:=
range
models
{
for
_
,
modelName
:=
range
models
{
if
!
acceptUnsetRatioModel
{
if
!
acceptUnsetRatioModel
{
if
!
model
.
HasModelBillingConfig
(
modelName
)
{
if
!
helper
.
HasModelBillingConfig
(
modelName
)
{
continue
continue
}
}
}
}
...
...
model/pricing.go
View file @
3a2138ba
...
@@ -86,20 +86,6 @@ func InvalidatePricingCache() {
...
@@ -86,20 +86,6 @@ func InvalidatePricingCache() {
lastGetPricingTime
=
time
.
Time
{}
lastGetPricingTime
=
time
.
Time
{}
}
}
func
HasModelBillingConfig
(
modelName
string
)
bool
{
if
_
,
ok
:=
ratio_setting
.
GetModelPrice
(
modelName
,
false
);
ok
{
return
true
}
if
_
,
ok
,
_
:=
ratio_setting
.
GetModelRatio
(
modelName
);
ok
{
return
true
}
if
billing_setting
.
GetBillingMode
(
modelName
)
!=
billing_setting
.
BillingModeTieredExpr
{
return
false
}
expr
,
ok
:=
billing_setting
.
GetBillingExpr
(
modelName
)
return
ok
&&
strings
.
TrimSpace
(
expr
)
!=
""
}
// GetVendors 返回当前定价接口使用到的供应商信息
// GetVendors 返回当前定价接口使用到的供应商信息
func
GetVendors
()
[]
PricingVendor
{
func
GetVendors
()
[]
PricingVendor
{
if
time
.
Since
(
lastGetPricingTime
)
>
time
.
Minute
*
1
||
len
(
pricingMap
)
==
0
{
if
time
.
Since
(
lastGetPricingTime
)
>
time
.
Minute
*
1
||
len
(
pricingMap
)
==
0
{
...
...
relay/gemini_handler.go
View file @
3a2138ba
...
@@ -77,7 +77,7 @@ func GeminiHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *typ
...
@@ -77,7 +77,7 @@ func GeminiHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *typ
if
!
strings
.
Contains
(
info
.
OriginModelName
,
"-nothinking"
)
{
if
!
strings
.
Contains
(
info
.
OriginModelName
,
"-nothinking"
)
{
// try to get no thinking model price
// try to get no thinking model price
noThinkingModelName
:=
info
.
OriginModelName
+
"-nothinking"
noThinkingModelName
:=
info
.
OriginModelName
+
"-nothinking"
containPrice
:=
helper
.
ContainPriceOrRatio
(
noThinkingModelName
)
containPrice
:=
helper
.
HasModelBillingConfig
(
noThinkingModelName
)
if
containPrice
{
if
containPrice
{
info
.
OriginModelName
=
noThinkingModelName
info
.
OriginModelName
=
noThinkingModelName
info
.
UpstreamModelName
=
noThinkingModelName
info
.
UpstreamModelName
=
noThinkingModelName
...
...
relay/helper/price.go
View file @
3a2138ba
...
@@ -2,6 +2,7 @@ package helper
...
@@ -2,6 +2,7 @@ package helper
import
(
import
(
"fmt"
"fmt"
"strings"
"github.com/QuantumNous/new-api/common"
"github.com/QuantumNous/new-api/common"
"github.com/QuantumNous/new-api/logger"
"github.com/QuantumNous/new-api/logger"
...
@@ -223,8 +224,18 @@ func ModelPriceHelperPerCall(c *gin.Context, info *relaycommon.RelayInfo) (types
...
@@ -223,8 +224,18 @@ func ModelPriceHelperPerCall(c *gin.Context, info *relaycommon.RelayInfo) (types
return
priceData
,
nil
return
priceData
,
nil
}
}
func
ContainPriceOrRatio
(
modelName
string
)
bool
{
func
HasModelBillingConfig
(
modelName
string
)
bool
{
return
model
.
HasModelBillingConfig
(
modelName
)
if
_
,
ok
:=
ratio_setting
.
GetModelPrice
(
modelName
,
false
);
ok
{
return
true
}
if
_
,
ok
,
_
:=
ratio_setting
.
GetModelRatio
(
modelName
);
ok
{
return
true
}
if
billing_setting
.
GetBillingMode
(
modelName
)
!=
billing_setting
.
BillingModeTieredExpr
{
return
false
}
expr
,
ok
:=
billing_setting
.
GetBillingExpr
(
modelName
)
return
ok
&&
strings
.
TrimSpace
(
expr
)
!=
""
}
}
func
modelPriceHelperTiered
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
,
promptTokens
int
,
meta
*
types
.
TokenCountMeta
,
groupRatioInfo
types
.
GroupRatioInfo
)
(
types
.
PriceData
,
error
)
{
func
modelPriceHelperTiered
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
,
promptTokens
int
,
meta
*
types
.
TokenCountMeta
,
groupRatioInfo
types
.
GroupRatioInfo
)
(
types
.
PriceData
,
error
)
{
...
...
setting/ratio_setting/model_ratio_test.go
deleted
100644 → 0
View file @
e3d64cb7
package
ratio_setting
import
"testing"
func
TestGetCompletionRatioInfoGPT55UsesOfficialOutputMultiplier
(
t
*
testing
.
T
)
{
info
:=
GetCompletionRatioInfo
(
"gpt-5.5"
)
if
info
.
Ratio
!=
6
{
t
.
Fatalf
(
"gpt-5.5 completion ratio = %v, want 6"
,
info
.
Ratio
)
}
if
!
info
.
Locked
{
t
.
Fatal
(
"gpt-5.5 completion ratio should be locked to the official multiplier"
)
}
}
func
TestGetCompletionRatioGPT55DatedVariant
(
t
*
testing
.
T
)
{
got
:=
GetCompletionRatio
(
"gpt-5.5-2026-04-24"
)
if
got
!=
6
{
t
.
Fatalf
(
"gpt-5.5 dated variant completion ratio = %v, want 6"
,
got
)
}
}
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