pub struct ProviderIndex { /* private fields */ }Expand description
Immutable provider catalog with O(1) lookup by id.
The catalog is compiled into the binary from catalog.json via include_str!.
Access it through ProviderIndex::embedded().
Implementations§
Source§impl ProviderIndex
impl ProviderIndex
Sourcepub fn from_providers(providers: Vec<ServiceDescriptor>) -> Self
pub fn from_providers(providers: Vec<ServiceDescriptor>) -> Self
Build a ProviderIndex from an explicit list of providers.
Useful for tests, overlays, or merging discovered providers into the
embedded catalog. Provider order is preserved. The embedded catalog has
no duplicate ids; if duplicates are passed, ProviderIndex::get
resolves to the last occurrence while ProviderIndex::all retains
every entry.
Sourcepub fn embedded() -> &'static ProviderIndex
pub fn embedded() -> &'static ProviderIndex
Access the static catalog embedded at compile time.
Sourcepub fn with_discovered(&self, discovered: &[ModelEntry]) -> ProviderIndex
pub fn with_discovered(&self, discovered: &[ModelEntry]) -> ProviderIndex
Return a new catalog where discovered model entries overlay this one.
For a discovered entry whose provider_id matches an existing provider,
its model is merged into that provider (replacing on id collision,
appending otherwise). Entries whose provider_id is not in the catalog
are gathered under a synthetic "discovered" provider.
This resolves the catalog↔discovery gap: once merged, discovered models
are visible to ProviderIndex::find_model and
ProviderIndex::estimate_cost. The catalog is not mutated; an owned
ProviderIndex is returned.
Sourcepub fn all(&self) -> &[ServiceDescriptor]
pub fn all(&self) -> &[ServiceDescriptor]
Return all providers in catalog order.
Sourcepub fn get(&self, id: &str) -> Option<&ServiceDescriptor>
pub fn get(&self, id: &str) -> Option<&ServiceDescriptor>
Look up a provider by ID. O(1).
Sourcepub fn categories(&self) -> Vec<String>
pub fn categories(&self) -> Vec<String>
Unique categories in catalog order.
Sourcepub fn providers_by_category(&self, category: &str) -> Vec<&ServiceDescriptor>
pub fn providers_by_category(&self, category: &str) -> Vec<&ServiceDescriptor>
Filter providers by category.
Sourcepub fn builtin_secret_keys(&self) -> HashSet<String>
pub fn builtin_secret_keys(&self) -> HashSet<String>
Collect all secret key variable names from providers that require one.
Sourcepub fn models_for(&self, provider_id: &str) -> &[ModelDescriptor]
pub fn models_for(&self, provider_id: &str) -> &[ModelDescriptor]
Get models for a specific provider.
Sourcepub fn find_model(
&self,
model_id: &str,
) -> Option<(&ServiceDescriptor, &ModelDescriptor)>
pub fn find_model( &self, model_id: &str, ) -> Option<(&ServiceDescriptor, &ModelDescriptor)>
Find a model by ID across all providers. Returns the first match (provider, model).
Sourcepub fn estimate_cost(
&self,
model_id: &str,
prompt_tokens: u32,
completion_tokens: u32,
) -> Option<f64>
pub fn estimate_cost( &self, model_id: &str, prompt_tokens: u32, completion_tokens: u32, ) -> Option<f64>
Estimate the USD cost of an LLM call given token counts.
Looks up model_id across all providers and computes:
(input_price * prompt_tokens + output_price * completion_tokens) / 1_000_000
Returns None if the model is not found or has no pricing data.
Trait Implementations§
Source§impl Clone for ProviderIndex
impl Clone for ProviderIndex
Source§fn clone(&self) -> ProviderIndex
fn clone(&self) -> ProviderIndex
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ProviderIndex
impl RefUnwindSafe for ProviderIndex
impl Send for ProviderIndex
impl Sync for ProviderIndex
impl Unpin for ProviderIndex
impl UnsafeUnpin for ProviderIndex
impl UnwindSafe for ProviderIndex
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
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>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.