React Native Apple Provider
React Native Apple Provider
@react-native-ai/apple는 Apple의 온디바이스 AI 기능을 React Native 및 Expo 애플리케이션에 가져다주는 커뮤니티 프로바이더예요. AI SDK를 완전히 디바이스에서 실행할 수 있게 해주며, iOS 26+에서 사용 가능한 Apple Intelligence 파운데이션 모델을 활용해 Apple의 네이티브 AI 프레임워크를 통해 텍스트 생성, 임베딩, 전사(transcription), 음성 합성을 제공해요.
출처: 문서
본문
Apple 프로바이더는 @react-native-ai/apple 모듈에서 사용할 수 있어요. 다음과 같이 설치할 수 있어요:
npm install @react-native-ai/apple
사전 요구사항
Apple 프로바이더를 사용하기 전에 다음이 필요해요:
- React Native 또는 Expo 애플리케이션: 이 프로바이더는 React Native와 Expo 애플리케이션에서만 동작해요. 설정 방법은 Expo Quickstart 가이드를 참고하세요.
- iOS 26+: Apple Intelligence 파운데이션 모델과 핵심 기능에 필요해요.
프로바이더 인스턴스
@react-native-ai/apple에서 기본 프로바이더 인스턴스 apple을 import 할 수 있어요:
import { apple } from '@react-native-ai/apple';
사용 가능 여부 확인
Apple AI 기능을 사용하기 전에 현재 디바이스에서 사용 가능한지 확인할 수 있어요:
if (!apple.isAvailable()) {
// 지원하지 않는 디바이스를 위한 폴백 로직 처리
}
언어 모델
Apple은 Apple Intelligence가 활성화된 iOS 26+ 디바이스에서 Apple Foundation Models을 통해 온디바이스 언어 모델을 제공해요.
텍스트 생성
Apple의 온디바이스 언어 모델로 텍스트를 생성해요:
import { apple } from '@react-native-ai/apple';
import { generateText } from 'ai';
const { text } = await generateText({
model: apple(),
prompt: 'Explain quantum computing in simple terms',
});
스트리밍 텍스트 생성
실시간 텍스트 생성을 위해서는:
import { apple } from '@react-native-ai/apple';
import { streamText } from 'ai';
const result = streamText({
model: apple(),
prompt: 'Write a short story about space exploration',
});
for await (const chunk of result.textStream) {
console.log(chunk);
}
구조화된 출력 생성
Zod 스키마를 사용해 구조화된 데이터를 생성해요:
import { apple } from '@react-native-ai/apple';
import { generateText, Output } from 'ai';
import { z } from 'zod';
const result = await generateText({
model: apple(),
output: Output.object({
schema: z.object({
recipe: z.string(),
ingredients: z.array(z.string()),
cookingTime: z.string(),
}),
}),
prompt: 'Create a recipe for chocolate chip cookies',
});
모델 설정
생성 파라미터를 설정해요:
const { text } = await generateText({
model: apple(),
prompt: 'Generate creative content',
temperature: 0.8, // Controls randomness (0-1)
maxTokens: 150, // Maximum tokens to generate
topP: 0.9, // Nucleus sampling threshold
topK: 40, // Top-K sampling parameter
});
도구 호출 (Tool Calling)
Apple 프로바이더는 도구 호출을 지원하며, 이때 도구는 AI SDK가 아니라 Apple Intelligence가 실행해요. 도구를 생성 호출에서 사용하려면 먼저 createAppleProvider를 사용해 프로바이더에 사전 등록해야 해요.
import { createAppleProvider } from '@react-native-ai/apple';
import { generateText, tool } from 'ai';
import { z } from 'zod';
const getWeather = tool({
description: 'Get current weather information',
inputSchema: z.object({
city: z.string().describe('The city name'),
}),
execute: async ({ city }) => {
return `Weather in ${city}: Sunny, 25°C`;
},
});
// Create a provider with all available tools
const apple = createAppleProvider({
availableTools: {
getWeather,
},
});
// Use the provider with selected tools
const result = await generateText({
model: apple(),
prompt: 'What is the weather like in San Francisco?',
tools: { getWeather },
});
도구는 AI SDK가 아니라 Apple Intelligence가 실행하므로,
stopWhen,onStepStart,onStepEnd같은 멀티스텝 기능은 지원되지 않아요.
텍스트 임베딩
Apple은 iOS 17+에서 사용 가능한 NLContextualEmbedding을 사용해 다국어 텍스트 임베딩을 제공해요.
import { apple } from '@react-native-ai/apple';
import { embed } from 'ai';
const { embedding } = await embed({
model: apple.embeddingModel(),
value: 'Hello world',
});
오디오 전사 (Transcription)
Apple은 iOS 26+에서 사용 가능한 SpeechAnalyzer와 SpeechTranscriber를 사용해 음성-텍스트 전사를 제공해요.
import { apple } from '@react-native-ai/apple';
import { transcribe } from 'ai';
const response = await transcribe({
model: apple.transcriptionModel(),
audio: audioBuffer,
});
console.log(response.text);
음성 합성
Apple은 AVSpeechSynthesizer를 사용한 텍스트-음성 합성을 제공하며, iOS 13+에서 사용 가능하고 iOS 17+에서는 기능이 향상돼요.
기본 음성 생성
텍스트를 음성으로 변환해요:
import { apple } from '@react-native-ai/apple';
import { generateSpeech } from 'ai';
const response = await generateSpeech({
model: apple.speechModel(),
text: 'Hello from Apple on-device speech!',
language: 'en-US',
});
음성 선택
voice 옵션에 식별자를 전달해 음성 합성에 사용할 음성을 설정할 수 있어요.
const response = await generateSpeech({
model: apple.speechModel(),
text: 'Custom voice example',
voice: 'com.apple.ttsbundle.Samantha-compact',
});
사용 가능한 음성을 확인하려면 getVoices 메서드를 사용할 수 있어요:
import { AppleSpeech } from '@react-native-ai/apple';
const voices = await AppleSpeech.getVoices();
console.log(voices);
플랫폼 요구사항
각 Apple AI 기능은 서로 다른 iOS 버전 요구사항을 가져요:
| 기능 | 최소 iOS 버전 | 추가 요구사항 |
|---|---|---|
| 텍스트 생성 | iOS 26+ | Apple Intelligence 활성화 디바이스 |
| 텍스트 임베딩 | iOS 17+ | - |
| 오디오 전사 | iOS 26+ | 언어 자산 다운로드 |
| 음성 합성 | iOS 13+ | Personal Voice는 iOS 17+ |
Apple Intelligence 기능은 현재 일부 디바이스에서만 사용 가능해요. 최신 디바이스 호환성 정보는 Apple 문서를 확인하세요.
추가 자료
- React Native Apple Provider GitHub 저장소
- React Native AI 문서
- Apple Intelligence
- Apple Foundation Models
더 알아보기 (Learn more)
- 출처 문서: React Native Apple Provider