Struct ProviderDispatch
pub struct ProviderDispatch { /* private fields */ }Expand description
Wraps a model provider so every call opens the correct
attribution_span! automatically. See the module docs for the
rationale and the CI gate that enforces routing through this type.
Implementations§
Source§impl ProviderDispatch
impl ProviderDispatch
Sourcepub fn new(inner: Arc<dyn ModelProvider>) -> Self
pub fn new(inner: Arc<dyn ModelProvider>) -> Self
Wrap an Arc<dyn ModelProvider> so its method calls open
attribution_span!(&*inner) automatically.
Sourcepub fn from_ref(inner: &dyn ModelProvider) -> ProviderDispatchRef<'_>
pub fn from_ref(inner: &dyn ModelProvider) -> ProviderDispatchRef<'_>
Wrap a borrowed &dyn ModelProvider. Returns a
ProviderDispatchRef for ergonomic chaining at call sites
that don’t hold an Arc.
Sourcepub async fn chat(
&self,
request: ChatRequest<'_>,
model: &str,
temperature: Option<f64>,
) -> Result<ChatResponse>
pub async fn chat( &self, request: ChatRequest<'_>, model: &str, temperature: Option<f64>, ) -> Result<ChatResponse>
Open attribution_span!(&*self.inner) + scope!(model: model)
around the inner provider’s chat call.
pub fn stream_chat( &self, request: ChatRequest<'_>, model: &str, temperature: Option<f64>, options: StreamOptions, ) -> BoxStream<'static, StreamResult<StreamEvent>>
pub async fn simple_chat( &self, message: &str, model: &str, temperature: Option<f64>, ) -> Result<String>
Sourcepub async fn chat_with_system(
&self,
system_prompt: Option<&str>,
message: &str,
model: &str,
temperature: Option<f64>,
) -> Result<String>
pub async fn chat_with_system( &self, system_prompt: Option<&str>, message: &str, model: &str, temperature: Option<f64>, ) -> Result<String>
Wrap the inner provider’s chat_with_system.
Sourcepub async fn chat_with_history(
&self,
messages: &[ChatMessage],
model: &str,
temperature: Option<f64>,
) -> Result<String>
pub async fn chat_with_history( &self, messages: &[ChatMessage], model: &str, temperature: Option<f64>, ) -> Result<String>
Wrap the inner provider’s chat_with_history.
Sourcepub async fn chat_with_tools(
&self,
messages: &[ChatMessage],
tools: &[Value],
model: &str,
temperature: Option<f64>,
) -> Result<ChatResponse>
pub async fn chat_with_tools( &self, messages: &[ChatMessage], tools: &[Value], model: &str, temperature: Option<f64>, ) -> Result<ChatResponse>
Wrap the inner provider’s chat_with_tools.
pub async fn list_models(&self) -> Result<Vec<String>>
Sourcepub async fn list_models_with_pricing(&self) -> Result<Vec<ModelInfo>>
pub async fn list_models_with_pricing(&self) -> Result<Vec<ModelInfo>>
Wrap the inner provider’s list_models_with_pricing. Same
&*self.inner rationale as list_models.
Auto Trait Implementations§
impl Freeze for ProviderDispatch
impl !RefUnwindSafe for ProviderDispatch
impl Send for ProviderDispatch
impl Sync for ProviderDispatch
impl Unpin for ProviderDispatch
impl UnsafeUnpin for ProviderDispatch
impl !UnwindSafe for ProviderDispatch
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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