pub struct LanguageModelSessionBuilder { /* private fields */ }Expand description
Builder for LanguageModelSession.
Implementations§
Source§impl LanguageModelSessionBuilder
impl LanguageModelSessionBuilder
Sourcepub fn instructions(self, instructions: impl Into<InstructionsText>) -> Self
pub fn instructions(self, instructions: impl Into<InstructionsText>) -> Self
Sets persistent system instructions for the session.
Sourcepub fn preamble(self, instructions: impl Into<InstructionsText>) -> Self
pub fn preamble(self, instructions: impl Into<InstructionsText>) -> Self
Alias for LanguageModelSessionBuilder::instructions using Rig terminology.
Sourcepub fn tool(self, tool: ToolDefinition) -> Self
pub fn tool(self, tool: ToolDefinition) -> Self
Adds one callable tool.
Sourcepub fn tools(self, tools: impl IntoIterator<Item = ToolDefinition>) -> Self
pub fn tools(self, tools: impl IntoIterator<Item = ToolDefinition>) -> Self
Adds multiple callable tools.
Sourcepub fn temperature(self, temperature: Temperature) -> Self
pub fn temperature(self, temperature: Temperature) -> Self
Sets the typed default temperature used by LanguageModelSession::respond_to and LanguageModelSession::stream_response.
Sourcepub fn with_temperature(self, temperature: Temperature) -> Self
pub fn with_temperature(self, temperature: Temperature) -> Self
Alias for LanguageModelSessionBuilder::temperature.
Sourcepub fn try_temperature(self, temperature: f64) -> Result<Self, Error>
pub fn try_temperature(self, temperature: f64) -> Result<Self, Error>
Parses and sets the default temperature from a raw boundary value.
§Errors
Returns Error::InvalidTemperature when temperature is outside
Apple Intelligence’s supported range.
Sourcepub fn max_tokens(self, max_tokens: MaxTokens) -> Self
pub fn max_tokens(self, max_tokens: MaxTokens) -> Self
Sets the default maximum response tokens.
Sourcepub fn with_max_tokens(self, max_tokens: MaxTokens) -> Self
pub fn with_max_tokens(self, max_tokens: MaxTokens) -> Self
Alias for LanguageModelSessionBuilder::max_tokens.
Sourcepub fn try_max_tokens(self, max_tokens: usize) -> Result<Self, Error>
pub fn try_max_tokens(self, max_tokens: usize) -> Result<Self, Error>
Parses and sets the default maximum response token count from a raw boundary value.
§Errors
Returns Error::InvalidMaxTokens when max_tokens cannot be represented
by the Swift bridge.
Sourcepub fn options(self, options: GenerationOptions) -> Self
pub fn options(self, options: GenerationOptions) -> Self
Replaces all default generation options.
Sourcepub fn build(self) -> Result<LanguageModelSession, Error>
pub fn build(self) -> Result<LanguageModelSession, Error>
Builds a stateful model session.
§Examples
use aimx::{AppleIntelligenceModels, Temperature};
let session = AppleIntelligenceModels::default()
.session()
.instructions("Answer in short paragraphs.")
.temperature(Temperature::new(0.2)?)
.build()?;§Errors
Returns Error::NullByte for invalid instructions,
Error::InvalidTemperature or Error::InvalidMaxTokens for invalid
defaults, Error::Json if tool metadata cannot be serialized, or
Error::Unavailable when Apple Intelligence is not ready.