スタートガイド
インストール手順と、このプラグインの完全なMarkdownガイドを含むセットアッププロンプトをコピーします。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-llm`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/llm/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
インストール
「インストール」セクションAIアシストによるセットアップでプラグインをインストールできます。以下のコマンドを使用して、お使いのAIツールに Capgo のスキルを追加してください:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins次に、以下のプロンプトを使用します:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-llm` plugin in my project.手動セットアップを希望する場合は、以下のコマンドを実行してプラグインをインストールし、下記のプラットフォーム別の手順に従ってください:
bun add @capgo/capacitor-llmbunx cap syncインポート
「インポート」セクションimport { CapgoLLM } from '@capgo/capacitor-llm';クイックスタート
「クイックスタート」セクションimport { CapgoLLM } from '@capgo/capacitor-llm';
const { id: chatId } = await CapgoLLM.createChat();await CapgoLLM.sendMessage({ chatId, message: 'Summarize this error log.' });を監視します: textFromAi, aiFinishedや generationError プラグインのREADMEに記載されているとおり、チャットセッションに対して行います。
例:UI表示前の準備
「例:UI表示前の準備」というセクションconst { readiness } = await CapgoLLM.getReadiness();if (readiness !== 'ready') { showModelDownloadScreen();}例:カスタムモデルのダウンロード
「例:カスタムモデルをダウンロード」セクションawait CapgoLLM.downloadModel({ url: 'https://cdn.example.com/model.litertlm' });よくある落とし穴
「よくある落とし穴」セクション- Web オフライン:MediaPipe GenAI は CDN からロードされるため、オフラインデモ用にランタイムとモデルをキャッシュしてください。
- Android Gemini Nano:すべてのデバイスで利用できるわけではないため、フォールバックモデルを実装してください。
- ストリーミング:事前にリスナーをアタッチして、
sendMessageトークンの取りこぼしを防いでください。
API の概要
「API 概要」セクションcreateChat
「createChat」セクション新しいチャットセッションを作成します
import { CapgoLLM } from '@capgo/capacitor-llm';
const result = await CapgoLLM.createChat();console.log(result);sendMessage
「sendMessage」セクション特定のチャットセッションでAIにメッセージを送信します
import { CapgoLLM } from '@capgo/capacitor-llm';
await CapgoLLM.sendMessage({ chatId: 'chat-id-123', message: 'Hello from Capacitor',});getReadiness
「getReadiness」セクションLLMの準備完了ステータスを取得します
import { CapgoLLM } from '@capgo/capacitor-llm';
const result = await CapgoLLM.getReadiness();console.log(result);setModel
「setModel」セクションモデルの設定を行います
- iOS: システムモデルのパスとして「Apple Intelligence」を使用するか、MediaPipeモデルへのパスを指定します
- Android: MediaPipeモデルファイルへのパス(assetsまたはfilesディレクトリ内)
import { CapgoLLM } from '@capgo/capacitor-llm';
await CapgoLLM.setModel({ path: 'path/to/file', modelType: 'task',});downloadModel
「downloadModel」セクションURLからモデルをダウンロードし、適切な場所に保存します
- iOS: アプリのdocumentsディレクトリにダウンロードします
- Android: アプリのfilesディレクトリにダウンロードします
import { CapgoLLM } from '@capgo/capacitor-llm';
const result = await CapgoLLM.downloadModel({ url: 'https://example.com' });console.log(result);型リファレンス
「型リファレンス」セクションModelOptions
「ModelOptions」セクションモデルの設定オプション
export interface ModelOptions { /** Model path or "Apple Intelligence" for iOS system model */ path: string; /** Model file type/extension (e.g., "task", "bin", "litertlm"). If not provided, will be extracted from path. */ modelType?: string; /** Maximum number of tokens the model handles */ maxTokens?: number; /** Number of tokens the model considers at each step */ topk?: number; /** Amount of randomness in generation (0.0-1.0) */ temperature?: number; /** Random seed for generation */ randomSeed?: number;}DownloadModelOptions
「DownloadModelOptions」セクションモデルをダウンロードするためのオプション。
export interface DownloadModelOptions { /** URL of the model file to download */ url: string; /** Optional: URL of companion file (e.g., .litertlm for Android) */ companionUrl?: string; /** Optional: Custom filename (defaults to filename from URL) */ filename?: string;}DownloadModelResult
「DownloadModelResult」セクションモデルのダウンロード結果。
export interface DownloadModelResult { /** Path where the model was saved */ path: string; /** Path where the companion file was saved (if applicable) */ companionPath?: string;}TextFromAiEvent
「TextFromAiEvent」セクションAIから受信したテキストのイベントデータ。
export interface TextFromAiEvent { /** The text content from AI - this is an incremental chunk, not the full text */ text: string; /** The chat session ID */ chatId: string; /** Whether this is a complete chunk (true) or partial streaming data (false) */ isChunk?: boolean;}AiFinishedEvent
「AiFinishedEvent」セクションAIの処理完了時のイベントデータ。
export interface AiFinishedEvent { /** The chat session ID that finished */ chatId: string;}DownloadProgressEvent
「DownloadProgressEvent」セクションダウンロードの進捗状況に関するイベントデータ。
export interface DownloadProgressEvent { /** Percentage of download completed (0-100) */ progress: number; /** Total bytes to download */ totalBytes?: number; /** Bytes downloaded so far */ downloadedBytes?: number;}ReadinessChangeEvent
「ReadinessChangeEvent」セクション準備完了ステータスの変更に関するイベントデータ。
export interface ReadinessChangeEvent { /** The readiness status */ readiness: string;}Source of Truth
「Source Of Truth」セクションこのページはプラグインの src/definitions.tsから生成されています。upstream で公開 API が変更されたら、再度 sync を実行してください。
Getting Startedの続きを進める
「Getting Started からの続き」セクション使用している場合 スタートガイド ダッシュボードと API の運用を計画するには、これを次と連携させます @capgo/capacitor-llm の使用方法 @capgo/capacitor-llm を使用して Native Build の機能を利用する場合、 API の概要 「API の概要」の実装の詳細については、 はじめに 「はじめに」における実装の詳細については、 API キー および「API Keys」の実装の詳細については、 デバイス 実装の詳細については Devices を参照してください。