#[non_exhaustive]pub struct Prompt {
pub tier: ModelTier,
pub system: Option<String>,
pub messages: Vec<Turn>,
pub json_schema: Option<Value>,
pub max_tokens: u32,
pub tools: Vec<ToolSpec>,
pub tool_choice: Option<ToolChoice>,
}Expand description
One completion request: the tier asked for, the conversation so far, and what the caller will accept back.
#[non_exhaustive]: build one with Prompt::new and the builder
methods rather than a struct literal. What a v2 port has to carry —
tools, temperature, a stop sequence — should not be a breaking change
for every caller, the same way Message is built.
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.tier: ModelTier§system: Option<String>§messages: Vec<Turn>§json_schema: Option<Value>A JSON Schema (draft 2020-12) the answer should conform to. When set,
the adapter asks its provider for structured output; a provider that
honours it fills Completion::json, and one that cannot leaves the
raw answer in Completion::text with json None, rather than
failing the call.
max_tokens: u32§tools: Vec<ToolSpec>The tools the model may call. Empty by default: a prompt that sends no tools behaves exactly as it did before tools existed, and an adapter is never asked to carry tools it was not given.
tool_choice: Option<ToolChoice>How the model should choose among Prompt::tools. None leaves
the choice to the provider’s own default; the builder sets it.
Implementations§
Source§impl Prompt
impl Prompt
Sourcepub fn new(tier: ModelTier) -> Self
pub fn new(tier: ModelTier) -> Self
An empty prompt for tier: no system prompt, no messages, no
schema, no tools, and DEFAULT_MAX_TOKENS as the ceiling.
Everything else is a builder method.
Sourcepub fn tools(self, tools: impl IntoIterator<Item = ToolSpec>) -> Self
pub fn tools(self, tools: impl IntoIterator<Item = ToolSpec>) -> Self
Offers the model every tool in tools.
Sourcepub fn tool_choice(self, tool_choice: ToolChoice) -> Self
pub fn tool_choice(self, tool_choice: ToolChoice) -> Self
Steers how the model chooses among the offered tools.
Sourcepub fn system(self, system: impl Into<String>) -> Self
pub fn system(self, system: impl Into<String>) -> Self
The standing instruction the model answers under.
Sourcepub fn user(self, content: impl Into<String>) -> Self
pub fn user(self, content: impl Into<String>) -> Self
Appends a Turn::user — the common case, a one-message prompt.
Sourcepub fn user_parts(self, parts: impl IntoIterator<Item = Part>) -> Self
pub fn user_parts(self, parts: impl IntoIterator<Item = Part>) -> Self
Appends a Turn::user_parts — a user message carrying text and
images in order (issue #628).
Sourcepub fn assistant(self, content: impl Into<String>) -> Self
pub fn assistant(self, content: impl Into<String>) -> Self
Appends a Turn::assistant.
Sourcepub fn turn(self, turn: Turn) -> Self
pub fn turn(self, turn: Turn) -> Self
Appends a whole turn, for a conversation built elsewhere.
Sourcepub fn json_schema(self, schema: Value) -> Self
pub fn json_schema(self, schema: Value) -> Self
Asks for structured output conforming to schema; a successful
completion then carries the parsed value in Completion::json.
Sourcepub fn max_tokens(self, max_tokens: u32) -> Self
pub fn max_tokens(self, max_tokens: u32) -> Self
The token ceiling for the answer.
Sourcepub fn has_images(&self) -> bool
pub fn has_images(&self) -> bool
Whether any turn carries an image Part (issue #628). The router
and the tool loop gate Capability::Images on this, exactly as
they gate Capability::Tools on Prompt::tools.
Sourcepub fn check_images(&self) -> Result<(), TextModelError>
pub fn check_images(&self) -> Result<(), TextModelError>
Refuses a prompt whose images exceed a bound (issue #628), without
encoding anything: the count against MAX_PROMPT_IMAGES, each
image’s encoded_image_len against MAX_IMAGE_ENCODED_BYTES,
and their sum against MAX_PROMPT_IMAGE_ENCODED_BYTES.
§Errors
TextModelError::ImageLimit, naming which bound was crossed:
ImageLimit::TooMany, ImageLimit::ImageTooLarge (with the
0-based index among the prompt’s images) or
ImageLimit::TotalTooLarge.