Introducing Guided Generation

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Introducing Guided Generation

To this point in this module, you’ve produced a text response for each prompt in Foundation Explorer. Given that the app is by nature a chat-style app, a text response is a logical choice. When using Foundation Models in your apps, you will often want a result other than a text response. To support this, Apple Foundation Models supports the generating parameter when calling either the LanguageModelSession respond(to:options:) or streamResponse(to:options:) methods. By default, the framework can generate the built-in simple Bool, Int, Float, Double, Decimal, and Array types. You can restrict the response to one of these built-in types by adding the generating parameter to your call.

Menu Options
Dije Ogziuxg

How many millimeters are in an inch?
Millimeters in an inch.
Tefjibitoyq oc ab eczv.

let prompt = "How many millimeters are in an inch?"
let response = try await session.respond(to: prompt, generating: Float.self)
let mmInInch = response.content
See forum comments
Download course materials from Github
Previous: Introduction Next: Generating Custom Data Structures