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 mit dem Titel „Installation“Du kannst unser KI-gestütztes Setup nutzen, um das Plugin zu installieren. Füge deinem KI-Tool die Capgo Skills mit folgendem Befehl hinzu:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsNutze anschließend 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 bevorziehst, 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 mit dem Titel „Quickstart“import { CapgoLLM } from '@capgo/capacitor-llm';
const { id: chatId } = await CapgoLLM.createChat();await CapgoLLM.sendMessage({ chatId, message: 'Summarize this error log.' });Höre auf textFromAi, aiFinished, und generationError in der Chat-Session, wie im Plugin-README dokumentiert.
Beispiel: Readiness vor dem UI
Abschnitt mit dem Titel „Beispiel: Readiness vor dem UI“const { readiness } = await CapgoLLM.getReadiness();if (readiness !== 'ready') { showModelDownloadScreen();}Beispiel: Ein Custom Model downloaden
Abschnitt: „Beispiel: Benutzerdefiniertes Modell herunterladen“await CapgoLLM.downloadModel({ url: 'https://cdn.example.com/model.litertlm' });Häufige Fehlerquellen
Abschnitt mit dem Titel „Häufige Fehlerquellen“- Web offline: MediaPipe GenAI lädt von einem CDN; cache Runtime und Modell für Offline-Demos.
- Android Gemini Nano: nicht auf jedem Gerät verfügbar; Fallback-Modelle implementieren.
- Streaming: Listener vorher anhängen,
sendMessagedamit keine Tokens verloren gehen.
API Übersicht
Abschnitt mit dem Titel „API Übersicht“createChat
Abschnitt „createChat“Erstellt eine neue Chat-Session
import { CapgoLLM } from '@capgo/capacitor-llm';
const result = await CapgoLLM.createChat();console.log(result);sendMessage
Abschnitt „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 „getReadiness“Ruft den Readiness-Status des LLM ab
import { CapgoLLM } from '@capgo/capacitor-llm';
const result = await CapgoLLM.getReadiness();console.log(result);setModel
Abschnitt „setModel“Setzt die Modell-Konfiguration
- iOS: Nutze „Apple Intelligence“ als Pfad für das Systemmodell oder gib den Pfad zu einem MediaPipe-Modell an
- Android: Pfad zu einer MediaPipe-Modell-Datei (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 Ort
- iOS: Wird in das Documents-Verzeichnis der App heruntergeladen
- Android: Wird in das files-Verzeichnis der App heruntergeladen
import { CapgoLLM } from '@capgo/capacitor-llm';
const result = await CapgoLLM.downloadModel({ url: 'https://example.com' });console.log(result);Typ-Referenz
Abschnitt mit dem Titel „Type Reference“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 KI-Completion.
export interface AiFinishedEvent { /** The chat session ID that finished */ chatId: string;}DownloadProgressEvent
Abschnitt mit dem Titel „DownloadProgressEvent“Event-Daten 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“Event-Daten für Änderungen des Readiness-Status.
export interface ReadinessChangeEvent { /** The readiness status */ readiness: string;}Source of Truth
Abschnitt mit dem Titel „Source of Truth“Diese Seite wird aus dem Plugin- src/definitions.ts. Führe den Sync erneut aus, wenn sich der öffentliche API upstream ändert.
Weiter mit Getting Started
Abschnitt „Weiter mit Getting Started“Wenn Sie ... verwenden Erste Schritte Um Dashboard- und API-Operationen zu planen, verbinde es mit @capgo/capacitor-llm verwenden für die native Funktion beim Verwenden von @capgo/capacitor-llm, API Übersicht für Details zur Implementierung in der Übersicht zu API, Einführung für das Implementierungsdetail in der Einleitung, API Keys für die Implementierungsdetails in den API Keys und Geräte für die Implementierungsdetails bei Devices.