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
@@ -4,12 +4,15 @@ import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"maps"
|
||||
"math"
|
||||
"strings"
|
||||
|
||||
"github.com/QuantumNous/new-api/common"
|
||||
"github.com/QuantumNous/new-api/constant"
|
||||
"github.com/QuantumNous/new-api/logger"
|
||||
"github.com/QuantumNous/new-api/model"
|
||||
"github.com/QuantumNous/new-api/pkg/billingexpr"
|
||||
relaycommon "github.com/QuantumNous/new-api/relay/common"
|
||||
"github.com/QuantumNous/new-api/setting/ratio_setting"
|
||||
"github.com/QuantumNous/new-api/types"
|
||||
@@ -379,3 +382,20 @@ func RecalculateTaskQuotaByTokens(ctx context.Context, task *model.Task, totalTo
|
||||
RecalculateTaskQuota(ctx, task, actualQuota, reason, clamp)
|
||||
return true
|
||||
}
|
||||
|
||||
// EvaluateTaskCompletionUsage evaluates actual facts against the frozen task
|
||||
// expression. It neither mutates the snapshot nor moves funds: synchronous
|
||||
// submission and polling have different persistence and settlement barriers.
|
||||
func EvaluateTaskCompletionUsage(snap *billingexpr.BillingSnapshot, facts map[string]any) (billingexpr.TieredResult, map[string]any, error) {
|
||||
if snap == nil {
|
||||
return billingexpr.TieredResult{}, nil, fmt.Errorf("task billing snapshot is missing")
|
||||
}
|
||||
usage := make(map[string]any, len(snap.UsageFacts)+len(facts))
|
||||
maps.Copy(usage, snap.UsageFacts)
|
||||
maps.Copy(usage, facts)
|
||||
result, err := billingexpr.ComputeTieredQuotaWithRequest(snap, billingexpr.TokenParams{}, billingexpr.RequestInput{Usage: usage})
|
||||
if err == nil && (result.ActualQuotaBeforeGroup < 0 || math.IsNaN(result.ActualQuotaBeforeGroup)) {
|
||||
err = fmt.Errorf("task completion expression produced an invalid cost")
|
||||
}
|
||||
return result, usage, err
|
||||
}
|
||||
Reference in new issue
Block a user