pub struct Choice {
pub instructions: Option<Value>,
pub criteria: Map<String, Value>,
}Expand description
A question that selects one option from choices the caller defines.
Options serialize in the order supplied, each mapped to a description that
is a string, object, array — or null for an option interpreted by its
name alone.
let tone = Choice::new("What is the tone of this message?")
.option("calm", "A neutral or polite message")
.option("angry", "An upset or hostile message");Fields§
§instructions: Option<Value>What the model should decide when choosing an option.
criteria: Map<String, Value>Options in the order the caller supplied them, mapped to descriptions
(a JSON null description means “interpret the name alone”).
Implementations§
Source§impl Choice
impl Choice
Sourcepub fn new(instructions: impl Into<Value>) -> Self
pub fn new(instructions: impl Into<Value>) -> Self
Creates a choice question with instructions and no options yet.
Sourcepub fn without_instructions() -> Self
pub fn without_instructions() -> Self
Creates a choice question with no instructions.
Sourcepub fn from_options<I, S>(instructions: impl Into<Value>, options: I) -> Self
pub fn from_options<I, S>(instructions: impl Into<Value>, options: I) -> Self
Creates a choice question whose options all have null descriptions.
Options serialize in iteration order of options.
Sourcepub fn from_pairs<I, S>(instructions: impl Into<Value>, pairs: I) -> Self
pub fn from_pairs<I, S>(instructions: impl Into<Value>, pairs: I) -> Self
Creates a choice question from an ordered list of (option, description) pairs.
Each description may be any JSON value; use Value::Null for an
undescribed option.
Sourcepub fn instructions(self, instructions: impl Into<Value>) -> Self
pub fn instructions(self, instructions: impl Into<Value>) -> Self
Replaces the instructions.
Sourcepub fn option(
self,
option: impl Into<String>,
description: impl Into<Value>,
) -> Self
pub fn option( self, option: impl Into<String>, description: impl Into<Value>, ) -> Self
Appends an option with a description.
The description may be a string, object, or array; pass
Value::Null for an undescribed option.
Sourcepub fn bare_option(self, option: impl Into<String>) -> Self
pub fn bare_option(self, option: impl Into<String>) -> Self
Appends an option whose description is null (interpreted by name alone).