What's New / Apple Intelligence, ML & Evaluation

What's new in _Vision_FoundationModels

+8 NewiOS · macOS · watchOS

_Vision_FoundationModels is a Swift cross-import overlay, not a standalone framework. Its API appears only when a target imports both Vision and FoundationModels. It exposes Vision image tasks, such as barcode reading and OCR, as tool types a foundation model can call.

The 27 SDK adds 8 APIs and deprecates or removes none. The additions are two tool types, BarcodeReaderTool and OCRTool, each with nested Arguments, Output, and Arguments.PartiallyGenerated.ID types. The PartiallyGenerated nesting means these tools support partial argument generation during streaming.

New

8
struct

BarcodeReaderTool

NewiOSmacOSwatchOS
public struct BarcodeReaderTool : Tool, @unchecked Sendable

A tool that scans machine-readable codes in an image.

When the model encounters an image containing machine-readable codes, it can call this tool to decode them. The tool returns an array of Barcode results, each containing the decoded content and the symbology type.

To enable this tool, configure your LanguageModelSession with an instance of BarcodeReaderTool.

let barcodeTool = BarcodeReaderTool()
let session = LanguageModelSession(tools: [barcodeTool])

You can override the default name and description to customize how the model identifies and uses the tool.

let customTool = BarcodeReaderTool(
    name: "scanQRCode",
    description: "Scan QR codes"
)
Declaration
public struct BarcodeReaderTool : Tool, @unchecked Sendable {

    /// A unique name for the tool, such as "get_weather", "toggleDarkMode", or "search contacts".
    public let name: String

    /// A natural language description of when and how to use the tool.
    public let description: String

    /// Creates a tool for decoding machine-readable codes.
    ///
    /// - Parameters:
    ///   - name: The name of the tool as exposed to the model. If not provided, a default name is used.
    ///   - description: A description of what the tool does, used by the model to determine when to call it. If not provided, a default description is used.
    public init(name: String? = nil, description: String? = nil)

    /// The arguments that this tool should accept.
    ///
    /// Typically arguments are either a ``Generable`` type or ``GeneratedContent``.
    public struct Arguments {

        /// An instance of the generation schema.
        nonisolated public static var generationSchema: GenerationSchema { get }

        /// This instance represented as generated content.
        ///
        /// Conformance to this protocol is provided by the `@Generable` macro.
        /// A manual implementation may be used to map values onto properties using
        /// different names. Use the generated content property as shown below, to
        /// manually return a new ``GeneratedContent`` with the properties you specify.
        ///
        /// ```swift
        /// struct Person: ConvertibleToGeneratedContent {
        ///    var name: String
        ///    var age: Int
        ///
        ///    var generatedContent: GeneratedContent {
        ///        GeneratedContent(properties: [
        ///            "firstName": name,
        ///            "ageInYears": age
        ///        ])
        ///    }
        /// }
        /// ```
        ///
        /// - Important: If your type also conforms to ``ConvertibleFromGeneratedContent``,
        /// it is critical that this implementation be symmetrical with ``ConvertibleFromGeneratedContent/init(_:)``.
        nonisolated public var generatedContent: GeneratedContent { get }

