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
8ff87ae6
authored
Oct 16, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add temporary TASK_PRICE_PATCH configuration to environment variables
parent
8511ea0f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
0 deletions
+25
-0
common/init.go
+14
-0
constant/env.go
+3
-0
relay/relay_task.go
+8
-0
No files found.
common/init.go
View file @
8ff87ae6
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
"os"
"os"
"path/filepath"
"path/filepath"
"strconv"
"strconv"
"strings"
"time"
"time"
"github.com/QuantumNous/new-api/constant"
"github.com/QuantumNous/new-api/constant"
...
@@ -118,4 +119,17 @@ func initConstantEnv() {
...
@@ -118,4 +119,17 @@ func initConstantEnv() {
constant
.
GenerateDefaultToken
=
GetEnvOrDefaultBool
(
"GENERATE_DEFAULT_TOKEN"
,
false
)
constant
.
GenerateDefaultToken
=
GetEnvOrDefaultBool
(
"GENERATE_DEFAULT_TOKEN"
,
false
)
// 是否启用错误日志
// 是否启用错误日志
constant
.
ErrorLogEnabled
=
GetEnvOrDefaultBool
(
"ERROR_LOG_ENABLED"
,
false
)
constant
.
ErrorLogEnabled
=
GetEnvOrDefaultBool
(
"ERROR_LOG_ENABLED"
,
false
)
soraPatchStr
:=
GetEnvOrDefaultString
(
"TASK_PRICE_PATCH"
,
""
)
if
soraPatchStr
!=
""
{
var
taskPricePatches
[]
string
soraPatches
:=
strings
.
Split
(
soraPatchStr
,
","
)
for
_
,
patch
:=
range
soraPatches
{
trimmedPatch
:=
strings
.
TrimSpace
(
patch
)
if
trimmedPatch
!=
""
{
taskPricePatches
=
append
(
taskPricePatches
,
trimmedPatch
)
}
}
constant
.
TaskPricePatches
=
taskPricePatches
}
}
}
constant/env.go
View file @
8ff87ae6
...
@@ -13,3 +13,6 @@ var NotifyLimitCount int
...
@@ -13,3 +13,6 @@ var NotifyLimitCount int
var
NotificationLimitDurationMinute
int
var
NotificationLimitDurationMinute
int
var
GenerateDefaultToken
bool
var
GenerateDefaultToken
bool
var
ErrorLogEnabled
bool
var
ErrorLogEnabled
bool
// temporary variable for sora patch, will be removed in future
var
TaskPricePatches
[]
string
relay/relay_task.go
View file @
8ff87ae6
...
@@ -72,6 +72,8 @@ func RelayTaskSubmit(c *gin.Context, info *relaycommon.RelayInfo) (taskErr *dto.
...
@@ -72,6 +72,8 @@ func RelayTaskSubmit(c *gin.Context, info *relaycommon.RelayInfo) (taskErr *dto.
}
else
{
}
else
{
ratio
=
modelPrice
*
groupRatio
ratio
=
modelPrice
*
groupRatio
}
}
// FIXME: 临时修补,支持任务仅按次计费
if
!
common
.
StringsContains
(
constant
.
TaskPricePatches
,
modelName
)
{
if
len
(
info
.
PriceData
.
OtherRatios
)
>
0
{
if
len
(
info
.
PriceData
.
OtherRatios
)
>
0
{
for
_
,
ra
:=
range
info
.
PriceData
.
OtherRatios
{
for
_
,
ra
:=
range
info
.
PriceData
.
OtherRatios
{
if
1.0
!=
ra
{
if
1.0
!=
ra
{
...
@@ -79,6 +81,7 @@ func RelayTaskSubmit(c *gin.Context, info *relaycommon.RelayInfo) (taskErr *dto.
...
@@ -79,6 +81,7 @@ func RelayTaskSubmit(c *gin.Context, info *relaycommon.RelayInfo) (taskErr *dto.
}
}
}
}
}
}
}
println
(
fmt
.
Sprintf
(
"model: %s, model_price: %.4f, group: %s, group_ratio: %.4f, final_ratio: %.4f"
,
modelName
,
modelPrice
,
info
.
UsingGroup
,
groupRatio
,
ratio
))
println
(
fmt
.
Sprintf
(
"model: %s, model_price: %.4f, group: %s, group_ratio: %.4f, final_ratio: %.4f"
,
modelName
,
modelPrice
,
info
.
UsingGroup
,
groupRatio
,
ratio
))
userQuota
,
err
:=
model
.
GetUserQuota
(
info
.
UserId
,
false
)
userQuota
,
err
:=
model
.
GetUserQuota
(
info
.
UserId
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -153,6 +156,10 @@ func RelayTaskSubmit(c *gin.Context, info *relaycommon.RelayInfo) (taskErr *dto.
...
@@ -153,6 +156,10 @@ func RelayTaskSubmit(c *gin.Context, info *relaycommon.RelayInfo) (taskErr *dto.
// gRatio = userGroupRatio
// gRatio = userGroupRatio
//}
//}
logContent
:=
fmt
.
Sprintf
(
"操作 %s"
,
info
.
Action
)
logContent
:=
fmt
.
Sprintf
(
"操作 %s"
,
info
.
Action
)
// FIXME: 临时修补,支持任务仅按次计费
if
common
.
StringsContains
(
constant
.
TaskPricePatches
,
modelName
)
{
logContent
=
fmt
.
Sprintf
(
"%s,按次计费"
,
logContent
)
}
else
{
if
len
(
info
.
PriceData
.
OtherRatios
)
>
0
{
if
len
(
info
.
PriceData
.
OtherRatios
)
>
0
{
var
contents
[]
string
var
contents
[]
string
for
key
,
ra
:=
range
info
.
PriceData
.
OtherRatios
{
for
key
,
ra
:=
range
info
.
PriceData
.
OtherRatios
{
...
@@ -164,6 +171,7 @@ func RelayTaskSubmit(c *gin.Context, info *relaycommon.RelayInfo) (taskErr *dto.
...
@@ -164,6 +171,7 @@ func RelayTaskSubmit(c *gin.Context, info *relaycommon.RelayInfo) (taskErr *dto.
logContent
=
fmt
.
Sprintf
(
"%s, 计算参数:%s"
,
logContent
,
strings
.
Join
(
contents
,
", "
))
logContent
=
fmt
.
Sprintf
(
"%s, 计算参数:%s"
,
logContent
,
strings
.
Join
(
contents
,
", "
))
}
}
}
}
}
other
:=
make
(
map
[
string
]
interface
{})
other
:=
make
(
map
[
string
]
interface
{})
if
c
!=
nil
&&
c
.
Request
!=
nil
&&
c
.
Request
.
URL
!=
nil
{
if
c
!=
nil
&&
c
.
Request
!=
nil
&&
c
.
Request
.
URL
!=
nil
{
other
[
"request_path"
]
=
c
.
Request
.
URL
.
Path
other
[
"request_path"
]
=
c
.
Request
.
URL
.
Path
...
...
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