Skip to main content

LanguageModelSessionBuilder

Struct LanguageModelSessionBuilder 

Source
pub struct LanguageModelSessionBuilder { /* private fields */ }
Expand description

Builder for LanguageModelSession.

Implementations§

Source§

impl LanguageModelSessionBuilder

Source

pub fn new() -> Self

Creates an empty session builder.

Source

pub fn instructions(self, instructions: impl Into<InstructionsText>) -> Self

Sets persistent system instructions for the session.

Source

pub fn preamble(self, instructions: impl Into<InstructionsText>) -> Self

Alias for LanguageModelSessionBuilder::instructions using Rig terminology.

Source

pub fn tool(self, tool: ToolDefinition) -> Self

Adds one callable tool.

Source

pub fn tools(self, tools: impl IntoIterator<Item = ToolDefinition>) -> Self

Adds multiple callable tools.

Source

pub fn temperature(self, temperature: Temperature) -> Self

Sets the typed default temperature used by LanguageModelSession::respond_to and LanguageModelSession::stream_response.

Source

pub fn with_temperature(self, temperature: Temperature) -> Self

Source

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.

Source

pub fn max_tokens(self, max_tokens: MaxTokens) -> Self

Sets the default maximum response tokens.

Source

pub fn with_max_tokens(self, max_tokens: MaxTokens) -> Self

Source

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.

Source

pub fn options(self, options: GenerationOptions) -> Self

Replaces all default generation options.

Source

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.

Trait Implementations§

Source§

impl Debug for LanguageModelSessionBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LanguageModelSessionBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WasmCompatSend for T
where T: Send,

Source§

impl<T> WasmCompatSync for T
where T: Sync,