pub struct DynModel<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 the bus serves is a
ModelHandle in the agent runtime instead: its calls are dispatched,
recorded and observed by the bus.
use rig_core::embeddings::EmbeddingsBuilder;
use rig_core::vector_store::in_memory_store::InMemoryVectorStore;
use rig_core::{Model, providers::openai::{self, OpenAI}};
let model = OpenAI::from_env()?.with_http(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: Operation> DynModel<Op>
impl<Op: Operation> DynModel<Op>
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 capabilities(&self) -> Capabilities
pub fn capabilities(&self) -> Capabilities
What a runtime accounts for about this model.
Sourcepub fn call(
&self,
request: impl Into<Op::Request>,
) -> impl Future<Output = Result<Op::Response, ProviderError>> + WasmCompatSend + 'static
pub fn call( &self, request: impl Into<Op::Request>, ) -> impl Future<Output = Result<Op::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 call_observed(
&self,
request: impl Into<Op::Request>,
observation: AdapterContext,
) -> impl Future<Output = Result<Op::Response, ProviderError>> + WasmCompatSend + 'static
pub fn call_observed( &self, request: impl Into<Op::Request>, observation: AdapterContext, ) -> impl Future<Output = Result<Op::Response, ProviderError>> + WasmCompatSend + 'static
Self::call, with the attempt observed under observation.
Sourcepub fn stream(
&self,
request: impl Into<Op::Request>,
) -> Result<Streamed<Op>, ProviderError>
pub fn stream( &self, request: impl Into<Op::Request>, ) -> Result<Streamed<Op>, ProviderError>
Open a streamed reply; Model::stream with the model erased.
Sourcepub fn stream_observed(
&self,
request: impl Into<Op::Request>,
observation: AdapterContext,
) -> Result<Streamed<Op>, ProviderError>
pub fn stream_observed( &self, request: impl Into<Op::Request>, observation: AdapterContext, ) -> Result<Streamed<Op>, ProviderError>
Self::stream, with the attempt observed under observation.
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.
Trait Implementations§
Auto Trait Implementations§
impl<Op> !RefUnwindSafe for DynModel<Op>
impl<Op> !UnwindSafe for DynModel<Op>
impl<Op> Freeze for DynModel<Op>
impl<Op> Send for DynModel<Op>
impl<Op> Sync for DynModel<Op>
impl<Op> Unpin for DynModel<Op>
impl<Op> UnsafeUnpin for DynModel<Op>where
Arc<dyn ErasedModel<Op>>: UnsafeUnpin,
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<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