pub struct TokenSequence {
pub vocabulary_id: VocabularyId,
pub vocabulary_version: Version,
pub vocabulary_digest: String,
pub modality: Modality,
pub adapter: Option<String>,
pub ids: Vec<u32>,
pub escapes: Vec<String>,
}Expand description
Token ids scoped to the exact vocabulary that produced them.
Ids from different vocabularies are never interchangeable, so a sequence always travels with the vocabulary id, version and content digest.
Fields§
§vocabulary_id: VocabularyId§vocabulary_version: Version§vocabulary_digest: String§modality: Modality§adapter: Option<String>§ids: Vec<u32>§escapes: Vec<String>Symbols the vocabulary does not contain, carried literally. An id of
vocabulary length + i stands for escapes[i]. Empty unless the
sequence was encoded with UnknownPolicy::Escape.
Implementations§
Source§impl TokenSequence
impl TokenSequence
Sourcepub fn to_bytes(&self) -> Result<Vec<u8>, KuteError>
pub fn to_bytes(&self) -> Result<Vec<u8>, KuteError>
Serialize to the .kute container: magic, little-endian header length,
JSON header, then LEB128 varint token ids.
Sourcepub fn to_bytes_compressed(&self) -> Result<Vec<u8>, KuteError>
pub fn to_bytes_compressed(&self) -> Result<Vec<u8>, KuteError>
Serialize to the compressed .kute container (format 2): the same
header, then the ids as fixed-width little-endian integers inside one
zlib stream. Smaller than format 1 on anything repetitive; from_bytes
reads both.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<TokenSequence, KuteError>
pub fn from_bytes(bytes: &[u8]) -> Result<TokenSequence, KuteError>
Parse a .kute container of either format. Rejects truncated,
oversized or trailing data.
A compressed container can hold about four thousand times its own
size in ids. For a container from a party you do not trust, use
TokenSequence::from_bytes_bounded.
Sourcepub fn from_bytes_bounded(
bytes: &[u8],
max_tokens: u64,
) -> Result<TokenSequence, KuteError>
pub fn from_bytes_bounded( bytes: &[u8], max_tokens: u64, ) -> Result<TokenSequence, KuteError>
As TokenSequence::from_bytes, but a container that declares more
than max_tokens tokens is refused before any id is read or
decompressed, so the caller decides how much memory a container may
claim.
Trait Implementations§
Source§impl Clone for TokenSequence
impl Clone for TokenSequence
Source§fn clone(&self) -> TokenSequence
fn clone(&self) -> TokenSequence
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TokenSequence
impl Debug for TokenSequence
Source§impl<'de> Deserialize<'de> for TokenSequence
impl<'de> Deserialize<'de> for TokenSequence
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<TokenSequence, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<TokenSequence, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for TokenSequence
Source§impl PartialEq for TokenSequence
impl PartialEq for TokenSequence
Source§impl Serialize for TokenSequence
impl Serialize for TokenSequence
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for TokenSequence
Auto Trait Implementations§
impl Forget for TokenSequence
impl Freeze for TokenSequence
impl Move for TokenSequence
impl RefUnwindSafe for TokenSequence
impl Send for TokenSequence
impl Sync for TokenSequence
impl Unpin for TokenSequence
impl UnsafeUnpin for TokenSequence
impl UnwindSafe for TokenSequence
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more