Zum Inhalt springen

Erste Schritte

GitHub

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:

Terminalfenster
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

Nutze 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:

Terminalfenster
bun add @capgo/capacitor-llm
bunx 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.' });

Höre auf textFromAi, aiFinished, und generationError in der Chat-Session, wie im Plugin-README dokumentiert.

const { readiness } = await CapgoLLM.getReadiness();
if (readiness !== 'ready') {
showModelDownloadScreen();
}
await CapgoLLM.downloadModel({ url: 'https://cdn.example.com/model.litertlm' });
  • 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, sendMessage damit keine Tokens verloren gehen.

Erstellt eine neue Chat-Session

import { CapgoLLM } from '@capgo/capacitor-llm';
const result = await CapgoLLM.createChat();
console.log(result);

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',
});

Ruft den Readiness-Status des LLM ab

import { CapgoLLM } from '@capgo/capacitor-llm';
const result = await CapgoLLM.getReadiness();
console.log(result);

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',
});

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);

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;
}

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;
}

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;
}

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;
}

Event-Daten für KI-Completion.

export interface AiFinishedEvent {
/** The chat session ID that finished */
chatId: string;
}

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;
}

Event-Daten für Änderungen des Readiness-Status.

export interface ReadinessChangeEvent {
/** The readiness status */
readiness: string;
}

Diese Seite wird aus dem Plugin- src/definitions.ts. Führe den Sync erneut aus, wenn sich der öffentliche API upstream ändert.

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.