From c2cccc8df24fe8b0961c555a13009935495a1b85 Mon Sep 17 00:00:00 2001 From: Arthur Zucker Date: Sun, 4 Aug 2024 19:31:05 +0200 Subject: [PATCH] propagate to pre_tokenizer --- bindings/python/src/pre_tokenizers.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bindings/python/src/pre_tokenizers.rs b/bindings/python/src/pre_tokenizers.rs index a2bd9b39c..a30b4ca82 100644 --- a/bindings/python/src/pre_tokenizers.rs +++ b/bindings/python/src/pre_tokenizers.rs @@ -450,6 +450,24 @@ impl PySequence { fn __getnewargs__<'p>(&self, py: Python<'p>) -> Bound<'p, PyTuple> { PyTuple::new_bound(py, [PyList::empty_bound(py)]) } + + fn __getitem__(self_: PyRef<'_, Self>, py: Python<'_>, index: usize) -> PyResult> { + match &self_.as_ref().pretok { + PyPreTokenizerTypeWrapper::Sequence(inner) => match inner.get(index) { + Some(item) => { + PyPreTokenizer::new(PyPreTokenizerTypeWrapper::Single(Arc::clone(item))) + .get_as_subtype(py) + } + _ => Err(PyErr::new::( + "Index not found", + )), + }, + PyPreTokenizerTypeWrapper::Single(inner) => { + PyPreTokenizer::new(PyPreTokenizerTypeWrapper::Single(Arc::clone(inner))) + .get_as_subtype(py) + } + } + } } pub(crate) fn from_string(string: String) -> Result {