feat(ratio): add functions to check for audio ratios and clean up unused code
This commit is contained in:
parent
7bbb7f8114
commit
87a75b0565
@ -18,6 +18,7 @@ import (
|
|||||||
"github.com/QuantumNous/new-api/service"
|
"github.com/QuantumNous/new-api/service"
|
||||||
"github.com/QuantumNous/new-api/setting/model_setting"
|
"github.com/QuantumNous/new-api/setting/model_setting"
|
||||||
"github.com/QuantumNous/new-api/setting/operation_setting"
|
"github.com/QuantumNous/new-api/setting/operation_setting"
|
||||||
|
"github.com/QuantumNous/new-api/setting/ratio_setting"
|
||||||
"github.com/QuantumNous/new-api/types"
|
"github.com/QuantumNous/new-api/types"
|
||||||
|
|
||||||
"github.com/shopspring/decimal"
|
"github.com/shopspring/decimal"
|
||||||
@ -181,7 +182,10 @@ func TextHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *types
|
|||||||
return newApiErr
|
return newApiErr
|
||||||
}
|
}
|
||||||
|
|
||||||
if usage.(*dto.Usage).CompletionTokenDetails.AudioTokens > 0 || usage.(*dto.Usage).PromptTokensDetails.AudioTokens > 0 {
|
var containAudioTokens = usage.(*dto.Usage).CompletionTokenDetails.AudioTokens > 0 || usage.(*dto.Usage).PromptTokensDetails.AudioTokens > 0
|
||||||
|
var containsAudioRatios = ratio_setting.ContainsAudioRatio(info.OriginModelName) || ratio_setting.ContainsAudioCompletionRatio(info.OriginModelName)
|
||||||
|
|
||||||
|
if containAudioTokens && containsAudioRatios {
|
||||||
service.PostAudioConsumeQuota(c, info, usage.(*dto.Usage), "")
|
service.PostAudioConsumeQuota(c, info, usage.(*dto.Usage), "")
|
||||||
} else {
|
} else {
|
||||||
postConsumeQuota(c, info, usage.(*dto.Usage))
|
postConsumeQuota(c, info, usage.(*dto.Usage))
|
||||||
|
|||||||
@ -674,6 +674,22 @@ func GetAudioCompletionRatio(name string) float64 {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ContainsAudioRatio(name string) bool {
|
||||||
|
audioRatioMapMutex.RLock()
|
||||||
|
defer audioRatioMapMutex.RUnlock()
|
||||||
|
name = FormatMatchingModelName(name)
|
||||||
|
_, ok := audioRatioMap[name]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func ContainsAudioCompletionRatio(name string) bool {
|
||||||
|
audioCompletionRatioMapMutex.RLock()
|
||||||
|
defer audioCompletionRatioMapMutex.RUnlock()
|
||||||
|
name = FormatMatchingModelName(name)
|
||||||
|
_, ok := audioCompletionRatioMap[name]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
func ModelRatio2JSONString() string {
|
func ModelRatio2JSONString() string {
|
||||||
modelRatioMapMutex.RLock()
|
modelRatioMapMutex.RLock()
|
||||||
defer modelRatioMapMutex.RUnlock()
|
defer modelRatioMapMutex.RUnlock()
|
||||||
@ -749,16 +765,6 @@ func UpdateAudioRatioByJSONString(jsonStr string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAudioRatioCopy() map[string]float64 {
|
|
||||||
audioRatioMapMutex.RLock()
|
|
||||||
defer audioRatioMapMutex.RUnlock()
|
|
||||||
copyMap := make(map[string]float64, len(audioRatioMap))
|
|
||||||
for k, v := range audioRatioMap {
|
|
||||||
copyMap[k] = v
|
|
||||||
}
|
|
||||||
return copyMap
|
|
||||||
}
|
|
||||||
|
|
||||||
func AudioCompletionRatio2JSONString() string {
|
func AudioCompletionRatio2JSONString() string {
|
||||||
audioCompletionRatioMapMutex.RLock()
|
audioCompletionRatioMapMutex.RLock()
|
||||||
defer audioCompletionRatioMapMutex.RUnlock()
|
defer audioCompletionRatioMapMutex.RUnlock()
|
||||||
@ -781,16 +787,6 @@ func UpdateAudioCompletionRatioByJSONString(jsonStr string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAudioCompletionRatioCopy() map[string]float64 {
|
|
||||||
audioCompletionRatioMapMutex.RLock()
|
|
||||||
defer audioCompletionRatioMapMutex.RUnlock()
|
|
||||||
copyMap := make(map[string]float64, len(audioCompletionRatioMap))
|
|
||||||
for k, v := range audioCompletionRatioMap {
|
|
||||||
copyMap[k] = v
|
|
||||||
}
|
|
||||||
return copyMap
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetModelRatioCopy() map[string]float64 {
|
func GetModelRatioCopy() map[string]float64 {
|
||||||
modelRatioMapMutex.RLock()
|
modelRatioMapMutex.RLock()
|
||||||
defer modelRatioMapMutex.RUnlock()
|
defer modelRatioMapMutex.RUnlock()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user