use super::answer::Evaluation;
use super::error::DecisionError;
use super::question::{QuestionKind, Request};
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct Capabilities {
pub question_kinds: Vec<QuestionKind>,
pub max_choice_options: usize,
pub max_score_levels: usize,
pub batching: bool,
pub max_concurrent_requests: usize,
pub local: bool,
pub max_request_tokens: Option<usize>,
pub max_state_and_question_tokens: Option<usize>,
}
impl Capabilities {
pub fn new(kinds: &[QuestionKind]) -> Self {
Self {
question_kinds: kinds.to_vec(),
max_choice_options: 255,
max_score_levels: 10,
batching: true,
max_concurrent_requests: 1,
local: false,
max_request_tokens: None,
max_state_and_question_tokens: None,
}
}
pub(crate) fn systemone() -> Self {
Self::new(QuestionKind::all()).with_token_limits(Some(64_000), Some(32_000))
}
pub(crate) fn unlimited() -> Self {
Self::new(QuestionKind::all())
.with_max_choice_options(usize::MAX)
.with_max_score_levels(usize::MAX)
}
pub fn with_max_choice_options(mut self, n: usize) -> Self {
self.max_choice_options = n;
self
}
pub fn with_max_score_levels(mut self, n: usize) -> Self {
self.max_score_levels = n;
self
}
pub fn with_batching(mut self, batching: bool) -> Self {
self.batching = batching;
self
}
pub fn with_max_concurrent_requests(mut self, n: usize) -> Self {
self.max_concurrent_requests = n.max(1);
self
}
pub fn with_local(mut self, local: bool) -> Self {
self.local = local;
self
}
pub fn with_token_limits(
mut self,
request: Option<usize>,
state_and_question: Option<usize>,
) -> Self {
self.max_request_tokens = request;
self.max_state_and_question_tokens = state_and_question;
self
}
pub fn supports(&self, kind: QuestionKind) -> bool {
self.question_kinds.contains(&kind)
}
}
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
pub trait DecisionBackend: crate::rt::MaybeSend + crate::rt::MaybeSync {
fn capabilities(&self) -> Capabilities;
async fn evaluate(&self, request: &Request) -> Result<Evaluation, DecisionError>;
}