Commit d1f3f2c3 by CaIon

fix(token_counter): update token counting logic to handle media token conditions

parent d92c9db6
...@@ -250,13 +250,18 @@ func getImageToken(fileMeta *types.FileMeta, model string, stream bool) (int, er ...@@ -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 ...@@ -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
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment