mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-04-19 07:37:27 +00:00
feat: add temporary TASK_PRICE_PATCH configuration to environment variables
This commit is contained in:
@@ -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() {
|
|||||||
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -72,10 +72,13 @@ func RelayTaskSubmit(c *gin.Context, info *relaycommon.RelayInfo) (taskErr *dto.
|
|||||||
} else {
|
} else {
|
||||||
ratio = modelPrice * groupRatio
|
ratio = modelPrice * groupRatio
|
||||||
}
|
}
|
||||||
if len(info.PriceData.OtherRatios) > 0 {
|
// FIXME: 临时修补,支持任务仅按次计费
|
||||||
for _, ra := range info.PriceData.OtherRatios {
|
if !common.StringsContains(constant.TaskPricePatches, modelName) {
|
||||||
if 1.0 != ra {
|
if len(info.PriceData.OtherRatios) > 0 {
|
||||||
ratio *= ra
|
for _, ra := range info.PriceData.OtherRatios {
|
||||||
|
if 1.0 != ra {
|
||||||
|
ratio *= ra
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -153,15 +156,20 @@ 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)
|
||||||
if len(info.PriceData.OtherRatios) > 0 {
|
// FIXME: 临时修补,支持任务仅按次计费
|
||||||
var contents []string
|
if common.StringsContains(constant.TaskPricePatches, modelName) {
|
||||||
for key, ra := range info.PriceData.OtherRatios {
|
logContent = fmt.Sprintf("%s,按次计费", logContent)
|
||||||
if 1.0 != ra {
|
} else {
|
||||||
contents = append(contents, fmt.Sprintf("%s: %.2f", key, ra))
|
if len(info.PriceData.OtherRatios) > 0 {
|
||||||
|
var contents []string
|
||||||
|
for key, ra := range info.PriceData.OtherRatios {
|
||||||
|
if 1.0 != ra {
|
||||||
|
contents = append(contents, fmt.Sprintf("%s: %.2f", key, ra))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(contents) > 0 {
|
||||||
|
logContent = fmt.Sprintf("%s, 计算参数:%s", logContent, strings.Join(contents, ", "))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if len(contents) > 0 {
|
|
||||||
logContent = fmt.Sprintf("%s, 计算参数:%s", logContent, strings.Join(contents, ", "))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
other := make(map[string]interface{})
|
other := make(map[string]interface{})
|
||||||
|
|||||||
Reference in New Issue
Block a user