|
@@ -144,8 +144,7 @@ func PreWssConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usag
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func PostWssConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, modelName string,
|
|
func PostWssConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, modelName string,
|
|
|
- usage *dto.RealtimeUsage, preConsumedQuota int, userQuota int, modelRatio float64, groupRatio float64,
|
|
|
|
|
- modelPrice float64, usePrice bool, extraContent string) {
|
|
|
|
|
|
|
+ usage *dto.RealtimeUsage, preConsumedQuota int, userQuota int, priceData helper.PriceData, extraContent string) {
|
|
|
|
|
|
|
|
useTimeSeconds := time.Now().Unix() - relayInfo.StartTime.Unix()
|
|
useTimeSeconds := time.Now().Unix() - relayInfo.StartTime.Unix()
|
|
|
textInputTokens := usage.InputTokenDetails.TextTokens
|
|
textInputTokens := usage.InputTokenDetails.TextTokens
|
|
@@ -159,18 +158,11 @@ func PostWssConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, mod
|
|
|
audioRatio := decimal.NewFromFloat(operation_setting.GetAudioRatio(relayInfo.OriginModelName))
|
|
audioRatio := decimal.NewFromFloat(operation_setting.GetAudioRatio(relayInfo.OriginModelName))
|
|
|
audioCompletionRatio := decimal.NewFromFloat(operation_setting.GetAudioCompletionRatio(modelName))
|
|
audioCompletionRatio := decimal.NewFromFloat(operation_setting.GetAudioCompletionRatio(modelName))
|
|
|
|
|
|
|
|
- autoGroup, exists := ctx.Get("auto_group")
|
|
|
|
|
- if exists {
|
|
|
|
|
- groupRatio = setting.GetGroupRatio(autoGroup.(string))
|
|
|
|
|
- log.Printf("final group ratio: %f", groupRatio)
|
|
|
|
|
- relayInfo.Group = autoGroup.(string)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ modelRatio := priceData.ModelRatio
|
|
|
|
|
+ groupRatio := priceData.GroupRatioInfo.GroupRatio
|
|
|
|
|
+ modelPrice := priceData.ModelPrice
|
|
|
|
|
+ usePrice := priceData.UsePrice
|
|
|
|
|
|
|
|
- actualGroupRatio := groupRatio
|
|
|
|
|
- userGroupRatio, ok := setting.GetGroupGroupRatio(relayInfo.UserGroup, relayInfo.Group)
|
|
|
|
|
- if ok {
|
|
|
|
|
- actualGroupRatio = userGroupRatio
|
|
|
|
|
- }
|
|
|
|
|
quotaInfo := QuotaInfo{
|
|
quotaInfo := QuotaInfo{
|
|
|
InputDetails: TokenDetails{
|
|
InputDetails: TokenDetails{
|
|
|
TextTokens: textInputTokens,
|
|
TextTokens: textInputTokens,
|
|
@@ -183,7 +175,7 @@ func PostWssConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, mod
|
|
|
ModelName: modelName,
|
|
ModelName: modelName,
|
|
|
UsePrice: usePrice,
|
|
UsePrice: usePrice,
|
|
|
ModelRatio: modelRatio,
|
|
ModelRatio: modelRatio,
|
|
|
- GroupRatio: actualGroupRatio,
|
|
|
|
|
|
|
+ GroupRatio: groupRatio,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
quota := calculateAudioQuota(quotaInfo)
|
|
quota := calculateAudioQuota(quotaInfo)
|
|
@@ -215,7 +207,7 @@ func PostWssConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, mod
|
|
|
logContent += ", " + extraContent
|
|
logContent += ", " + extraContent
|
|
|
}
|
|
}
|
|
|
other := GenerateWssOtherInfo(ctx, relayInfo, usage, modelRatio, groupRatio,
|
|
other := GenerateWssOtherInfo(ctx, relayInfo, usage, modelRatio, groupRatio,
|
|
|
- completionRatio.InexactFloat64(), audioRatio.InexactFloat64(), audioCompletionRatio.InexactFloat64(), modelPrice, userGroupRatio)
|
|
|
|
|
|
|
+ completionRatio.InexactFloat64(), audioRatio.InexactFloat64(), audioCompletionRatio.InexactFloat64(), modelPrice, priceData.GroupRatioInfo.GroupSpecialRatio)
|
|
|
model.RecordConsumeLog(ctx, relayInfo.UserId, relayInfo.ChannelId, usage.InputTokens, usage.OutputTokens, logModel,
|
|
model.RecordConsumeLog(ctx, relayInfo.UserId, relayInfo.ChannelId, usage.InputTokens, usage.OutputTokens, logModel,
|
|
|
tokenName, quota, logContent, relayInfo.TokenId, userQuota, int(useTimeSeconds), relayInfo.IsStream, relayInfo.Group, other)
|
|
tokenName, quota, logContent, relayInfo.TokenId, userQuota, int(useTimeSeconds), relayInfo.IsStream, relayInfo.Group, other)
|
|
|
}
|
|
}
|
|
@@ -231,9 +223,8 @@ func PostClaudeConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo,
|
|
|
tokenName := ctx.GetString("token_name")
|
|
tokenName := ctx.GetString("token_name")
|
|
|
completionRatio := priceData.CompletionRatio
|
|
completionRatio := priceData.CompletionRatio
|
|
|
modelRatio := priceData.ModelRatio
|
|
modelRatio := priceData.ModelRatio
|
|
|
- groupRatio := priceData.GroupRatio
|
|
|
|
|
|
|
+ groupRatio := priceData.GroupRatioInfo.GroupRatio
|
|
|
modelPrice := priceData.ModelPrice
|
|
modelPrice := priceData.ModelPrice
|
|
|
- userGroupRatio := priceData.UserGroupRatio
|
|
|
|
|
cacheRatio := priceData.CacheRatio
|
|
cacheRatio := priceData.CacheRatio
|
|
|
cacheTokens := usage.PromptTokensDetails.CachedTokens
|
|
cacheTokens := usage.PromptTokensDetails.CachedTokens
|
|
|
|
|
|
|
@@ -282,7 +273,7 @@ func PostClaudeConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
other := GenerateClaudeOtherInfo(ctx, relayInfo, modelRatio, groupRatio, completionRatio,
|
|
other := GenerateClaudeOtherInfo(ctx, relayInfo, modelRatio, groupRatio, completionRatio,
|
|
|
- cacheTokens, cacheRatio, cacheCreationTokens, cacheCreationRatio, modelPrice, userGroupRatio)
|
|
|
|
|
|
|
+ cacheTokens, cacheRatio, cacheCreationTokens, cacheCreationRatio, modelPrice, priceData.GroupRatioInfo.GroupSpecialRatio)
|
|
|
model.RecordConsumeLog(ctx, relayInfo.UserId, relayInfo.ChannelId, promptTokens, completionTokens, modelName,
|
|
model.RecordConsumeLog(ctx, relayInfo.UserId, relayInfo.ChannelId, promptTokens, completionTokens, modelName,
|
|
|
tokenName, quota, logContent, relayInfo.TokenId, userQuota, int(useTimeSeconds), relayInfo.IsStream, relayInfo.Group, other)
|
|
tokenName, quota, logContent, relayInfo.TokenId, userQuota, int(useTimeSeconds), relayInfo.IsStream, relayInfo.Group, other)
|
|
|
}
|
|
}
|
|
@@ -303,23 +294,10 @@ func PostAudioConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo,
|
|
|
audioCompletionRatio := decimal.NewFromFloat(operation_setting.GetAudioCompletionRatio(relayInfo.OriginModelName))
|
|
audioCompletionRatio := decimal.NewFromFloat(operation_setting.GetAudioCompletionRatio(relayInfo.OriginModelName))
|
|
|
|
|
|
|
|
modelRatio := priceData.ModelRatio
|
|
modelRatio := priceData.ModelRatio
|
|
|
- groupRatio := priceData.GroupRatio
|
|
|
|
|
|
|
+ groupRatio := priceData.GroupRatioInfo.GroupRatio
|
|
|
modelPrice := priceData.ModelPrice
|
|
modelPrice := priceData.ModelPrice
|
|
|
usePrice := priceData.UsePrice
|
|
usePrice := priceData.UsePrice
|
|
|
|
|
|
|
|
- autoGroup, exists := ctx.Get("auto_group")
|
|
|
|
|
- if exists {
|
|
|
|
|
- groupRatio = setting.GetGroupRatio(autoGroup.(string))
|
|
|
|
|
- log.Printf("final group ratio: %f", groupRatio)
|
|
|
|
|
- relayInfo.Group = autoGroup.(string)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- actualGroupRatio := groupRatio
|
|
|
|
|
- userGroupRatio, ok := setting.GetGroupGroupRatio(relayInfo.UserGroup, relayInfo.Group)
|
|
|
|
|
- if ok {
|
|
|
|
|
- actualGroupRatio = userGroupRatio
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
quotaInfo := QuotaInfo{
|
|
quotaInfo := QuotaInfo{
|
|
|
InputDetails: TokenDetails{
|
|
InputDetails: TokenDetails{
|
|
|
TextTokens: textInputTokens,
|
|
TextTokens: textInputTokens,
|
|
@@ -332,7 +310,7 @@ func PostAudioConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo,
|
|
|
ModelName: relayInfo.OriginModelName,
|
|
ModelName: relayInfo.OriginModelName,
|
|
|
UsePrice: usePrice,
|
|
UsePrice: usePrice,
|
|
|
ModelRatio: modelRatio,
|
|
ModelRatio: modelRatio,
|
|
|
- GroupRatio: actualGroupRatio,
|
|
|
|
|
|
|
+ GroupRatio: groupRatio,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
quota := calculateAudioQuota(quotaInfo)
|
|
quota := calculateAudioQuota(quotaInfo)
|
|
@@ -372,7 +350,7 @@ func PostAudioConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo,
|
|
|
logContent += ", " + extraContent
|
|
logContent += ", " + extraContent
|
|
|
}
|
|
}
|
|
|
other := GenerateAudioOtherInfo(ctx, relayInfo, usage, modelRatio, groupRatio,
|
|
other := GenerateAudioOtherInfo(ctx, relayInfo, usage, modelRatio, groupRatio,
|
|
|
- completionRatio.InexactFloat64(), audioRatio.InexactFloat64(), audioCompletionRatio.InexactFloat64(), modelPrice, userGroupRatio)
|
|
|
|
|
|
|
+ completionRatio.InexactFloat64(), audioRatio.InexactFloat64(), audioCompletionRatio.InexactFloat64(), modelPrice, priceData.GroupRatioInfo.GroupSpecialRatio)
|
|
|
model.RecordConsumeLog(ctx, relayInfo.UserId, relayInfo.ChannelId, usage.PromptTokens, usage.CompletionTokens, logModel,
|
|
model.RecordConsumeLog(ctx, relayInfo.UserId, relayInfo.ChannelId, usage.PromptTokens, usage.CompletionTokens, logModel,
|
|
|
tokenName, quota, logContent, relayInfo.TokenId, userQuota, int(useTimeSeconds), relayInfo.IsStream, relayInfo.Group, other)
|
|
tokenName, quota, logContent, relayInfo.TokenId, userQuota, int(useTimeSeconds), relayInfo.IsStream, relayInfo.Group, other)
|
|
|
}
|
|
}
|