pub struct DynModel<Op>where
Op: Operation,{ /* private fields */ }Expand description
A model of one operation with its wire and transport erased. Clones share
the model. Built with Model::erase or From<Model<W, T>>, so a
consumer takes impl Into<DynModel<Op>> and accepts either.
Every call runs the driver the concrete model runs: spans, request ids, the operation’s fold and error enrichment are the same.
A model used by one consumer is passed as is; a model shared by several
is erased once and the handle is cloned. A model a handler table serves
is a ModelHandle in the agent runtime instead: its calls are
dispatched, recorded and observed there.
use rig_core::embeddings::EmbeddingsBuilder;
use rig_core::vector_store::in_memory_store::InMemoryVectorStore;
use rig_core::{Model, providers::openai::{self, OpenAIConfig}};
let model = OpenAIConfig::from_env()?.connect(http).embedding(openai::TEXT_EMBEDDING_3_SMALL, None).erase();
let embeddings = EmbeddingsBuilder::new(model.clone())
.documents(["a document".to_owned()])?
.build()
.await?;
let index = InMemoryVectorStore::from_documents(embeddings).index(model);Implementations§
Source§impl<Op> DynModel<Op>where
Op: Operation,
impl<Op> DynModel<Op>where
Op: Operation,
Sourcepub fn id(&self) -> Option<&str>
pub fn id(&self) -> Option<&str>
The model id the wire addresses, when the operation addresses one.
Sourcepub fn spec(&self) -> Option<&ModelSpec>
pub fn spec(&self) -> Option<&ModelSpec>
The catalog facts of the model the wire addresses: the spec it was
connected to, else the catalog’s entry for its id. None for an
operation that addresses no model, or a model the catalog does not
list.
Sourcepub fn capabilities(&self) -> Capabilities
pub fn capabilities(&self) -> Capabilities
What a runtime accounts for about this model.
Sourcepub fn call(
&self,
request: impl Into<<Op as Operation>::Request>,
) -> impl Future<Output = Result<<Op as Operation>::Response, ProviderError>> + WasmCompatSend + 'static
pub fn call( &self, request: impl Into<<Op as Operation>::Request>, ) -> impl Future<Output = Result<<Op as Operation>::Response, ProviderError>> + WasmCompatSend + 'static
Send request and fold the whole reply into the operation’s
response; Model::call with the model erased. The call owns what
it sends, so it can be spawned.
Sourcepub fn stream(
&self,
request: impl Into<<Op as Operation>::Request>,
) -> Result<Streamed<Op>, ProviderError>
pub fn stream( &self, request: impl Into<<Op as Operation>::Request>, ) -> Result<Streamed<Op>, ProviderError>
Open a streamed reply; Model::stream with the model erased.
Source§impl DynModel<Completion>
impl DynModel<Completion>
Sourcepub fn check(&self, request: &CompletionRequest) -> Result<(), CheckError>
pub fn check(&self, request: &CompletionRequest) -> Result<(), CheckError>
Every option of request this model would refuse, with nothing
sent; Model::check with the model erased.
use rig_core::catalog::Catalog;
use rig_core::completion::{CheckError, CompletionRequest, Effort};
use rig_core::providers::registry::ConnectOptions;
let model = Catalog::builtin().connect_with("openai/gpt-6-sol", ConnectOptions::new())?;
let request = CompletionRequest::new("hi")
.temperature(0.2)
.reasoning(Effort::High);
if let Err(CheckError::Unsupported(refused)) = model.check(&request) {
for refusal in refused {
println!("{refusal}");
}
}§Errors
As Model::check.
Source§impl DynModel<Embedding>
impl DynModel<Embedding>
Sourcepub async fn embed_text(&self, text: &str) -> Result<Embedding, ProviderError>
pub async fn embed_text(&self, text: &str) -> Result<Embedding, ProviderError>
Embed one text, returning the last vector or an error if none is returned.