mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-09 12:00:47 +00:00
feat(task): replace built-in task adaptors with a sandboxed JS plugin system (#7076)
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package billingexpr
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestTaskUsageExpressionUsesFactsAndTaskQuotaConversion(t *testing.T) {
|
||||
expression := `tier("1080p", u("seconds") * (u("resolution") == "1080p" ? 0.4 : 0.2))`
|
||||
cost, trace, err := RunExprWithRequest(expression, TokenParams{}, RequestInput{Usage: map[string]any{"seconds": 10.0, "resolution": "1080p"}})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 4.0, cost)
|
||||
assert.Equal(t, "1080p", trace.MatchedTier)
|
||||
result, err := ComputeTieredQuotaWithRequest(&BillingSnapshot{ExprString: expression, ExprHash: ExprHashString(expression), GroupRatio: 2, QuotaPerUnit: 500000, ExprVersion: 1, TaskUsageBilling: true}, TokenParams{}, RequestInput{Usage: map[string]any{"seconds": 10.0, "resolution": "1080p"}})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 4_000_000, result.ActualQuotaAfterGroup)
|
||||
}
|
||||
Reference in New Issue
Block a user