pub struct Provider { /* private fields */ }Expand description
Cloudflare Workers AI provider implementing anyllm::ChatProvider.
Wraps a worker::Ai binding to call AI models directly from within
a Cloudflare Worker. No HTTP overhead: calls go through the Workers
runtime’s internal AI binding.
§Construction
Obtain the worker::Ai binding from the Worker’s Env:
ⓘ
let ai = env.ai("AI")?;
let provider = Provider::new(ai);The "AI" string must match the binding name in wrangler.toml:
[ai]
binding = "AI"Implementations§
Source§impl Provider
impl Provider
Sourcepub fn with_chat_capabilities(
self,
resolver: impl ChatCapabilityResolver,
) -> Self
pub fn with_chat_capabilities( self, resolver: impl ChatCapabilityResolver, ) -> Self
Install a resolver consulted before the provider’s built-in capability logic.
Trait Implementations§
Source§impl ChatProvider for Provider
impl ChatProvider for Provider
Source§type Stream = Pin<Box<dyn Stream<Item = Result<StreamEvent, Error>> + Send>>
type Stream = Pin<Box<dyn Stream<Item = Result<StreamEvent, Error>> + Send>>
Concrete stream type returned by
chat_streamSource§async fn chat(&self, request: &ChatRequest) -> Result<ChatResponse>
async fn chat(&self, request: &ChatRequest) -> Result<ChatResponse>
Send a chat completion request and return the full response. Read more
Source§async fn chat_stream(&self, request: &ChatRequest) -> Result<ChatStream>
async fn chat_stream(&self, request: &ChatRequest) -> Result<ChatStream>
Send a chat completion request and return a stream of chunks. Read more
Source§fn chat_capability(
&self,
model: &str,
capability: ChatCapability,
) -> CapabilitySupport
fn chat_capability( &self, model: &str, capability: ChatCapability, ) -> CapabilitySupport
Returns support information for a provider/model capability query.
Source§impl EmbeddingProvider for Provider
impl EmbeddingProvider for Provider
Source§async fn embed(&self, request: &EmbeddingRequest) -> Result<EmbeddingResponse>
async fn embed(&self, request: &EmbeddingRequest) -> Result<EmbeddingResponse>
Send an embedding request and return ordered vectors. Read more
Source§fn embedding_capability(
&self,
_model: &str,
capability: EmbeddingCapability,
) -> CapabilitySupport
fn embedding_capability( &self, _model: &str, capability: EmbeddingCapability, ) -> CapabilitySupport
Returns support information for a provider/model embedding capability.
Source§impl ExtractExt for Provider
Available on crate feature extract only.
impl ExtractExt for Provider
Available on crate feature
extract only.Source§impl ProviderIdentity for Provider
impl ProviderIdentity for Provider
Source§fn provider_name(&self) -> &'static str
fn provider_name(&self) -> &'static str
Returns the provider identity name.
Auto Trait Implementations§
impl Freeze for Provider
impl !RefUnwindSafe for Provider
impl Send for Provider
impl Sync for Provider
impl Unpin for Provider
impl UnsafeUnpin for Provider
impl !UnwindSafe for Provider
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