pub struct AiBackend { /* private fields */ }Expand description
A SystemOne decision model run through a Worker’s AI binding.
Holds the binding object (env.AI) and the catalog path of the model to
run. What the binding throws or rejects with is classified like the REST
API’s errors:
- out of capacity (
3040):DecisionError::RateLimited, retried withwith_retry’s policy (defaultRetryConfig::default); - daily free allocation used up (
3036):DecisionError::Http429, not retried — nothing succeeds before the reset; - anything else:
DecisionError::Backendwith the binding’s message, not retried.
A DecisionModel::or fallback applies to all of them.
Implementations§
Source§impl AiBackend
impl AiBackend
Sourcepub fn new(ai: impl Into<JsValue>, model_path: impl Into<String>) -> Self
pub fn new(ai: impl Into<JsValue>, model_path: impl Into<String>) -> Self
Run model_path (e.g. CLEF) through ai, the Worker’s AI
binding: workers-rs’s Ai (env.ai("AI")?) or the raw env.AI
JsValue.
Capabilities: every question type, 255 options, 10 levels, batching, and SystemOne’s 64k/32k token estimates — a state over them fails before the binding is called.
Sourcepub fn with_capabilities(self, capabilities: Capabilities) -> Self
pub fn with_capabilities(self, capabilities: Capabilities) -> Self
Report these capabilities instead.
Sourcepub fn with_retry(self, retry: RetryConfig) -> Self
pub fn with_retry(self, retry: RetryConfig) -> Self
Retry policy for out-of-capacity errors (default
RetryConfig::default: 3 retries, 1 s initial, 2x, 30 s cap).
Sourcepub fn model_path(&self) -> &str
pub fn model_path(&self) -> &str
The catalog path this backend runs.
Trait Implementations§
Source§impl DecisionBackend for AiBackend
impl DecisionBackend for AiBackend
Source§fn capabilities(&self) -> Capabilities
fn capabilities(&self) -> Capabilities
What this backend can answer.
Source§fn evaluate<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 Request,
) -> Pin<Box<dyn Future<Output = Result<Evaluation, DecisionError>> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn evaluate<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 Request,
) -> Pin<Box<dyn Future<Output = Result<Evaluation, DecisionError>> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Evaluate one request.
Auto Trait Implementations§
impl Freeze for AiBackend
impl RefUnwindSafe for AiBackend
impl Send for AiBackend
impl Sync for AiBackend
impl Unpin for AiBackend
impl UnsafeUnpin for AiBackend
impl UnwindSafe for AiBackend
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