Skip to content

Commit 637ba66

Browse files
authored
Merge pull request #121 from rudrankriyam/26.4-beta-3
Update documentation for Xcode 26.4 beta 3
2 parents 8aed294 + 5e70251 commit 637ba66

File tree

1 file changed

+151
-39
lines changed

1 file changed

+151
-39
lines changed

fmf.md

Lines changed: 151 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,33 @@ extension ConvertibleToGeneratedContent {
8989
@available(watchOS, unavailable)
9090
public struct DynamicGenerationSchema : Sendable {
9191

92+
/// Creates a null schema.
93+
///
94+
/// You can use null schemas as a way to express types that
95+
/// cannot be absent, but may have an empty value.
96+
///
97+
/// let person = DynamicGenerationSchema(
98+
/// name: "Person",
99+
/// properties: []
100+
/// DynamicGenerationSchema.Property(
101+
/// name: "fullName",
102+
/// schema: DynamicGenerationSchema(type: String.self)
103+
/// )
104+
/// ]
105+
/// )
106+
///
107+
/// let nullablePerson = DynamicGenerationSchema(
108+
/// name: "NullablePerson",
109+
/// anyOf: [person, .null]
110+
/// )
111+
///
112+
/// let schema = try GenerationSchema(root: nullablePerson, dependencies: [])
113+
///
114+
@available(iOS 26.4, macOS 26.4, *)
115+
@available(tvOS, unavailable)
116+
@available(watchOS, unavailable)
117+
public static var null: DynamicGenerationSchema { get }
118+
92119
/// Creates an object schema.
93120
///
94121
/// - Parameters:
@@ -97,6 +124,18 @@ public struct DynamicGenerationSchema : Sendable {
97124
/// - properties: The properties to associated with this schema.
98125
public init(name: String, description: String? = nil, properties: [DynamicGenerationSchema.Property])
99126

127+
/// Creates an object schema.
128+
///
129+
/// - Parameters:
130+
/// - name: A name this dynamic schema can be referenced by.
131+
/// - description: A natural language description of this schema.
132+
/// - representNilExplicitlyInGeneratedContent: Controls how the model will represent nil.
133+
/// - properties: The properties to associated with this schema.
134+
@available(iOS 26.4, macOS 26.4, *)
135+
@available(tvOS, unavailable)
136+
@available(watchOS, unavailable)
137+
public init(name: String, description: String? = nil, representNilExplicitlyInGeneratedContent explicitNil: Bool, properties: [DynamicGenerationSchema.Property])
138+
100139
/// Creates an any-of schema.
101140
///
102141
/// - Parameters:
@@ -233,12 +272,60 @@ extension Generable {
233272
/// case nonFiction
234273
/// }
235274
/// ```
236-
/// - SeeAlso: @Generable macro ``Generable(description:representNullExplicitlyInGeneratedContent:)``
275+
/// - SeeAlso: @Generable macro ``Generable(description:representNilExplicitlyInGeneratedContent:)``
237276
@available(iOS 26.0, macOS 26.0, *)
238277
@available(tvOS, unavailable)
239278
@available(watchOS, unavailable)
240279
@attached(extension, conformances: Generable, names: named(init(_:)), named(generatedContent)) @attached(member, names: arbitrary) public macro Generable(description: String? = nil) = #externalMacro(module: "FoundationModelsMacros", type: "GenerableMacro")
241280

281+
/// Conforms a type to ``Generable`` protocol.
282+
///
283+
/// You can apply this macro to structures and enumerations.
284+
///
285+
/// ```swift
286+
/// @Generable(representNilExplicitlyInGeneratedContent: true)
287+
/// struct Character {
288+
/// @Guide(description: "A short title")
289+
/// let title: String
290+
///
291+
/// @Guide(description: "An optional short subtitle for the novel")
292+
/// let subtitle: String?
293+
///
294+
/// @Guide(description: "The genre of the novel")
295+
/// let genre: Genre
296+
/// }
297+
///
298+
/// @Generable
299+
/// enum Genre {
300+
/// case fiction
301+
/// case nonFiction
302+
/// }
303+
/// ```
304+
///
305+
/// The `representNilExplicitlyInGeneratedContent` argument controls how the
306+
/// model represents nil properties. When `false`, the model will omit nil
307+
/// properties from the generated content, so no property will be present. When
308+
/// `true`, the model will produce a property, but its value will be
309+
/// ``GeneratedContent/Kind/null``.
310+
///
311+
/// ```swift
312+
/// // representNilExplicitlyInGeneratedContent: false
313+
/// let content = GeneratedContent(properties: [:])
314+
///
315+
/// // representNilExplicitlyInGeneratedContent: true
316+
/// let content = GeneratedContent(properties: ["foo": nil])
317+
/// ```
318+
///
319+
/// Controlling this behavior can be important when interfacing with external
320+
/// systems, using custom adapters, or working with one-shot examples that
321+
/// contain explicitly encoded nils.
322+
///
323+
/// - SeeAlso: @Generable macro ``Generable(description:)``
324+
@available(iOS 26.4, macOS 26.4, *)
325+
@available(tvOS, unavailable)
326+
@available(watchOS, unavailable)
327+
@attached(extension, conformances: Generable, names: named(init(_:)), named(generatedContent)) @attached(member, names: arbitrary) public macro Generable(description: String? = nil, representNilExplicitlyInGeneratedContent: Bool) = #externalMacro(module: "FoundationModelsMacros", type: "GenerableMacro")
328+
242329
/// A type that represents structured, generated content.
243330
///
244331
/// Generated content may contain a single value, an array, or key-value pairs with unique keys.
@@ -1149,6 +1236,18 @@ public struct GenerationSchema : Sendable, Codable, CustomDebugStringConvertible
11491236
/// - properties: An array of properties.
11501237
public init(type: any Generable.Type, description: String? = nil, properties: [GenerationSchema.Property])
11511238

1239+
/// Creates a schema by providing an array of properties.
1240+
///
1241+
/// - Parameters:
1242+
/// - type: The type this schema represents.
1243+
/// - description: A natural language description of this schema.
1244+
/// - representNilExplicitlyInGeneratedContent: Controls how the model will represent nil.
1245+
/// - properties: An array of properties.
1246+
@available(iOS 26.4, macOS 26.4, *)
1247+
@available(tvOS, unavailable)
1248+
@available(watchOS, unavailable)
1249+
public init(type: any Generable.Type, description: String? = nil, representNilExplicitlyInGeneratedContent explicitNil: Bool, properties: [GenerationSchema.Property])
1250+
11521251
/// Creates a schema for a string enumeration.
11531252
///
11541253
/// - Parameters:
@@ -1689,7 +1788,7 @@ extension LanguageModelSession {
16891788
/// prompt eagerly and reduce latency for the future request.
16901789
///
16911790
/// - Important: You should only use prewarm when you have a window of at least 1 second before
1692-
/// the call to a respond method, like ``respond(to:options:)`` or ``streamResponse(to:options:)``.
1791+
/// the call to a respond method, like ``respond(to:options:)-(Prompt,_)`` or ``streamResponse(to:options:)-(Prompt,_)``.
16931792
///
16941793
/// Calling this method does not guarantee that the system loads your assets immediately, particularly if
16951794
/// your app is running in the background or the system is under load.
@@ -2433,9 +2532,15 @@ public protocol PromptRepresentable {
24332532
/// The `SystemLanguageModel` refers to the on-device text foundation model that powers Apple
24342533
/// Intelligence. Use ``default`` to access the base version of the model and perform general-purpose
24352534
/// text generation tasks. To access a specialized version of the model, initialize the model
2436-
/// with ``UseCase`` to perform tasks like ``UseCase/contentTagging``.
2535+
/// with ``UseCase`` to perform tasks like ``UseCase/contentTagging``. Apple will periodically
2536+
/// update `SystemLanguageModel` in routine OS updates to improve the on-device model's abilities and
2537+
/// performance. Currently there are 2 model versions that align with:
2538+
/// - iOS, iPadOS, macOS, and visionOS **26.0 - 26.3**
2539+
/// - iOS, iPadOS, macOS, visionOS **26.4**
24372540
///
2438-
/// Verify the model availability before you use the model. Model availability depends on device factors like:
2541+
/// To better understand the impact of model version on your app, see the guide <doc:updating-prompts-for-new-model-versions>.
2542+
///
2543+
/// Before you use the model, you'll need to verify its availability. Model availability depends on device factors like:
24392544
///
24402545
/// * The device must support Apple Intelligence.
24412546
/// * Apple Intelligence must be turned on in Settings.
@@ -2526,21 +2631,27 @@ extension SystemLanguageModel {
25262631
@available(watchOS, unavailable)
25272632
public struct Guardrails : Sendable {
25282633

2529-
/// Default guardrails. This mode ensures that unsafe content in prompts and responses will be
2530-
/// blocked with a `LanguageModelSession.GenerationError.guardrailViolation`
2634+
/// Guardrails that block unsafe content in prompts and responses.
2635+
///
2636+
/// The `default` guardrail level means that all guardrails are turned on. When
2637+
/// the guardrails block unsafe content from either the prompt input or model response,
2638+
/// the framework will throw a
2639+
/// ``LanguageModelSession/GenerationError/guardrailViolation(_:)``
25312640
/// error.
25322641
public static let `default`: SystemLanguageModel.Guardrails
25332642

2534-
/// Guardrails that allow for permissively transforming text input, including
2535-
/// potentially unsafe content, to text responses, such as summarizing an article.
2643+
/// Guardrails that allow for permissively transforming text input.
25362644
///
2537-
/// In this mode, requests you make to the model that generate a `String` will not throw
2538-
/// `LanguageModelSession.GenerationError.guardrailViolation` errors.
2539-
/// However, when the purpose of your instructions and prompts is not transforming user input,
2540-
/// the model may still refuse to respond to potentially unsafe prompts by generating an
2541-
/// explanation.
2645+
/// The `permissiveContentTransform` guardrail mode is designed to let the model handle
2646+
/// potentially unsafe content, such as summarizing a news article. In this mode, requests you make to
2647+
/// the model that generate a `String` will not throw
2648+
/// ``LanguageModelSession/GenerationError/guardrailViolation(_:)`` errors.
2649+
/// However, the model may still sometimes refuse to respond to a sensitive prompt, in which case
2650+
/// it will generate a `String` refusal message.
25422651
///
2543-
/// When you generate responses other than `String`, this mode behaves the same way as `.default`.
2652+
/// When you generate responses other than `String`, this mode behaves the same way
2653+
/// as ``SystemLanguageModel/Guardrails/default`` mode and _will_ throw
2654+
/// ``LanguageModelSession/GenerationError/guardrailViolation(_:)`` errors.
25442655
public static let permissiveContentTransformations: SystemLanguageModel.Guardrails
25452656
}
25462657
}
@@ -2668,50 +2779,50 @@ extension SystemLanguageModel {
26682779
@available(watchOS, unavailable)
26692780
extension SystemLanguageModel {
26702781

2671-
/// Token usage information for a prompt or transcript.
2782+
/// Returns the token count for the specified prompt.
26722783
///
2673-
/// Provides the total number of tokens used.
2784+
/// - Parameter prompt: The prompt to calculate the token count for.
2785+
/// - Returns: The token count for the prompt.
26742786
@available(iOS 26.4, macOS 26.4, *)
26752787
@available(tvOS, unavailable)
26762788
@available(watchOS, unavailable)
2677-
public struct TokenUsage {
2789+
nonisolated(nonsending) final public func tokenCount(for prompt: some PromptRepresentable) async throws -> Int
26782790

2679-
/// The total token count.
2680-
public var tokenCount: Int
2681-
}
2682-
2683-
/// Returns token usage information for the specified instructions and tools.
2791+
/// Returns the token count for the specified instructions.
26842792
///
2685-
/// This method calculates the token count for a set of instructions and
2686-
/// tool definitions. The token count includes both the instructions and the
2687-
/// tool hints that would be included in the model's context.
2793+
/// - Parameter instructions: The instructions to calculate the token count for.
2794+
/// - Returns: The token count for the instructions.
2795+
@available(iOS 26.4, macOS 26.4, *)
2796+
@available(tvOS, unavailable)
2797+
@available(watchOS, unavailable)
2798+
nonisolated(nonsending) final public func tokenCount(for instructions: Instructions) async throws -> Int
2799+
2800+
/// Returns the token count for the specified tools.
26882801
///
2689-
/// - Parameters:
2690-
/// - instructions: Instructions to calculate token usage for.
2691-
/// - tools: An array of tools that will be available to the model. Defaults to an empty array if not specified.
2692-
/// - Returns: A summary of token usage for the instructions and tools.
2802+
/// - Parameter tools: An array of tools to calculate the token count for.
2803+
/// - Returns: The token count for the tools.
26932804
@available(iOS 26.4, macOS 26.4, *)
26942805
@available(tvOS, unavailable)
26952806
@available(watchOS, unavailable)
2696-
nonisolated(nonsending) final public func tokenUsage(for instructions: Instructions, tools: [any Tool] = []) async throws -> SystemLanguageModel.TokenUsage
2807+
nonisolated(nonsending) final public func tokenCount(for tools: [any Tool]) async throws -> Int
26972808

2698-
/// Returns token usage information for the specified prompt.
2809+
/// Returns the token count for the specified schema.
26992810
///
2700-
/// - Parameter prompt: A prompt to calculate token usage for.
2701-
/// - Returns: A summary of token usage for the prompt.
2811+
/// - Parameter schema: The schema to calculate the token count for.
2812+
/// - Returns: The token count for the schema.
27022813
@available(iOS 26.4, macOS 26.4, *)
27032814
@available(tvOS, unavailable)
27042815
@available(watchOS, unavailable)
2705-
nonisolated(nonsending) final public func tokenUsage(for prompt: some PromptRepresentable) async throws -> SystemLanguageModel.TokenUsage
2816+
nonisolated(nonsending) final public func tokenCount(for schema: GenerationSchema) async throws -> Int
27062817

2707-
/// Returns token usage information for the specified collection of transcript entries.
2818+
/// Returns the token count for the specified collection of transcript entries.
27082819
///
2709-
/// - Parameter transcriptEntries: A collection of transcript entries to calculate token usage for.
2710-
/// - Returns: A summary of token usage for the transcript.
2820+
/// - Parameter transcriptEntries: A collection of transcript entries to calculate the token count for.
2821+
/// - Returns: The token count for the transcript.
27112822
@available(iOS 26.4, macOS 26.4, *)
27122823
@available(tvOS, unavailable)
27132824
@available(watchOS, unavailable)
2714-
nonisolated(nonsending) final public func tokenUsage(for transcriptEntries: some Collection<Transcript.Entry>) async throws -> SystemLanguageModel.TokenUsage
2825+
nonisolated(nonsending) final public func tokenCount(for transcriptEntries: some Collection<Transcript.Entry>) async throws -> Int
27152826
}
27162827

27172828
@available(iOS 26.0, macOS 26.0, *)
@@ -2730,7 +2841,7 @@ extension SystemLanguageModel {
27302841
@backDeployed(before: iOS 26.4, macOS 26.4, visionOS 26.4)
27312842
@available(tvOS, unavailable)
27322843
@available(watchOS, unavailable)
2733-
final public var contextSize: Int { get async throws }
2844+
final public var contextSize: Int { get }
27342845
}
27352846

27362847
@available(iOS 26.0, macOS 26.0, *)
@@ -4556,3 +4667,4 @@ extension Array : PromptRepresentable where Element : PromptRepresentable {
45564667
/// An instance that represents a prompt.
45574668
public var promptRepresentation: Prompt { get }
45584669
}
4670+

0 commit comments

Comments
 (0)