Erste Schritte
Kopiere einen Setup-Prompt mit den Installationsschritten und dem vollständigen Markdown-Guide für dieses Plugin.
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.
Installieren
Abschnitt „Installation“Du kannst unser KI-gestütztes Setup nutzen, um das Plugin zu installieren. Füge die Capgo Skills mit dem folgenden Befehl deinem KI-Tool hinzu:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsNutze dann diesen Prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-llm` plugin in my project.Wenn du ein manuelles Setup bevorzugst, installiere das Plugin mit den folgenden Befehlen und befolge die plattformspezifischen Anweisungen unten:
bun add @capgo/capacitor-llmbunx cap syncImportieren
Abschnitt mit dem Titel „Import“import { CapgoLLM } from '@capgo/capacitor-llm';Quickstart
Abschnitt „Quick start“import { CapgoLLM } from '@capgo/capacitor-llm';
const { id: chatId } = await CapgoLLM.createChat();await CapgoLLM.sendMessage({ chatId, message: 'Summarize this error log.' });Lauscht auf textFromAi, aiFinished, und generationError in der Chat-Session, wie im Plugin-README dokumentiert.
Beispiel: Readiness vor der UI
Abschnitt mit dem Titel „Beispiel: Readiness vor UI“const { readiness } = await CapgoLLM.getReadiness();if (readiness !== 'ready') { showModelDownloadScreen();}Beispiel: Custom Model herunterladen
Abschnitt mit dem Titel „Beispiel: Ein eigenes Modell herunterladen“await CapgoLLM.downloadModel({ url: 'https://cdn.example.com/model.litertlm' });Häufige Stolperfallen
Abschnitt „Häufige Fallstricke“- Web offline: MediaPipe GenAI lädt von einem CDN, cache die Runtime und das Modell für Offline-Demos.
- Android Gemini Nano: nicht auf jedem Gerät verfügbar, Fallback-Modelle behandeln.
- Streaming: Listener vorher anhängen
sendMessagedamit Sie keine Tokens verpassen.
API Übersicht
Abschnitt „API Übersicht“createChat
Abschnitt mit dem Titel „createChat“Erstellt eine neue Chat-Session
import { CapgoLLM } from '@capgo/capacitor-llm';
const result = await CapgoLLM.createChat();console.log(result);sendMessage
Abschnitt mit dem Titel „sendMessage“Sendet eine Nachricht an die KI in einer bestimmten Chat-Session
import { CapgoLLM } from '@capgo/capacitor-llm';
await CapgoLLM.sendMessage({ chatId: 'chat-id-123', message: 'Hello from Capacitor',});getReadiness
Abschnitt mit dem Titel „getReadiness“Ruft den Readiness-Status des LLM ab
import { CapgoLLM } from '@capgo/capacitor-llm';
const result = await CapgoLLM.getReadiness();console.log(result);Setzt die Modellkonfiguration
- iOS: Verwenden Sie „Apple Intelligence“ als Pfad für das Systemmodell oder geben Sie den Pfad zum MediaPipe-Modell an
- Android: Pfad zu einer MediaPipe-Modelldatei (im assets- oder files-Verzeichnis)
import { CapgoLLM } from '@capgo/capacitor-llm';
await CapgoLLM.setModel({ path: 'path/to/file', modelType: 'task',});downloadModel
Abschnitt mit dem Titel „downloadModel“Lädt ein Modell von einer URL herunter und speichert es am entsprechenden Speicherort
- iOS: Lädt in das documents-Verzeichnis der App herunter
- Android: Lädt in das files-Verzeichnis der App herunter
import { CapgoLLM } from '@capgo/capacitor-llm';
const result = await CapgoLLM.downloadModel({ url: 'https://example.com' });console.log(result);Typreferenz
Abschnitt mit dem Titel „Typreferenz“ModelOptions
Abschnitt mit dem Titel „ModelOptions“Konfigurationsoptionen für das Modell.
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
Abschnitt „DownloadModelOptions“Optionen für den Download eines Modells.
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
Abschnitt „DownloadModelResult“Ergebnis des Modell-Downloads.
export interface DownloadModelResult { /** Path where the model was saved */ path: string; /** Path where the companion file was saved (if applicable) */ companionPath?: string;}TextFromAiEvent
Abschnitt „TextFromAiEvent“Event-Daten für den von der KI empfangenen Text.
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
Abschnitt „AiFinishedEvent“Event-Daten für den Abschluss der KI.
export interface AiFinishedEvent { /** The chat session ID that finished */ chatId: string;}DownloadProgressEvent
Abschnitt mit dem Titel “DownloadProgressEvent”Ereignisdaten für den Download-Fortschritt.
export interface DownloadProgressEvent { /** Percentage of download completed (0-100) */ progress: number; /** Total bytes to download */ totalBytes?: number; /** Bytes downloaded so far */ downloadedBytes?: number;}ReadinessChangeEvent
Abschnitt mit dem Titel “ReadinessChangeEvent”Ereignisdaten für Änderungen des Bereitstellungsstatus.
export interface ReadinessChangeEvent { /** The readiness status */ readiness: string;}Source of Truth
Abschnitt mit dem Titel „Source of Truth“Diese Seite wird aus dem Plugin generiert src/definitions.ts. Führe den Sync erneut aus, wenn sich das öffentliche API upstream ändert.
Weiter geht's nach Getting Started
Abschnitt: „Weiter geht’s mit Getting Started“Wenn du es nutzt Erste Schritte um Dashboard- und API-Operationen zu planen, verbinde es mit Verwendung von @capgo/capacitor-llm für die native Funktion in Verwendung von @capgo/capacitor-llm, API Übersicht für Details zur Implementierung im API Overview, Einführung für die Implementierungsdetails in der Einleitung, API Schlüssel für das Implementierungsdetail in API Keys und Geräte für das Implementierungsdetail in Devices.