Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/apple-llm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
A Vercel AI SDK provider for Apple Foundation Models, enabling access to Apple Intelligence in React Native applications.

**Requirements:**
- iOS 26+

- iOS 26+ for text generation
- iOS 26.4+ for token counting and Image Playground generation
- iOS 27+ for image prompts, Private Cloud Compute, and Vision built-in tools
- Apple Intelligence enabled device
- Vercel AI SDK v5
- React Native New Architecture
Expand All @@ -14,16 +17,21 @@ import { generateText } from 'ai'

const answer = await generateText({
model: apple(),
prompt: 'What is the meaning of life?'
prompt: 'What is the meaning of life?',
})
```

## Features

- ✅ Text generation with Apple Foundation Models
- ✅ Image prompts on iOS 27+
- ✅ Runtime model info and context-size metadata
- ✅ Private Cloud Compute language model selection on iOS 27+
- ✅ Structured outputs
- ✅ Tool calling
- ✅ Vision OCR and barcode built-in tools on iOS 27+
- ✅ Streaming
- ✅ Image Playground generation through the AI SDK image API

## Documentation

Expand Down
17 changes: 16 additions & 1 deletion packages/apple-llm/ios/AppleLLM.mm
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ - (void)generateText:(nonnull NSArray *)messages
@"topP": options.topP().has_value() ? @(options.topP().value()) : [NSNull null],
@"topK": options.topK().has_value() ? @(options.topK().value()) : [NSNull null],
@"schema": options.schema() ?: [NSNull null],
@"tools": options.tools() ?: [NSNull null]
@"tools": options.tools() ?: [NSNull null],
@"providerOptions": options.providerOptions() ?: [NSNull null]
};

auto callToolBlock = ^(NSString *toolId, NSString *arguments, void (^completion)(id, NSError *)) {
Expand All @@ -131,6 +132,19 @@ - (void)countTokens:(nonnull NSString *)text
[_llm countTokens:text resolve:resolve reject:reject];
}

- (void)getModelInfo:(NSString *)locale
model:(NSString *)model
resolve:(nonnull RCTPromiseResolveBlock)resolve
reject:(nonnull RCTPromiseRejectBlock)reject {
[_llm getModelInfo:locale model:model resolve:resolve reject:reject];
}

- (void)generateImages:(nonnull NSDictionary *)options
resolve:(nonnull RCTPromiseResolveBlock)resolve
reject:(nonnull RCTPromiseRejectBlock)reject {
[_llm generateImages:options resolve:resolve reject:reject];
}

- (void)cancelStream:(nonnull NSString *)streamId {
[_llm cancelStream:streamId];
}
Expand All @@ -144,6 +158,7 @@ - (void)generateStream:(nonnull NSString *)streamId messages:(nonnull NSArray *)
@"topK": options.topK().has_value() ? @(options.topK().value()) : [NSNull null],
@"schema": options.schema() ?: [NSNull null],
@"tools": options.tools() ?: [NSNull null],
@"providerOptions": options.providerOptions() ?: [NSNull null],
};

auto callToolBlock = ^(NSString *toolId, NSString *arguments, void (^completion)(id, NSError *)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/apple-llm/ios/AppleLLMError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ enum AppleLLMError: Error, LocalizedError {
return "Generation error: \(message)"
case .streamNotFound(let id):
return "Stream with ID \(id) not found"
case .invalidMessage(let role):
return "Invalid message role '\(role)'. Supported roles are: system, user, assistant"
case .invalidMessage(let message):
return "Invalid message: \(message)"
case .conflictingSamplingMethods:
return "Cannot specify both topP and topK parameters simultaneously. Please use only one sampling method."
case .invalidSchema(let message):
Expand Down
Loading
Loading