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
151264df
authored
Mar 02, 2026
by
Calcium-Ion
Committed by
GitHub
Mar 02, 2026
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3081 from BenLampson/main
Return error when model price/ratio unset
parents
1afa23bc
bea317ac
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
7 deletions
+40
-7
relay/helper/price.go
+19
-4
relay/mjproxy_handler.go
+14
-2
relay/relay_task.go
+7
-1
No files found.
relay/helper/price.go
View file @
151264df
...
@@ -140,18 +140,33 @@ func ModelPriceHelper(c *gin.Context, info *relaycommon.RelayInfo, promptTokens
...
@@ -140,18 +140,33 @@ func ModelPriceHelper(c *gin.Context, info *relaycommon.RelayInfo, promptTokens
}
}
// ModelPriceHelperPerCall 按次计费的 PriceHelper (MJ、Task)
// ModelPriceHelperPerCall 按次计费的 PriceHelper (MJ、Task)
func
ModelPriceHelperPerCall
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
)
types
.
PriceData
{
func
ModelPriceHelperPerCall
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
)
(
types
.
PriceData
,
error
)
{
groupRatioInfo
:=
HandleGroupRatio
(
c
,
info
)
groupRatioInfo
:=
HandleGroupRatio
(
c
,
info
)
modelPrice
,
success
:=
ratio_setting
.
GetModelPrice
(
info
.
OriginModelName
,
true
)
modelPrice
,
success
:=
ratio_setting
.
GetModelPrice
(
info
.
OriginModelName
,
true
)
// 如果没有配置价格,
则使用默认价格
// 如果没有配置价格,
检查模型倍率配置
if
!
success
{
if
!
success
{
// 没有配置费用,返回错误
defaultPrice
,
ok
:=
ratio_setting
.
GetDefaultModelPriceMap
()[
info
.
OriginModelName
]
defaultPrice
,
ok
:=
ratio_setting
.
GetDefaultModelPriceMap
()[
info
.
OriginModelName
]
if
!
ok
{
if
!
ok
{
modelPrice
=
0.1
// 不再使用默认价格,而是返回错误
return
types
.
PriceData
{},
fmt
.
Errorf
(
"模型 %s 价格未配置,请联系管理员设置"
,
info
.
OriginModelName
)
}
else
{
}
else
{
modelPrice
=
defaultPrice
modelPrice
=
defaultPrice
}
}
// 没有配置倍率也不接受没配置,那就返回错误
_
,
ratioSuccess
,
matchName
:=
ratio_setting
.
GetModelRatio
(
info
.
OriginModelName
)
if
!
ratioSuccess
{
acceptUnsetRatio
:=
false
if
info
.
UserSetting
.
AcceptUnsetRatioModel
{
acceptUnsetRatio
=
true
}
if
!
acceptUnsetRatio
{
return
types
.
PriceData
{},
fmt
.
Errorf
(
"模型 %s 倍率或价格未配置,请联系管理员设置或开始自用模式;Model %s ratio or price not set, please set or start self-use mode"
,
matchName
,
matchName
)
}
}
}
}
quota
:=
int
(
modelPrice
*
common
.
QuotaPerUnit
*
groupRatioInfo
.
GroupRatio
)
quota
:=
int
(
modelPrice
*
common
.
QuotaPerUnit
*
groupRatioInfo
.
GroupRatio
)
...
@@ -170,7 +185,7 @@ func ModelPriceHelperPerCall(c *gin.Context, info *relaycommon.RelayInfo) types.
...
@@ -170,7 +185,7 @@ func ModelPriceHelperPerCall(c *gin.Context, info *relaycommon.RelayInfo) types.
Quota
:
quota
,
Quota
:
quota
,
GroupRatioInfo
:
groupRatioInfo
,
GroupRatioInfo
:
groupRatioInfo
,
}
}
return
priceData
return
priceData
,
nil
}
}
func
ContainPriceOrRatio
(
modelName
string
)
bool
{
func
ContainPriceOrRatio
(
modelName
string
)
bool
{
...
...
relay/mjproxy_handler.go
View file @
151264df
...
@@ -186,7 +186,13 @@ func RelaySwapFace(c *gin.Context, info *relaycommon.RelayInfo) *dto.MidjourneyR
...
@@ -186,7 +186,13 @@ func RelaySwapFace(c *gin.Context, info *relaycommon.RelayInfo) *dto.MidjourneyR
}
}
modelName
:=
service
.
CovertMjpActionToModelName
(
constant
.
MjActionSwapFace
)
modelName
:=
service
.
CovertMjpActionToModelName
(
constant
.
MjActionSwapFace
)
priceData
:=
helper
.
ModelPriceHelperPerCall
(
c
,
info
)
priceData
,
err
:=
helper
.
ModelPriceHelperPerCall
(
c
,
info
)
if
err
!=
nil
{
return
&
dto
.
MidjourneyResponse
{
Code
:
4
,
Description
:
err
.
Error
(),
}
}
userQuota
,
err
:=
model
.
GetUserQuota
(
info
.
UserId
,
false
)
userQuota
,
err
:=
model
.
GetUserQuota
(
info
.
UserId
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -487,7 +493,13 @@ func RelayMidjourneySubmit(c *gin.Context, relayInfo *relaycommon.RelayInfo) *dt
...
@@ -487,7 +493,13 @@ func RelayMidjourneySubmit(c *gin.Context, relayInfo *relaycommon.RelayInfo) *dt
modelName
:=
service
.
CovertMjpActionToModelName
(
midjRequest
.
Action
)
modelName
:=
service
.
CovertMjpActionToModelName
(
midjRequest
.
Action
)
priceData
:=
helper
.
ModelPriceHelperPerCall
(
c
,
relayInfo
)
priceData
,
err
:=
helper
.
ModelPriceHelperPerCall
(
c
,
relayInfo
)
if
err
!=
nil
{
return
&
dto
.
MidjourneyResponse
{
Code
:
4
,
Description
:
err
.
Error
(),
}
}
userQuota
,
err
:=
model
.
GetUserQuota
(
relayInfo
.
UserId
,
false
)
userQuota
,
err
:=
model
.
GetUserQuota
(
relayInfo
.
UserId
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
relay/relay_task.go
View file @
151264df
...
@@ -41,6 +41,8 @@ func ResolveOriginTask(c *gin.Context, info *relaycommon.RelayInfo) *dto.TaskErr
...
@@ -41,6 +41,8 @@ func ResolveOriginTask(c *gin.Context, info *relaycommon.RelayInfo) *dto.TaskErr
if
strings
.
Contains
(
path
,
"/v1/videos/"
)
&&
strings
.
HasSuffix
(
path
,
"/remix"
)
{
if
strings
.
Contains
(
path
,
"/v1/videos/"
)
&&
strings
.
HasSuffix
(
path
,
"/remix"
)
{
info
.
Action
=
constant
.
TaskActionRemix
info
.
Action
=
constant
.
TaskActionRemix
}
}
// 提取 remix 任务的 video_id
if
info
.
Action
==
constant
.
TaskActionRemix
{
if
info
.
Action
==
constant
.
TaskActionRemix
{
videoID
:=
c
.
Param
(
"video_id"
)
videoID
:=
c
.
Param
(
"video_id"
)
if
strings
.
TrimSpace
(
videoID
)
==
""
{
if
strings
.
TrimSpace
(
videoID
)
==
""
{
...
@@ -176,7 +178,11 @@ func RelayTaskSubmit(c *gin.Context, info *relaycommon.RelayInfo) (*TaskSubmitRe
...
@@ -176,7 +178,11 @@ func RelayTaskSubmit(c *gin.Context, info *relaycommon.RelayInfo) (*TaskSubmitRe
// 4. 价格计算:基础模型价格
// 4. 价格计算:基础模型价格
info
.
OriginModelName
=
modelName
info
.
OriginModelName
=
modelName
info
.
PriceData
=
helper
.
ModelPriceHelperPerCall
(
c
,
info
)
priceData
,
err
:=
helper
.
ModelPriceHelperPerCall
(
c
,
info
)
if
err
!=
nil
{
return
nil
,
service
.
TaskErrorWrapper
(
err
,
"model_price_error"
,
http
.
StatusBadRequest
)
}
info
.
PriceData
=
priceData
// 5. 计费估算:让适配器根据用户请求提供 OtherRatios(时长、分辨率等)
// 5. 计费估算:让适配器根据用户请求提供 OtherRatios(时长、分辨率等)
// 必须在 ModelPriceHelperPerCall 之后调用(它会重建 PriceData)。
// 必须在 ModelPriceHelperPerCall 之后调用(它会重建 PriceData)。
...
...
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