#[non_exhaustive]pub struct DecisionRequest {
pub model: String,
pub input: DecisionInput,
pub images: Vec<Image>,
pub questions: Vec<(String, Question)>,
pub options: RequestOptions,
}Expand description
Named questions about one input, answered by a decision model.
Every field is semantic: a provider either sends it as given or fails.
There are no hints to degrade, so unlike chat and embedding requests a
decision request carries no UnsupportedPolicy.
use allama::DecisionRequest;
use allama::decision::Question;
let request = DecisionRequest::new("nimble", "I was charged twice. Please refund me.")
.question(
"label",
Question::choice("Which label fits this ticket?")
.option("billing", "Payments and refunds")
.option("bug", "Software errors"),
)
.question("refund", Question::yes_no("Is the customer requesting a refund?"));
assert_eq!(request.questions.len(), 2);Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.model: StringModel identifier.
input: DecisionInputWhat the questions are about.
images: Vec<Image>Images the model reads together with the input, in order, for
models that report
DecisionCapability::ImageInput.
Every question is about the input and the images alike.
Image::detail is a hint no decision API honors: adapters warn
about it.
questions: Vec<(String, Question)>Questions by unique name, in order.
options: RequestOptionsProvider-specific options.
Implementations§
Source§impl DecisionRequest
impl DecisionRequest
Sourcepub fn new(model: impl Into<String>, input: impl Into<DecisionInput>) -> Self
pub fn new(model: impl Into<String>, input: impl Into<DecisionInput>) -> Self
A request for model about input, with no questions yet.
Sourcepub fn image(self, image: impl Into<Image>) -> Self
pub fn image(self, image: impl Into<Image>) -> Self
Append an image the model reads together with the input.
use allama::{DecisionRequest, Image};
use allama::decision::Question;
let request = DecisionRequest::new("@cf/cloudflare/clef", "A product photo from a listing.")
.image(Image::bytes("image/png", png_bytes))
.question("damaged", Question::yes_no("Does the product look damaged?"));
assert_eq!(request.images.len(), 1);Sourcepub fn question(
self,
name: impl Into<String>,
question: impl Into<Question>,
) -> Self
pub fn question( self, name: impl Into<String>, question: impl Into<Question>, ) -> Self
Append a question named name. Names must be unique.
Sourcepub fn find_question(&self, name: &str) -> Option<&Question>
pub fn find_question(&self, name: &str) -> Option<&Question>
The question named name, if any.
Sourcepub fn validate(&self, limits: &DecisionLimits) -> Result<()>
pub fn validate(&self, limits: &DecisionLimits) -> Result<()>
Check the request’s structure and limits before sending it.
Providers call this through
validate_decision_request
before any I/O.
§Errors
Returns Error::InvalidRequest when:
- the model, input, a question name, instructions, an option key, a level label, or a description is blank;
- question names, option keys, or level labels repeat within their scope;
- a choice has fewer than two options or a score fewer than two levels;
- the request exceeds
limits, its images included.
Sourcepub fn with_option<T: ProviderOptions + Serialize>(self, value: T) -> Self
pub fn with_option<T: ProviderOptions + Serialize>(self, value: T) -> Self
Attach provider options of the exact type.
Sourcepub fn with_opaque_option<T: Clone + Send + Sync + 'static>(
self,
value: T,
) -> Self
pub fn with_opaque_option<T: Clone + Send + Sync + 'static>( self, value: T, ) -> Self
Attach an application value that is not a provider option: data a
wrapper of yours reads back with option, such as a
tenant id or a conversation id. Replaces any earlier value of that
type.
The value needs no namespace and no serde: adapters never send it,
and it is left out of the request’s serialized form and its
equality (an opaque option, RequestOptions::insert_opaque).
Sourcepub fn with_options_json(
self,
namespace: impl Into<String>,
value: Value,
) -> Self
pub fn with_options_json( self, namespace: impl Into<String>, value: Value, ) -> Self
Attach provider options in their namespaced JSON form.
Sourcepub fn resolve_option<T>(&self) -> Result<T>
pub fn resolve_option<T>(&self) -> Result<T>
Resolve provider options of type T, falling back to the default.
§Errors
Sourcepub fn option_mut<T: Clone + Send + Sync + 'static>(&mut self) -> Option<&mut T>
pub fn option_mut<T: Clone + Send + Sync + 'static>(&mut self) -> Option<&mut T>
Mutably borrow provider options of the exact type, when attached.
Like option, the JSON form is not consulted; to
change the options whichever form they were given in, use
resolve_option_mut.
Sourcepub fn resolve_option_mut<T>(&mut self) -> Result<&mut T>
pub fn resolve_option_mut<T>(&mut self) -> Result<&mut T>
Resolve provider options of type T for changing in place: the
typed value, else the JSON form, else T::default(), stored as the
typed value. Use it to add to the caller’s options without
replacing them, as with_option would.