We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e20fc1a commit 477d1afCopy full SHA for 477d1af
crates/bpe-openai/src/lib.rs
@@ -86,6 +86,15 @@ impl Tokenizer {
86
.sum()
87
}
88
89
+ pub fn count_till_limit(&self, text: &str, token_limit: usize) -> Option<usize> {
90
+ self.split(text)
91
+ .try_fold(token_limit, |token_limit, piece| {
92
+ self.bpe
93
+ .count_till_limit(piece.as_bytes(), token_limit)
94
+ .map(|piece_count| token_limit - piece_count)
95
+ })
96
+ }
97
+
98
pub fn encode(&self, text: &str) -> Vec<u32> {
99
self.split(text)
100
.flat_map(|piece| self.bpe.encode_via_backtracking(piece.as_bytes()))
0 commit comments