Skip to content

deveix/react-native-apple-llm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

30 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

React Native Apple LLM Plugin

A React Native plugin to access Apple Intelligence Foundation Models using native on-device LLM APIs. This module lets you check model availability, create sessions, generate structured outputs (JSON), and text using Apple's LLMs, all from React Native.

πŸš€ Features

  • On-device Apple Intelligence - Access Apple's Foundation Models locally
  • Privacy-focused - All processing happens on-device, no data sent to servers
  • Structured JSON output - Generate structured data with JSON schemas
  • Text generation - Create human-like text responses
  • Session management - Configure and manage LLM sessions
  • TypeScript support - Full type safety and IntelliSense

πŸ“± Requirements

  • iOS 26.0
  • Xcode 26
  • Apple Intelligence enabled device (iPhone 15 Pro, iPhone 16 series, M1+ iPad/Mac)

mit licence npm version npm downloads npm downloads

Follow on X

πŸ“¦ Installation

  1. Install the package:
npm install react-native-apple-llm
# or
yarn add react-native-apple-llm
# or
pnpm add react-native-apple-llm
  1. Link the native module (if not autolinked):
npx pod-install
# or if using CocoaPods directly
cd ios && pod install

🎯 Use Cases

This plugin is perfect for building:

  • AI-powered mobile apps with privacy-first approach
  • Chatbots and virtual assistants that work offline
  • Content generation tools for social media and blogs
  • Data extraction and structuring from user input
  • Smart forms that auto-fill based on natural language
  • Educational apps with personalized AI tutoring
  • Accessibility tools with intelligent text processing

πŸš€ Quick Start

import {
  isFoundationModelsEnabled,
  configureSession,
  generateText,
} from "react-native-apple-llm";

// Check if Apple Intelligence is available
const checkAvailability = async () => {
  const status = await isFoundationModelsEnabled();
  console.log("Apple Intelligence status:", status);
};

// Generate simple text
const generateSimpleText = async () => {
  await configureSession({
    instructions: "You are a helpful assistant.",
  });

  const response = await generateText({
    prompt: "Explain React Native in one sentence",
  });

  console.log(response);
};

πŸ“‹ TODO

  • Streaming support using Event Emitters
  • Tool creation and invocation support
  • Schema as zod
  • Function calling capabilities

πŸ“š API Reference

Methods

isFoundationModelsEnabled(): Promise<FoundationModelsAvailability>

Checks if Foundation Models (Apple Intelligence) are enabled and available on the device.

Returns:

  • "available" - Apple Intelligence is ready to use
  • "appleIntelligenceNotEnabled" - User needs to enable Apple Intelligence in Settings
  • "modelNotReady" - Model is downloading or preparing
  • "unavailable" - Device doesn't support Apple Intelligence
const status = await isFoundationModelsEnabled();
if (status === "available") {
  // Proceed with LLM operations
}

configureSession(options: LLMConfigOptions): Promise<boolean>

Configures the LLM session with system instructions and behavior.

Parameters:

  • options.instructions (optional): System instructions that guide the LLM's behavior
await configureSession({
  instructions:
    "You are an expert React Native developer. Provide concise, practical answers.",
});

generateStructuredOutput(options: LLMGenerateOptions): Promise<any>

Generates structured output using a JSON schema. Perfect for extracting data, creating forms, or building structured responses.

Parameters:

  • options.structure: JSON schema defining the expected output structure
  • options.prompt: The prompt/question for the LLM
const userInfo = await generateStructuredOutput({
  structure: {
    name: { type: "string", description: "User's full name" },
    age: { type: "number", description: "User's age" },
    interests: {
      type: "object",
      properties: {
        hobbies: { type: "string" },
        skills: { type: "string" },
      },
    },
  },
  prompt:
    "Extract user information: John is 25 years old and loves programming and photography",
});

generateText(options: LLMGenerateTextOptions): Promise<string>

