pub struct ModelRegistry { /* private fields */ }Expand description
Model registry with embedded + dynamic models
The registry maintains two sets of models:
- Embedded models: Compiled into the binary, always available
- Dynamic models: Fetched at runtime (optional), stored in RwLock
§Example
use m2m::models::ModelRegistry;
let registry = ModelRegistry::new();
// Lookup by ID
let card = registry.get("openai/gpt-4o").unwrap();
assert_eq!(card.abbrev, "og4o");
// Lookup by abbreviation
let card = registry.get("ml3170i").unwrap();
assert_eq!(card.id, "meta-llama/llama-3.1-70b-instruct");
// Abbreviate a model name
let abbrev = registry.abbreviate("openai/gpt-4o");
assert_eq!(abbrev, "og4o");
// Expand an abbreviation
let id = registry.expand("og4o").unwrap();
assert_eq!(id, "openai/gpt-4o");Implementations§
Source§impl ModelRegistry
impl ModelRegistry
Sourcepub fn get(&self, id_or_abbrev: &str) -> Option<ModelCard>
pub fn get(&self, id_or_abbrev: &str) -> Option<ModelCard>
Get a model by ID or abbreviation
Tries lookups in order:
- Direct ID match in embedded models
- Abbreviation match
- Dynamic models (if any)
Sourcepub fn get_encoding(&self, model: &str) -> Encoding
pub fn get_encoding(&self, model: &str) -> Encoding
Get the encoding for a model (with fallback inference)
If the model is not in the registry, infers encoding from the model ID.
Sourcepub fn get_context_length(&self, model: &str) -> u32
pub fn get_context_length(&self, model: &str) -> u32
Get the context length for a model (with safe default)
Sourcepub fn abbreviate(&self, model_id: &str) -> String
pub fn abbreviate(&self, model_id: &str) -> String
Abbreviate a model ID
Returns the abbreviation from the registry if available, otherwise generates one using the standard algorithm.
Sourcepub fn expand(&self, abbrev: &str) -> Option<String>
pub fn expand(&self, abbrev: &str) -> Option<String>
Expand an abbreviation to full model ID
Returns None if the abbreviation is not recognized.
Sourcepub fn list_abbrevs(&self) -> Vec<&str>
pub fn list_abbrevs(&self) -> Vec<&str>
List all known abbreviations
Sourcepub fn embedded_count(&self) -> usize
pub fn embedded_count(&self) -> usize
Get count of embedded models
Sourcepub fn dynamic_count(&self) -> usize
pub fn dynamic_count(&self) -> usize
Get count of dynamic models
Sourcepub fn add_dynamic(&self, card: ModelCard) -> Result<()>
pub fn add_dynamic(&self, card: ModelCard) -> Result<()>
Add a model to the dynamic registry
Sourcepub fn clear_dynamic(&self) -> Result<()>
pub fn clear_dynamic(&self) -> Result<()>
Clear dynamic models
Sourcepub fn get_by_provider(&self, provider: Provider) -> Vec<ModelCard>
pub fn get_by_provider(&self, provider: Provider) -> Vec<ModelCard>
Get models filtered by provider
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ModelRegistry
impl RefUnwindSafe for ModelRegistry
impl Send for ModelRegistry
impl Sync for ModelRegistry
impl Unpin for ModelRegistry
impl UnwindSafe for ModelRegistry
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
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
Converts
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>
Converts
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