pub struct ModelFacts { /* private fields */ }Expand description
The facts a completion wire encodes with: the spec of the model it was
connected to, and the catalog that spec came from, which answers for any
other model a request names. Every completion wire holds one, and its
Descriptor hands it to the completion fold,
which prices usage from it.
The default binds no spec and answers from Catalog::builtin. Facts
are not part of a wire’s serialized form or of its equality: a wire read
back from storage answers from the built-in catalog until it is given
facts again. Clones are cheap.
use rig_core::catalog::{Catalog, ModelFacts, Pricing};
use rig_core::providers::registry::ProviderId;
let anthropic = ProviderId::catalog("anthropic").ok_or("a known vendor")?;
let mut catalog = Catalog::builtin().clone();
let spec = catalog.get_exact(anthropic, "claude-haiku-4-5").ok_or("listed")?;
catalog.insert(spec.clone().with_pricing(Pricing::new(0.5, 2.5)));
let facts = catalog.facts(anthropic, "claude-haiku-4-5-20990101");
let spec = facts.for_model("anthropic", "claude-haiku-4-5-20990101").ok_or("bound")?;
assert_eq!(spec.pricing.as_ref().map(|pricing| pricing.input), Some(0.5));Implementations§
Source§impl ModelFacts
impl ModelFacts
Sourcepub fn new(spec: impl Into<Arc<ModelSpec>>) -> Self
pub fn new(spec: impl Into<Arc<ModelSpec>>) -> Self
The facts of spec, for the model it lists. Any other model is
answered from Catalog::builtin.
Sourcepub fn with_catalog(self, catalog: &Catalog) -> Self
pub fn with_catalog(self, catalog: &Catalog) -> Self
The same facts, answering every model but the bound one from
catalog.
Sourcepub fn spec(&self) -> Option<&ModelSpec>
pub fn spec(&self) -> Option<&ModelSpec>
The spec of the model the wire was connected to, when it was connected through the catalog or given one.
Sourcepub fn for_model(&self, vendor: &str, model: &str) -> Option<&ModelSpec>
pub fn for_model(&self, vendor: &str, model: &str) -> Option<&ModelSpec>
The facts of vendor’s model: the bound spec when model is the id
the wire was connected to (or the id the spec lists), otherwise the
catalog’s entry by Catalog::get’s rule. None for a model the
catalog does not list. vendor is the provider’s descriptor name
("anthropic", "aws_bedrock").
A spec under a catalog vendor answers only under that vendor, since a wire also asks about other vendors’ rows for its model. A spec under a declared vendor answers under any: no wire carries a declared vendor’s name, so the wire it was bound to asks under its own.
Trait Implementations§
Source§impl Clone for ModelFacts
impl Clone for ModelFacts
Source§impl Debug for ModelFacts
impl Debug for ModelFacts
Source§impl Default for ModelFacts
impl Default for ModelFacts
impl Eq for ModelFacts
Source§impl PartialEq for ModelFacts
Facts take no part in a wire’s equality, as they take none in its
serialized form: two wires that send the same requests are equal.
impl PartialEq for ModelFacts
Facts take no part in a wire’s equality, as they take none in its serialized form: two wires that send the same requests are equal.
Auto Trait Implementations§
impl Freeze for ModelFacts
impl RefUnwindSafe for ModelFacts
impl Send for ModelFacts
impl Sync for ModelFacts
impl Unpin for ModelFacts
impl UnsafeUnpin for ModelFacts
impl UnwindSafe for ModelFacts
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,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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 more