mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-04-19 00:07:27 +00:00
Merge pull request #2670 from seefs001/fix/chat2claude-log
This commit is contained in:
@@ -335,6 +335,7 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage
|
|||||||
|
|
||||||
var audioInputQuota decimal.Decimal
|
var audioInputQuota decimal.Decimal
|
||||||
var audioInputPrice float64
|
var audioInputPrice float64
|
||||||
|
isClaudeUsageSemantic := relayInfo.ChannelType == constant.ChannelTypeAnthropic
|
||||||
if !relayInfo.PriceData.UsePrice {
|
if !relayInfo.PriceData.UsePrice {
|
||||||
baseTokens := dPromptTokens
|
baseTokens := dPromptTokens
|
||||||
// 减去 cached tokens
|
// 减去 cached tokens
|
||||||
@@ -342,14 +343,14 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage
|
|||||||
// OpenAI/OpenRouter 等 API 的 prompt_tokens 包含缓存 tokens,需要减去
|
// OpenAI/OpenRouter 等 API 的 prompt_tokens 包含缓存 tokens,需要减去
|
||||||
var cachedTokensWithRatio decimal.Decimal
|
var cachedTokensWithRatio decimal.Decimal
|
||||||
if !dCacheTokens.IsZero() {
|
if !dCacheTokens.IsZero() {
|
||||||
if relayInfo.ChannelType != constant.ChannelTypeAnthropic {
|
if !isClaudeUsageSemantic {
|
||||||
baseTokens = baseTokens.Sub(dCacheTokens)
|
baseTokens = baseTokens.Sub(dCacheTokens)
|
||||||
}
|
}
|
||||||
cachedTokensWithRatio = dCacheTokens.Mul(dCacheRatio)
|
cachedTokensWithRatio = dCacheTokens.Mul(dCacheRatio)
|
||||||
}
|
}
|
||||||
var dCachedCreationTokensWithRatio decimal.Decimal
|
var dCachedCreationTokensWithRatio decimal.Decimal
|
||||||
if !dCachedCreationTokens.IsZero() {
|
if !dCachedCreationTokens.IsZero() {
|
||||||
if relayInfo.ChannelType != constant.ChannelTypeAnthropic {
|
if !isClaudeUsageSemantic {
|
||||||
baseTokens = baseTokens.Sub(dCachedCreationTokens)
|
baseTokens = baseTokens.Sub(dCachedCreationTokens)
|
||||||
}
|
}
|
||||||
dCachedCreationTokensWithRatio = dCachedCreationTokens.Mul(dCachedCreationRatio)
|
dCachedCreationTokensWithRatio = dCachedCreationTokens.Mul(dCachedCreationRatio)
|
||||||
@@ -459,6 +460,11 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage
|
|||||||
}
|
}
|
||||||
logContent := strings.Join(extraContent, ", ")
|
logContent := strings.Join(extraContent, ", ")
|
||||||
other := service.GenerateTextOtherInfo(ctx, relayInfo, modelRatio, groupRatio, completionRatio, cacheTokens, cacheRatio, modelPrice, relayInfo.PriceData.GroupRatioInfo.GroupSpecialRatio)
|
other := service.GenerateTextOtherInfo(ctx, relayInfo, modelRatio, groupRatio, completionRatio, cacheTokens, cacheRatio, modelPrice, relayInfo.PriceData.GroupRatioInfo.GroupSpecialRatio)
|
||||||
|
// For chat-based calls to the Claude model, tagging is required. Using Claude's rendering logs, the two approaches handle input rendering differently.
|
||||||
|
if isClaudeUsageSemantic {
|
||||||
|
other["claude"] = true
|
||||||
|
other["usage_semantic"] = "anthropic"
|
||||||
|
}
|
||||||
if imageTokens != 0 {
|
if imageTokens != 0 {
|
||||||
other["image"] = true
|
other["image"] = true
|
||||||
other["image_ratio"] = imageRatio
|
other["image_ratio"] = imageRatio
|
||||||
|
|||||||
Reference in New Issue
Block a user