@@ -189,19 +189,21 @@ protected virtual int CountTokens(string? text, ReadOnlySpan<char> textSpan, Enc
189189        /// <param name="text">The text to encode.</param> 
190190        /// <param name="considerPreTokenization">Indicate whether to consider pre-tokenization before tokenization.</param> 
191191        /// <param name="considerNormalization">Indicate whether to consider normalization before tokenization.</param> 
192+         /// <param name="maxTokenCount">Indicate whether to consider a max token count for counting tokens.</param> 
192193        /// <returns>The number of token Ids that the input text will be encoded to.</returns> 
193-         public  int  CountTokens ( string  text ,  bool  considerPreTokenization  =  true ,  bool  considerNormalization  =  true ) 
194-             =>  CountTokens ( text ,  text . AsSpan ( ) ,  new  EncodeSettings  {  ConsiderPreTokenization  =  considerPreTokenization ,  ConsiderNormalization  =  considerNormalization  } ) ; 
194+         public  int  CountTokens ( string  text ,  bool  considerPreTokenization  =  true ,  bool  considerNormalization  =  true ,   int   maxTokenCount   =   int . MaxValue ) 
195+             =>  CountTokens ( text ,  text . AsSpan ( ) ,  new  EncodeSettings  {  ConsiderPreTokenization  =  considerPreTokenization ,  ConsiderNormalization  =  considerNormalization ,   MaxTokenCount   =   maxTokenCount  } ) ; 
195196
196197        /// <summary> 
197198        /// Get the number of tokens that the input text will be encoded to. 
198199        /// </summary> 
199200        /// <param name="text">The text to encode.</param> 
200201        /// <param name="considerPreTokenization">Indicate whether to consider pre-tokenization before tokenization.</param> 
201202        /// <param name="considerNormalization">Indicate whether to consider normalization before tokenization.</param> 
203+         /// <param name="maxTokenCount">Indicate whether to consider a max token count for counting tokens.</param> 
202204        /// <returns>The number of token Ids that the input text will be encoded to.</returns> 
203-         public  int  CountTokens ( ReadOnlySpan < char >  text ,  bool  considerPreTokenization  =  true ,  bool  considerNormalization  =  true ) 
204-             =>  CountTokens ( null ,  text ,  new  EncodeSettings  {  ConsiderPreTokenization  =  considerPreTokenization ,  ConsiderNormalization  =  considerNormalization  } ) ; 
205+         public  int  CountTokens ( ReadOnlySpan < char >  text ,  bool  considerPreTokenization  =  true ,  bool  considerNormalization  =  true ,   int   maxTokenCount   =   int . MaxValue ) 
206+             =>  CountTokens ( null ,  text ,  new  EncodeSettings  {  ConsiderPreTokenization  =  considerPreTokenization ,  ConsiderNormalization  =  considerNormalization ,   MaxTokenCount   =   maxTokenCount  } ) ; 
205207
206208        /// <summary> 
207209        /// Find the index of the maximum encoding capacity without surpassing the token limit. 
0 commit comments