Generates natural text responses from the LLM.

Parameters:

  • options.prompt: The prompt/question for the LLM

Returns: Generated text as a string

const explanation = await generateText({
  prompt: "Explain the benefits of on-device AI processing",
});

resetSession(): Promise<boolean>

Resets the current LLM session, clearing any previous context or instructions.

await resetSession();
// Session is now fresh and ready for new instructions

Types

StructureProperty

Defines a property in your JSON schema:

interface StructureProperty {
  type?: "string" | "integer" | "number" | "boolean" | "object";
  description?: string;
  enum?: string[];
  properties?: StructureSchema;
}

StructureSchema

A key-value mapping for defining structured output:

type StructureSchema = {
  [key: string]: StructureProperty;
};

Configuration Options

interface LLMConfigOptions {
  instructions?: string;
}

interface LLMGenerateOptions {
  structure: StructureSchema;
  prompt: string;
}

interface LLMGenerateTextOptions {
  prompt: string;
}

πŸ’‘ Advanced Examples

Building a Smart Recipe Parser

const parseRecipe = async (recipeText: string) => {
  await configureSession({
    instructions:
      "Extract recipe information accurately. Focus on ingredients and steps.",
  });

  const recipe = await generateStructuredOutput({
    structure: {
      title: { type: "string", description: "Recipe name" },
      servings: { type: "number", description: "Number of servings" },
      ingredients: {
        type: "object",
        properties: {
          list: { type: "string", description: "Comma-separated ingredients" },
        },
      },
      instructions: {
        type: "object",
        properties: {
          steps: {
            type: "string",
            description: "Step-by-step cooking instructions",
          },
        },
      },
      cookingTime: { type: "string", description: "Total cooking time" },
    },
    prompt: `Extract recipe details from: ${recipeText}`,
  });

  return recipe;
};

Creating an AI Writing Assistant

const improveWriting = async (text: string, style: string) => {
  await configureSession({
    instructions: `You are a professional writing coach. Improve text while maintaining the author's voice.`,
  });

  const improved = await generateText({
    prompt: `Improve this text in a ${style} style: "${text}"`,
  });

  return improved;
};

Building a Data Extraction Tool

const extractContactInfo = async (businessCard: string) => {
  const contactInfo = await generateStructuredOutput({
    structure: {
      name: { type: "string", description: "Full name" },
      company: { type: "string", description: "Company name" },
      email: { type: "string", description: "Email address" },
      phone: { type: "string", description: "Phone number" },
      address: { type: "string", description: "Business address" },
      website: { type: "string", description: "Website URL" },
    },
    prompt: `Extract contact information from this business card: ${businessCard}`,
  });

  return contactInfo;
};

πŸ”’ Privacy & Security

  • 100% On-device processing - No data leaves your device
  • No internet required - Works completely offline
  • Apple's privacy standards - Built on Apple's privacy-first architecture
  • No tracking or analytics - This plugin doesn't collect any user data
  • Secure by design - Leverages iOS security and sandboxing

πŸ› οΈ Troubleshooting

Common Issues

Apple Intelligence not available:

const status = await isFoundationModelsEnabled();
if (status === "appleIntelligenceNotEnabled") {
  // Guide user to enable Apple Intelligence in Settings > Apple Intelligence & Siri
}

Model not ready:

if (status === "modelNotReady") {
  // Apple Intelligence is downloading. Ask user to wait and try again.
}

Device not supported:

if (status === "unavailable") {
  // Device doesn't support Apple Intelligence. Consider fallback options.
}

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Development Setup

  1. Clone the repository
  2. Install dependencies: yarn install
  3. Build the project: yarn build
  4. Run tests: yarn test

πŸ“„ License

MIT License - see LICENSE.md for details.

πŸ”— Related Projects


Star ⭐ this repo if you find it helpful!

Made with ❀️ by Ahmed Kasem