feat: publish v1.0.0-rc.36-custom.1
Publish Docker image (Multi-arch) / Build & push (amd64) (push) Failing after 9m20s
Release (Linux, macOS, Windows) / Linux Release (push) Failing after 55m7s
Publish Docker image (Multi-arch) / Build & push (arm64) (push) Canceled after 0s
Release (Linux, macOS, Windows) / macOS Release (push) Canceled after 0s
Release (Linux, macOS, Windows) / Windows Release (push) Canceled after 0s
Publish Docker image (Multi-arch) / Create multi-arch manifests (push) Canceled after 0s
Publish Docker image (Multi-arch) / Build & push (amd64) (push) Failing after 9m20s
Release (Linux, macOS, Windows) / Linux Release (push) Failing after 55m7s
Publish Docker image (Multi-arch) / Build & push (arm64) (push) Canceled after 0s
Release (Linux, macOS, Windows) / macOS Release (push) Canceled after 0s
Release (Linux, macOS, Windows) / Windows Release (push) Canceled after 0s
Publish Docker image (Multi-arch) / Create multi-arch manifests (push) Canceled after 0s
This commit is contained in:
commit
bb7968b612
2381 files changed
+551494
No files matched your search
@@ -0,0 +1,68 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"github.com/QuantumNous/new-api/model"
|
||||
"github.com/QuantumNous/new-api/relaykit/dto"
|
||||
)
|
||||
|
||||
const (
|
||||
usageBillingPathLocal = "local"
|
||||
usageBillingPathUpstream = "upstream"
|
||||
usageBillingPathOpenAI = "billing-usage-openai"
|
||||
usageBillingPathOpenAIEstimated = "billing-usage-openai-estimated"
|
||||
usageBillingPathAnthropic = "billing-usage-anthropic"
|
||||
usageBillingPathAnthropicEstimated = "billing-usage-anthropic-estimated"
|
||||
usageBillingPathGemini = "billing-usage-gemini"
|
||||
usageBillingPathGeminiEstimated = "billing-usage-gemini-estimated"
|
||||
)
|
||||
|
||||
func effectiveBillingUsage(usage *dto.Usage) *dto.Usage {
|
||||
if billingUsage, ok := usageFromBillingUsage(usage); ok {
|
||||
return billingUsage
|
||||
}
|
||||
return usage
|
||||
}
|
||||
|
||||
func usageBillingPathForLog(isLocalCountTokens bool, usage *dto.Usage) string {
|
||||
effectiveUsage, ok := usageFromBillingUsage(usage)
|
||||
if !ok {
|
||||
if isLocalCountTokens {
|
||||
return usageBillingPathLocal
|
||||
}
|
||||
return usageBillingPathUpstream
|
||||
}
|
||||
|
||||
switch effectiveUsage.UsageSemantic {
|
||||
case dto.BillingUsageSemanticOpenAI:
|
||||
if usage.BillingUsage.Estimated {
|
||||
return usageBillingPathOpenAIEstimated
|
||||
}
|
||||
return usageBillingPathOpenAI
|
||||
case dto.BillingUsageSemanticAnthropic:
|
||||
if usage.BillingUsage.Estimated {
|
||||
return usageBillingPathAnthropicEstimated
|
||||
}
|
||||
return usageBillingPathAnthropic
|
||||
case dto.BillingUsageSemanticGemini:
|
||||
if usage.BillingUsage.Estimated {
|
||||
return usageBillingPathGeminiEstimated
|
||||
}
|
||||
return usageBillingPathGemini
|
||||
}
|
||||
|
||||
return usageBillingPathUpstream
|
||||
}
|
||||
|
||||
func appendUsageBillingPathForLog(other *model.LogOther, isLocalCountTokens bool, usage *dto.Usage) {
|
||||
if other == nil {
|
||||
return
|
||||
}
|
||||
other.SetAdmin("usage_billing_path", usageBillingPathForLog(isLocalCountTokens, usage))
|
||||
}
|
||||
|
||||
func usageFromBillingUsage(usage *dto.Usage) (*dto.Usage, bool) {
|
||||
if usage == nil || usage.BillingUsage == nil {
|
||||
return nil, false
|
||||
}
|
||||
return usage.BillingUsage.CanonicalUsage()
|
||||
}
|
||||
Reference in new issue
Block a user