        /// A representation of partially generated content
        nonisolated public struct PartiallyGenerated : Identifiable, nonisolated ConvertibleFromGeneratedContent {

            /// The stable identity of the entity associated with this instance.
            public var id: GenerationID

            /// Creates an instance from content generated by a model.
            ///
            /// Conformance to this protocol is provided by the `@Generable` macro.
            /// A manual implementation may be used to map values onto properties using
            /// different names. To manually initialize your type from generated content,
            /// decode the values as shown below:
            ///
            /// ```swift
            /// struct Person: ConvertibleFromGeneratedContent {
            ///     var name: String
            ///     var age: Int
            ///
            ///     init(_ content: GeneratedContent) {
            ///         self.name = try content.value(forProperty: "firstName")
            ///         self.age = try content.value(forProperty: "ageInYears")
            ///     }
            /// }
            /// ```
            ///
            /// - Important: If your type also conforms to ``ConvertibleToGeneratedContent``,
            /// it is critical that this implementation be symmetrical with ``ConvertibleToGeneratedContent/generatedContent``.
            ///
            /// - SeeAlso: `@Generable` macro ``Generable(description:)``
            nonisolated public init(_ content: GeneratedContent) throws

            /// A type representing the stable identity of the entity associated with

Truncated.

extension

BarcodeReaderTool.Arguments

NewiOSmacOSwatchOS
extension BarcodeReaderTool.Arguments : nonisolated Generable
Declaration
extension BarcodeReaderTool.Arguments : nonisolated Generable {

    /// Creates an instance from content generated by a model.
    ///
    /// Conformance to this protocol is provided by the `@Generable` macro.
    /// A manual implementation may be used to map values onto properties using
    /// different names. To manually initialize your type from generated content,
    /// decode the values as shown below:
    ///
    /// ```swift
    /// struct Person: ConvertibleFromGeneratedContent {
    ///     var name: String
    ///     var age: Int
    ///
    ///     init(_ content: GeneratedContent) {
    ///         self.name = try content.value(forProperty: "firstName")
    ///         self.age = try content.value(forProperty: "ageInYears")
    ///     }
    /// }
    /// ```
    ///
    /// - Important: If your type also conforms to ``ConvertibleToGeneratedContent``,
    /// it is critical that this implementation be symmetrical with ``ConvertibleToGeneratedContent/generatedContent``.
    ///
    /// - SeeAlso: `@Generable` macro ``Generable(description:)``
    nonisolated public init(_ content: GeneratedContent) throws
}
struct

OCRTool

NewiOSmacOS
public struct OCRTool : Tool, @unchecked Sendable

A tool that recognizes text in an image.

The tool returns a string containing all recognized text from the image. To enable this tool, configure your LanguageModelSession with an instance of OCRTool.

let ocrTool = OCRTool()
let session = LanguageModelSession(tools: [ocrTool])

You can override the default name and description to customize how the model identifies and uses the tool.

let customTool = OCRTool(
    name: "extractText",
    description: "Extract text from documents"
)
Declaration
public struct OCRTool : Tool, @unchecked Sendable {

    /// A unique name for the tool, such as "get_weather", "toggleDarkMode", or "search contacts".
    public let name: String

    /// A natural language description of when and how to use the tool.
    public let description: String

    /// Creates a tool for recognizing text in images.
    ///
    /// - Parameters:
    ///   - name: The name of the tool as exposed to the model. If not provided, a default name is used.
    ///   - description: A description of what the tool does, used by the model to determine when to call it. If not provided, a default description is used.
    public init(name: String? = nil, description: String? = nil)

    /// The arguments that this tool should accept.
    ///
    /// Typically arguments are either a ``Generable`` type or ``GeneratedContent``.
    public struct Arguments {

        /// An instance of the generation schema.
        nonisolated public static var generationSchema: GenerationSchema { get }

        /// This instance represented as generated content.
        ///
        /// Conformance to this protocol is provided by the `@Generable` macro.
        /// A manual implementation may be used to map values onto properties using
        /// different names. Use the generated content property as shown below, to
        /// manually return a new ``GeneratedContent`` with the properties you specify.
        ///
        /// ```swift
        /// struct Person: ConvertibleToGeneratedContent {
        ///    var name: String
        ///    var age: Int
        ///
        ///    var generatedContent: GeneratedContent {
        ///        GeneratedContent(properties: [
        ///            "firstName": name,
        ///            "ageInYears": age
        ///        ])
        ///    }
        /// }
        /// ```
        ///
        /// - Important: If your type also conforms to ``ConvertibleFromGeneratedContent``,
        /// it is critical that this implementation be symmetrical with ``ConvertibleFromGeneratedContent/init(_:)``.
        nonisolated public var generatedContent: GeneratedContent { get }

        /// A representation of partially generated content
        nonisolated public struct PartiallyGenerated : Identifiable, nonisolated ConvertibleFromGeneratedContent {

            /// The stable identity of the entity associated with this instance.
            public var id: GenerationID

            /// Creates an instance from content generated by a model.
            ///
            /// Conformance to this protocol is provided by the `@Generable` macro.
            /// A manual implementation may be used to map values onto properties using
            /// different names. To manually initialize your type from generated content,
            /// decode the values as shown below:
            ///
            /// ```swift
            /// struct Person: ConvertibleFromGeneratedContent {
            ///     var name: String
            ///     var age: Int
            ///
            ///     init(_ content: GeneratedContent) {
            ///         self.name = try content.value(forProperty: "firstName")
            ///         self.age = try content.value(forProperty: "ageInYears")
            ///     }
            /// }
            /// ```
            ///
            /// - Important: If your type also conforms to ``ConvertibleToGeneratedContent``,
            /// it is critical that this implementation be symmetrical with ``ConvertibleToGeneratedContent/generatedContent``.
            ///
            /// - SeeAlso: `@Generable` macro ``Generable(description:)``
            nonisolated public init(_ content: GeneratedContent) throws

            /// A type representing the stable identity of the entity associated with

Truncated.

extension

OCRTool.Arguments

NewiOSmacOS
extension OCRTool.Arguments : nonisolated Generable
Declaration
extension OCRTool.Arguments : nonisolated Generable {

    /// Creates an instance from content generated by a model.
    ///
    /// Conformance to this protocol is provided by the `@Generable` macro.
    /// A manual implementation may be used to map values onto properties using
    /// different names. To manually initialize your type from generated content,
    /// decode the values as shown below:
    ///
    /// ```swift
    /// struct Person: ConvertibleFromGeneratedContent {
    ///     var name: String
    ///     var age: Int
    ///
    ///     init(_ content: GeneratedContent) {
    ///         self.name = try content.value(forProperty: "firstName")
    ///         self.age = try content.value(forProperty: "ageInYears")
    ///     }
    /// }
    /// ```
    ///
    /// - Important: If your type also conforms to ``ConvertibleToGeneratedContent``,
    /// it is critical that this implementation be symmetrical with ``ConvertibleToGeneratedContent/generatedContent``.
    ///
    /// - SeeAlso: `@Generable` macro ``Generable(description:)``
    nonisolated public init(_ content: GeneratedContent) throws
}
typealias

BarcodeReaderTool.Output

NewiOSmacOSwatchOS
public typealias Output = some PromptRepresentable

The output that this tool produces for the language model to reason about in subsequent interactions.

Typically output is either a String or a Generable type.

typealias

BarcodeReaderTool.Arguments.PartiallyGenerated.ID

NewiOSmacOSwatchOS
public typealias ID = GenerationID

A type representing the stable identity of the entity associated with an instance.

typealias

OCRTool.Output

NewiOSmacOS
public typealias Output = some PromptRepresentable

The output that this tool produces for the language model to reason about in subsequent interactions.

Typically output is either a String or a Generable type.

typealias

OCRTool.Arguments.PartiallyGenerated.ID

NewiOSmacOS
public typealias ID = GenerationID

A type representing the stable identity of the entity associated with an instance.

No APIs match your filter.

← More in Apple Intelligence, ML & Evaluation