mirror of
https://github.com/BerriAI/litellm.git
synced 2026-12-03 01:38:46 +00:00
* refactor(rust): standardize Azure Messages module path * docs(rust): define shared types crate boundaries * refactor(rust): share request helpers and type Anthropic blocks * docs(rust): format shared type invariants as bullets * test(rust): parameterize repeated cases with rstest * refactor(rust): move Responses transform result into llms * fix(anthropic): validate chat and batch responses * docs(rust): clarify API format ownership boundaries * docs: clarify Rust error message construction * refactor(auth): keep shared Rust errors provider-neutral * refactor(rust): separate format contracts from provider policy * fix(rust): type Anthropic chat response text collection * fix(rust): pass audio secret sources through hosts * fix(rust): unblock batch lint and OCR error assertions * test(rust): assert response failures at the adapter boundary * refactor(rust): declare error messages with typed context * wip * fix(rust): adapt Bedrock error details * style(rust): cargo fmt bedrock audio transcription Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(rust): adapt tests and dead code to typed error details Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(rust): keep converse error contracts and read env secrets without litellm Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * ci(rust): raise the native wheel size gate to 45 MB Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(rust): tolerate missing usage in converse responses on the transcription route Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Yujong Lee <yujong@berri.ai> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
47 lines
1.4 KiB
Rust
47 lines
1.4 KiB
Rust
use litellm_token_counter_tiktoken::{LoadError, UnsupportedTokenizer};
|
|
pub use litellm_token_counter_tiktoken::{TiktokenTokenizer, Vocabulary, encoding_for_model};
|
|
|
|
use crate::{Error, TextCodec, TokenCounter, Tokenizer};
|
|
|
|
impl TokenCounter {
|
|
pub fn from_tiktoken(encoding: &str) -> Result<Self, Error> {
|
|
TiktokenTokenizer::from_name(encoding)
|
|
.map(Self::new)
|
|
.map_err(Error::from)
|
|
}
|
|
}
|
|
|
|
impl Tokenizer for TiktokenTokenizer {
|
|
fn count_tokens(&self, text: &str) -> Result<usize, Error> {
|
|
Ok(TiktokenTokenizer::count_tokens(self, text))
|
|
}
|
|
}
|
|
|
|
impl TextCodec for TiktokenTokenizer {
|
|
fn encode(&self, text: &str) -> Result<Vec<u32>, Error> {
|
|
Ok(TiktokenTokenizer::encode(self, text))
|
|
}
|
|
|
|
fn decode(&self, ids: &[u32], _skip_special_tokens: bool) -> Result<String, Error> {
|
|
TiktokenTokenizer::decode(self, ids).map_err(|error| Error::Decode(error.to_string()))
|
|
}
|
|
|
|
fn name(&self) -> &str {
|
|
TiktokenTokenizer::name(self)
|
|
}
|
|
}
|
|
|
|
impl From<UnsupportedTokenizer> for Error {
|
|
fn from(error: UnsupportedTokenizer) -> Self {
|
|
Self::UnsupportedTokenizer(error.0)
|
|
}
|
|
}
|
|
|
|
impl From<LoadError> for Error {
|
|
fn from(error: LoadError) -> Self {
|
|
match error {
|
|
LoadError::Unsupported(error) => error.into(),
|
|
LoadError::Ranks(source) => Self::Ranks(source.into()),
|
|
}
|
|
}
|
|
}
|