feat: publish sanitized custom.97 source

This commit is contained in:
cneicy committed 2026-10-27 20:43:39 +08:00
1 parent 8e6ed0317b
commit 86c0276156
1022 files changed
+69903 -19207

No files matched your search

+5 -4
View File
@@ -9,6 +9,7 @@ import (
"github.com/QuantumNous/new-api/common"
"github.com/QuantumNous/new-api/constant"
"github.com/QuantumNous/new-api/model"
"github.com/QuantumNous/new-api/tokenkit"
relaycommon "github.com/QuantumNous/new-api/relay/common"
"github.com/QuantumNous/new-api/relaykit/dto"
"github.com/QuantumNous/new-api/relaykit/types"
@@ -70,7 +71,7 @@ func resolveAttemptGuardResult(reason string, info *relaycommon.RelayInfo) strin
return reason
}
if info != nil && info.ResponseModel != nil && info.ResponseModel.ReturnedModel != "" {
if info.ResponseModel.Mismatch {
if info.ResponseModel.Mismatch() {
return "mismatch_allowed"
}
return "accepted"
@@ -120,7 +121,7 @@ func recordDurableAttempt(c *gin.Context, info *relaycommon.RelayInfo, usage *dt
if reason != "accepted" && reason != "unchecked" {
params.Other.SetPublic("model_guard_result", reason)
}
log := &model.Log{UserId: info.UserId, Username: common.GetContextKeyString(c, constant.ContextKeyUserName), CreatedAt: time.Now().Unix(), Type: model.LogTypeConsume, Content: params.Content, TokenName: params.TokenName, ModelName: params.ModelName, Quota: params.Quota, PromptTokens: params.PromptTokens, CompletionTokens: params.CompletionTokens, UseTime: params.UseTimeSeconds, IsStream: params.IsStream, ChannelId: params.ChannelId, TokenId: params.TokenId, Group: params.Group, RequestId: info.RequestId, Other: params.Other.JSONString(), CorrelationKey: c.GetString("log_correlation_key")}
log := &model.Log{UserId: info.UserId, Username: common.GetContextKeyString(c, constant.ContextKeyUserName), CreatedAt: time.Now().Unix(), Type: model.LogTypeConsume, Content: params.Other.SetContent(params.Content), TokenName: params.TokenName, ModelName: params.ModelName, Quota: params.Quota, PromptTokens: params.PromptTokens, CompletionTokens: params.CompletionTokens, UseTime: params.UseTimeSeconds, IsStream: params.IsStream, ChannelId: params.ChannelId, TokenId: params.TokenId, Group: params.Group, RequestId: info.RequestId, Other: params.Other.JSONString(), CorrelationKey: c.GetString("log_correlation_key")}
billable := params.Quota > 0 || params.PromptTokens > 0 || params.CompletionTokens > 0
usageBody, _ := common.Marshal(usage)
logBody, _ := common.Marshal(log)
@@ -216,14 +217,14 @@ func (collector *GuardUsageCollector) Observe(payload []byte, stream bool) {
if collector.outputTokens == 0 {
text := ExtractOutputTextFromResponses(event.Response)
if text != "" {
collector.outputTokens = CountTextToken(text, collector.info.OriginModelName)
collector.outputTokens = tokenkit.Count(collector.info.OriginModelName, text)
collector.observed = true
}
}
}
if strings.HasSuffix(event.Type, ".delta") && event.Delta != "" {
collector.observed = true
collector.outputTokens += CountTextToken(event.Delta, collector.info.OriginModelName)
collector.outputTokens += tokenkit.Count(collector.info.OriginModelName, event.Delta)
}
if collector.hasUsage || collector.observed || collector.ctx.GetString("attempt_returned_model") != "" && collector.ctx.GetString("attempt_returned_model") != collector.info.OriginModelName {
if time.Since(collector.lastCheckpoint) > time.Second || collector.hasUsage {