feat: sync deployed v1.0.0-rc.38-custom.42
Sync production source including routing, billing, Astra detection and public uptime. Update custom build instructions and license packaging.
This commit is contained in:
1 parent
aa6c3f50f4
commit
ceddfd3d6b
828 files changed
+122253
-13702
No files matched your search
+36
-14
@@ -12,8 +12,10 @@ import (
|
||||
"github.com/QuantumNous/new-api/common"
|
||||
"github.com/QuantumNous/new-api/constant"
|
||||
"github.com/QuantumNous/new-api/dto"
|
||||
"github.com/QuantumNous/new-api/logger"
|
||||
"github.com/QuantumNous/new-api/model"
|
||||
"github.com/QuantumNous/new-api/pkg/billingexpr"
|
||||
"github.com/QuantumNous/new-api/pkg/jsplugin"
|
||||
"github.com/QuantumNous/new-api/relay/channel"
|
||||
"github.com/QuantumNous/new-api/relay/channel/task/taskcommon"
|
||||
relaycommon "github.com/QuantumNous/new-api/relay/common"
|
||||
@@ -248,25 +250,29 @@ func RelayTaskSubmit(c *gin.Context, info *relaycommon.RelayInfo) (*TaskSubmitRe
|
||||
info.OriginModelName = modelName
|
||||
var priceData types.PriceData
|
||||
var err error
|
||||
useTiered := billing_setting.GetBillingMode(modelName) == billing_setting.BillingModeTieredExpr
|
||||
var exprStr string
|
||||
var exists bool
|
||||
if useTiered {
|
||||
exprStr, exists = billing_setting.GetBillingExpr(modelName)
|
||||
} else if info.IsModelMapped {
|
||||
if billing_setting.GetBillingMode(info.UpstreamModelName) == billing_setting.BillingModeTieredExpr {
|
||||
if tailExpr, tailOK := billing_setting.GetBillingExpr(info.UpstreamModelName); tailOK && strings.TrimSpace(tailExpr) != "" {
|
||||
exprStr = tailExpr
|
||||
exists = true
|
||||
useTiered = true
|
||||
}
|
||||
}
|
||||
pluginKey := c.GetString("task_plugin_key")
|
||||
pinnedValue, _ := c.Get(jsplugin.ContextKeyPinnedPlugin)
|
||||
pinnedPlugin, _ := pinnedValue.(jsplugin.PinnedPlugin)
|
||||
if pinnedPlugin.Plugin != nil {
|
||||
pluginKey = pinnedPlugin.Plugin.Meta.Key
|
||||
}
|
||||
exprStr, exists := billing_setting.ResolveTaskBillingExpr(pluginKey, modelName, info.UpstreamModelName)
|
||||
useTiered := exists || billing_setting.GetBillingMode(modelName) == billing_setting.BillingModeTieredExpr
|
||||
if useTiered {
|
||||
provider, supported := adaptor.(channel.TaskUsageFactsProvider)
|
||||
if billingexpr.UsesFixedPricing(exprStr) {
|
||||
return nil, service.TaskErrorWrapper(fmt.Errorf("fixed pricing is not supported for task usage expressions"), "model_price_error", http.StatusBadRequest)
|
||||
}
|
||||
if !exists || !supported {
|
||||
return nil, service.TaskErrorWrapper(fmt.Errorf("task model %s has no usage expression or meter", modelName), "model_price_error", http.StatusBadRequest)
|
||||
}
|
||||
sharedModel := pinnedPlugin.Generation.SharedModel(modelName) || pinnedPlugin.Generation.SharedModel(info.UpstreamModelName)
|
||||
if sharedModel && pinnedPlugin.Plugin != nil {
|
||||
schema, _ := pinnedPlugin.Plugin.Meta.UsageForModel(info.UpstreamModelName)
|
||||
if !billing_setting.TaskExprCompatible(exprStr, schema) {
|
||||
return nil, service.TaskErrorWrapper(fmt.Errorf("task model %s pricing is not configured for plugin %s", modelName, pluginKey), "model_price_error", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
var facts map[string]any
|
||||
if validatedProvider, ok := adaptor.(channel.TaskValidatedUsageFactsProvider); ok {
|
||||
facts, err = validatedProvider.ExtractUsageFactsValidated(c, info)
|
||||
@@ -364,7 +370,21 @@ func RelayTaskSubmit(c *gin.Context, info *relaycommon.RelayInfo) (*TaskSubmitRe
|
||||
|
||||
// 11. 提交后计费调整:让适配器根据上游实际返回调整 OtherRatios
|
||||
finalQuota := info.PriceData.Quota
|
||||
if info.TieredBillingSnapshot == nil {
|
||||
if parsed.Immediate != nil && parsed.Immediate.Status == model.TaskStatusFailure {
|
||||
finalQuota = 0
|
||||
} else if snap := info.TieredBillingSnapshot; snap != nil {
|
||||
if parsed.Immediate != nil && parsed.Immediate.Status == model.TaskStatusSuccess && len(parsed.Immediate.UsageFacts) > 0 {
|
||||
settlement, facts, err := service.EvaluateTaskCompletionUsage(snap, parsed.Immediate.UsageFacts)
|
||||
if err != nil {
|
||||
logger.LogWarn(c, fmt.Sprintf("task immediate usage settlement failed; retaining reserved quota: %v", err))
|
||||
} else {
|
||||
finalQuota = settlement.ActualQuotaAfterGroup
|
||||
snap.UsageFacts = facts
|
||||
snap.EstimatedTier = settlement.MatchedTier
|
||||
noteTaskQuotaClamp(info, settlement.Clamp)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if adjustedRatios := adaptor.AdjustBillingOnSubmit(info, parsed.TaskData); len(adjustedRatios) > 0 {
|
||||
if adjustedQuota, ok := recalcQuotaFromRatios(info, adjustedRatios); ok {
|
||||
// 基于调整后的 ratios 重新计算 quota
|
||||
@@ -375,6 +395,8 @@ func RelayTaskSubmit(c *gin.Context, info *relaycommon.RelayInfo) (*TaskSubmitRe
|
||||
}
|
||||
}
|
||||
|
||||
info.PriceData.Quota = finalQuota
|
||||
|
||||
return &TaskSubmitResult{
|
||||
UpstreamTaskID: parsed.UpstreamTaskID,
|
||||
TaskData: parsed.TaskData,
|
||||
|
||||
Reference in new issue
Block a user