Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,15 +598,14 @@ impl CoreBPE {
(tokens, completions)
}

pub fn new<E, SE, NSE>(
pub fn new<E, SE>(
encoder: E,
special_tokens_encoder: SE,
pattern: &str,
) -> Result<Self, Box<dyn std::error::Error + Send + Sync>>
where
E: IntoIterator<Item = (Vec<u8>, Rank)>,
SE: IntoIterator<Item = (String, Rank)>,
NSE: IntoIterator<Item = (String, (Rank, Rank))>,
{
Self::new_internal(
HashMap::from_iter(encoder),
Expand Down Expand Up @@ -677,10 +676,9 @@ impl CoreBPE {

#[cfg(test)]
mod tests {
use fancy_regex::Regex;
use rustc_hash::FxHashMap as HashMap;

use crate::{Rank, byte_pair_split};
use crate::{CoreBPE, Rank, byte_pair_split};

fn setup_ranks() -> HashMap<Vec<u8>, Rank> {
HashMap::from_iter([(b"ab".to_vec(), 0), (b"cd".to_vec(), 1)])
Expand All @@ -699,4 +697,16 @@ mod tests {
let res = byte_pair_split(b"abab", &ranks);
assert_eq!(res, vec![b"ab", b"ab"]);
}

#[test]
fn test_public_constructor_is_callable() {
let bpe = CoreBPE::new(
vec![(b"ab".to_vec(), 0)],
Vec::<(String, Rank)>::new(),
r".+",
)
.unwrap();

assert_eq!(bpe.encode_ordinary("ab"), vec![0]);
}
}