TechnologiesMachine Learning & AI

FoundationModels

iOSmacOStvOSwatchOSvisionOS

FoundationModels provides on-device large language model APIs for prompting a model, generating structured content, and running guided generation sessions. You drive a SystemLanguageModel through a LanguageModelSession, sending a Prompt together with Instructions and tuning the request with GenerationOptions, ContextOptions, and a GenerationSchema. Mark your own types as Generable to have the model produce structured, decodable output through GeneratedContent, and constrain results with GenerationGuide. The framework also models supporting concerns such as Tool definitions, Attachment and ImageReference inputs, the running Transcript, LanguageModelError handling, and PrivateCloudComputeLanguageModel for compute beyond the device.

Essentials 5

The on-device language model and the session that drives prompting and generation.

  • Cl
    SystemLanguageModel
    An on-device Apple Foundation Model capable of text generation tasks.
  • Cl
    LanguageModelSession
    An object that represents a session that interacts with a language model.
  • Pr
    LanguageModel
    A protocol that you use to interface with a model.
  • Cl
    PrivateCloudComputeLanguageModel
    A variant of Apple Foundation Models that runs on Private Cloud Compute to provide enhanced
  • St
    LanguageModelCapabilities
    A set of capabilities that a language model provides.

Prompts and Instructions 9

Types for composing the prompt and the guiding instructions you send to the model.

  • St
    Prompt
    A prompt from a person to the model.
  • Pr
    PromptRepresentable
    A type whose value can represent a prompt.
  • St
    Instructions
    Details you provide that define the model's intended behavior on prompts.
  • Pr
    InstructionsRepresentable
    A type that can be represented as instructions.
  • Pr
    DynamicInstructions
    A type that represents dynamic instructions.
  • St
    AnyDynamicInstructions
    A dynamic instructions type that's type-erased.
  • St
    ConditionalDynamicInstructions
    A dynamic instructions type that conditionally selects between two conditions.
  • St
    EmptyDynamicInstructions
    An empty dynamic instructions type..
  • St
    TupleDynamicInstructions
    A dynamic instructions type that represents a tuple.

Structured Generation 8

Protocols and types for producing decodable, schema-constrained structured output.

  • Pr
    Generable
    A type that the model uses when responding to prompts.
  • St
    GeneratedContent
    A type that represents structured, generated content.
  • Pr
    ConvertibleFromGeneratedContent
    A type that can be initialized from generated content.
  • Pr
    ConvertibleToGeneratedContent
    A type that can be converted to generated content.
  • St
    GenerationSchema
    A type that describes the properties of an object and any guides
  • St
    DynamicGenerationSchema
    The dynamic counterpart to the generation schema type that you use to construct schemas at runtime.
  • St
    GenerationGuide
    Guides that control how values are generated.
  • St
    GenerationID
    A unique identifier that is stable for the duration of a response, but not across responses.

Generation Configuration 2

Options that tune how the model generates a response within a session.

  • St
    GenerationOptions
    Options that control how the model generates its response to a prompt.
  • St
    ContextOptions
    Options that configure details that should appear in the prompt.

Tools 2

Definitions that let the model call your code to extend what it can do.

  • Pr
    Tool
    A tool that a model can call to gather information at runtime or perform side effects.
  • St
    AnyTool
    A tool that the framework invokes in dynamic instructions.

Attachments and Image Inputs 4

Inputs that attach additional content, such as images, to a prompt.

  • St
    Attachment
    An asset provided to the model.
  • Pr
    AttachmentContent
    A type that you use as the content of an attachment.
  • St
    ImageAttachmentContent
    A type that holds image data.
  • St
    ImageReference
    A reference to an image in a session's transcript.

Transcripts and Session Properties 5

The running record of a session and the keyed properties that describe its state.

  • St
    Transcript
    A linear history of entries that reflect an interaction with a session.
  • St
    TranscriptErrorHandlingPolicy
    Options for controlling how a language model session manages the transcript when errors occur.
  • Cl
    SessionPropertyValues
    A container for property values.
  • Pr
    SessionPropertyKey
    A protocol for defining a custom session property key.
  • St
    LanguageModelFeedback
    Feedback appropriate for logging or attaching to Feedback Assistant.

Custom Executors 3

Lower-level types for implementing a custom backend that fulfills generation requests.

  • Pr
    LanguageModelExecutor
    A protocol that defines the interface for responding to session requests.
  • St
    LanguageModelExecutorGenerationChannel
    A type you use to send model output deltas and updates to the framework.
  • St
    LanguageModelExecutorGenerationRequest
    A type that contains the details for a generation request.

Errors 1

The error type reported when a language model operation fails.

  • En
    LanguageModelError
    A failure that may occur while generating a response when using any language model.

Structures 3

  • St
    DynamicInstructionsBuilder
  • St
    InstructionsBuilder
    A type that represents an instructions builder.
  • St
    PromptBuilder
    A type that represents a prompt builder.

Extends 10

OptionalNeverBoolStringIntFloatDoubleDecimalArrayResult
← Machine Learning & AI