فهرست منبع

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

CaIon 6 ماه پیش
والد
کامیت
c5a1cbe755
1فایلهای تغییر یافته به همراه9 افزوده شده و 4 حذف شده
  1. 9 4
      service/token_counter.go

+ 9 - 4
service/token_counter.go

@@ -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) {
-	if meta == nil {
-		return 0, errors.New("token count meta is nil")
+	if !constant.GetMediaToken {
+		return 0, nil
+	}
+	if !constant.GetMediaTokenNotStream && !info.IsStream {
+		return 0, nil
 	}
-
 	if info.RelayFormat == types.RelayFormatOpenAIRealtime {
 		return 0, nil
 	}
+	if meta == nil {
+		return 0, errors.New("token count meta is nil")
+	}
 
 	model := common.GetContextKeyString(c, constant.ContextKeyOriginalModel)
 	tkm := 0
@@ -276,7 +281,7 @@ func CountRequestToken(c *gin.Context, meta *types.TokenCountMeta, info *relayco
 
 	shouldFetchFiles := true
 
-	if info.RelayFormat == types.RelayFormatOpenAIRealtime || info.RelayFormat == types.RelayFormatGemini {
+	if info.RelayFormat == types.RelayFormatGemini {
 		shouldFetchFiles = false
 	}