Platforms to show: All Mac Windows Linux Cross-Platform

Back to LanguageModelSessionsMBS class.

LanguageModelSessionsMBS.Constructor(Model as SystemLanguageModelsMBS = nil, Instructions as InstructionsMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Foundation Models MBS Swift Plugin 25.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Start a new session in blank slate state with instructions.

model: The language model to use for this session.
instructions: Instructions that control the model's behavior.

See also:

LanguageModelSessionsMBS.Constructor(Model as SystemLanguageModelsMBS = nil, Instructions as String)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Foundation Models MBS Swift Plugin 25.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Start a new session in blank slate state with string-based instructions.
Example
Var session As New LanguageModelSessionsMBS("You are a chatbot in Xojo.")
Var instructions as string = session.Instructions
MessageBox Instructions

model: The language model to use for this session.
instructions: Instructions that control the model's behavior.

See also:

LanguageModelSessionsMBS.Constructor(Model as SystemLanguageModelsMBS = nil, Transcript as TranscriptMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Foundation Models MBS Swift Plugin 25.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Start a session by rehydrating from a transcript.

model: The language model to use for this session.
transcript: A transcript to resume from.

See also:

LanguageModelSessionsMBS.prewarm(Prompt as PromptMBS = nil)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Foundation Models MBS Swift Plugin 25.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Requests that the system eagerly load the resources required for this session into memory and optionally caches a prefix of your prompt.

This method can be useful in cases where you have a strong signal that the user will interact with session within a few seconds. For example, you might call prewarm when the user begins typing into a text field.

If you know a prefix for the future prompt, passing it to prewarm will allow the system to process the prompt eagerly and reduce latency for the future request.

Important: You should only use prewarm when you have a window of at least 1s before the call to respond.

Note: Calling this method does not guarantee that the system loads your assets immediately, particularly if your app is running in the background or the system is under load.

LanguageModelSessionsMBS.respond(prompt as PromptMBS) as ResponseMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Foundation Models MBS Swift Plugin 25.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Produces a response to a prompt.

prompt: A prompt for the model to respond to.

We wait for the answer and return it.

If temperature >= 0 or maximumResponseTokens >= 0, we pass these as options.

See also:

Some examples using this method:

LanguageModelSessionsMBS.respond(prompt as PromptMBS, theDelegate as ResponseCompletedMBS, tag as Variant = nil)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Foundation Models MBS Swift Plugin 25.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Produces a response to a prompt.

prompt: A prompt for the model to respond to.

We call the delegate later to report result and pass through tag value.

If temperature >= 0 or maximumResponseTokens >= 0, we pass these as options.

See also:

LanguageModelSessionsMBS.respond(prompt as String) as String

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Foundation Models MBS Swift Plugin 25.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Produces a response to a prompt.
Example
Var session As New LanguageModelSessionsMBS("You are a chatbot in Xojo. Be brief.")
var response as string = session.respond("Can Xojo do web apps?")
MessageBox response

' Yes, Xojo can be used To create web apps. Xojo Web Apps Is a framework
' that allows developers To build web applications Using Xojo's native
' programming language. It provides a set Of tools And libraries To handle
' web development tasks, such As server-side scripting,
' HTML/CSS/JavaScript, And database integration.

prompt: A prompt for the model to respond to.

We wait for the answer and return it.

If temperature >= 0 or maximumResponseTokens >= 0, we pass these as options.

See also:

LanguageModelSessionsMBS.respond(prompt as String, theDelegate as ResponseCompletedMBS, tag as Variant = nil)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Foundation Models MBS Swift Plugin 25.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Produces a response to a prompt.

prompt: A prompt for the model to respond to.

We call the delegate later to report result and pass through tag value.

If temperature >= 0 or maximumResponseTokens >= 0, we pass these as options.

See also:

LanguageModelSessionsMBS.tokenCount(prompt as PromptMBS) as Integer   New in 26.2

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Foundation Models MBS Swift Plugin 26.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the token count for the specified instructions.

New for macOS/iOS 26.4 or newer.

See also:

LanguageModelSessionsMBS.tokenCount(prompt as PromptMBS, theDelegate as TokenCountCompletedMBS, tag as Variant = nil)   New in 26.2

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Foundation Models MBS Swift Plugin 26.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Calculates the token count for the specified instructions.

New for macOS/iOS 26.4 or newer.

See also:

LanguageModelSessionsMBS.tokenCount(prompt as String) as Integer   New in 26.2

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Foundation Models MBS Swift Plugin 26.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Calculates the token count for the specified prompt.
Example
Var session As New LanguageModelSessionsMBS("")
Var count As Integer = session.tokenCount("Hello World")

Break // shows 10

New for macOS/iOS 26.4 or newer.

See also:

LanguageModelSessionsMBS.tokenCount(prompt as String, theDelegate as TokenCountCompletedMBS, tag as Variant = nil)   New in 26.2

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Foundation Models MBS Swift Plugin 26.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the token count for the specified instructions.

Calls TokenCountCompletedMBS event later.

New for macOS/iOS 26.4 or newer.

See also:

LanguageModelSessionsMBS.transcript as TranscriptMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Foundation Models MBS Swift Plugin 25.5 ✅ Yes ❌ No ❌ No ✅ Yes All
A full history of interactions, including user inputs and model responses.

Some examples using this method:

The items on this page are in the following plugins: MBS Swift Plugin.


The biggest plugin in space...