fix(token_counter): update token counting logic to handle media token conditions
This commit is contained in:
parent
d92c9db61c
commit
d1f3f2c395
@ -250,13 +250,18 @@ func getImageToken(fileMeta *types.FileMeta, model string, stream bool) (int, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
func CountRequestToken(c *gin.Context, meta *types.TokenCountMeta, info *relaycommon.RelayInfo) (int, error) {
|
func CountRequestToken(c *gin.Context, meta *types.TokenCountMeta, info *relaycommon.RelayInfo) (int, error) {
|
||||||
if meta == nil {
|
if !constant.GetMediaToken {
|
||||||
return 0, errors.New("token count meta is nil")
|
return 0, nil
|
||||||
|
}
|
||||||
|
if !constant.GetMediaTokenNotStream && !info.IsStream {
|
||||||
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if info.RelayFormat == types.RelayFormatOpenAIRealtime {
|
if info.RelayFormat == types.RelayFormatOpenAIRealtime {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
if meta == nil {
|
||||||
|
return 0, errors.New("token count meta is nil")
|
||||||
|
}
|
||||||
|
|
||||||
model := common.GetContextKeyString(c, constant.ContextKeyOriginalModel)
|
model := common.GetContextKeyString(c, constant.ContextKeyOriginalModel)
|
||||||
tkm := 0
|
tkm := 0
|
||||||
@ -276,7 +281,7 @@ func CountRequestToken(c *gin.Context, meta *types.TokenCountMeta, info *relayco
|
|||||||
|
|
||||||
shouldFetchFiles := true
|
shouldFetchFiles := true
|
||||||
|
|
||||||
if info.RelayFormat == types.RelayFormatOpenAIRealtime || info.RelayFormat == types.RelayFormatGemini {
|
if info.RelayFormat == types.RelayFormatGemini {
|
||||||
shouldFetchFiles = false
|
shouldFetchFiles = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user