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.
- ClSystemLanguageModelAn on-device Apple Foundation Model capable of text generation tasks.
- ClLanguageModelSessionAn object that represents a session that interacts with a language model.
- PrLanguageModelA protocol that you use to interface with a model.
- ClPrivateCloudComputeLanguageModelA variant of Apple Foundation Models that runs on Private Cloud Compute to provide enhanced
- StLanguageModelCapabilitiesA 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.
- StPromptA prompt from a person to the model.
- PrPromptRepresentableA type whose value can represent a prompt.
- StInstructionsDetails you provide that define the model's intended behavior on prompts.
- PrInstructionsRepresentableA type that can be represented as instructions.
- PrDynamicInstructionsA type that represents dynamic instructions.
- StAnyDynamicInstructionsA dynamic instructions type that's type-erased.
- StConditionalDynamicInstructionsA dynamic instructions type that conditionally selects between two conditions.
- StEmptyDynamicInstructionsAn empty dynamic instructions type..
- StTupleDynamicInstructionsA dynamic instructions type that represents a tuple.
Structured Generation 8
Protocols and types for producing decodable, schema-constrained structured output.
- PrGenerableA type that the model uses when responding to prompts.
- StGeneratedContentA type that represents structured, generated content.
- PrConvertibleFromGeneratedContentA type that can be initialized from generated content.
- PrConvertibleToGeneratedContentA type that can be converted to generated content.
- StGenerationSchemaA type that describes the properties of an object and any guides
- StDynamicGenerationSchemaThe dynamic counterpart to the generation schema type that you use to construct schemas at runtime.
- StGenerationGuideGuides that control how values are generated.
- StGenerationIDA 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.
- StGenerationOptionsOptions that control how the model generates its response to a prompt.
- StContextOptionsOptions 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.
- PrToolA tool that a model can call to gather information at runtime or perform side effects.
- StAnyToolA tool that the framework invokes in dynamic instructions.
Attachments and Image Inputs 4
Inputs that attach additional content, such as images, to a prompt.
- StAttachmentAn asset provided to the model.
- PrAttachmentContentA type that you use as the content of an attachment.
- StImageAttachmentContentA type that holds image data.
- StImageReferenceA 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.
- StTranscriptA linear history of entries that reflect an interaction with a session.
- StTranscriptErrorHandlingPolicyOptions for controlling how a language model session manages the transcript when errors occur.
- ClSessionPropertyValuesA container for property values.
- PrSessionPropertyKeyA protocol for defining a custom session property key.
- StLanguageModelFeedbackFeedback appropriate for logging or attaching to Feedback Assistant.
Custom Executors 3
Lower-level types for implementing a custom backend that fulfills generation requests.
- PrLanguageModelExecutorA protocol that defines the interface for responding to session requests.
- StLanguageModelExecutorGenerationChannelA type you use to send model output deltas and updates to the framework.
- StLanguageModelExecutorGenerationRequestA type that contains the details for a generation request.
Errors 1
The error type reported when a language model operation fails.
- EnLanguageModelErrorA failure that may occur while generating a response when using any language model.
Structures 3
- StDynamicInstructionsBuilder
- StInstructionsBuilderA type that represents an instructions builder.
- StPromptBuilderA type that represents a prompt builder.