Zum Inhalt springen

Einstieg

Terminal-Fenster
bun add @capgo/capacitor-llm
bunx cap sync
import { CapgoLLM } from '@capgo/capacitor-llm';

Erstellt eine neue Chat-Sitzung

import { CapgoLLM } from '@capgo/capacitor-llm';
await CapgoLLM.createChat();

Sendet eine Nachricht an den AI in einer bestimmten Chat-Sitzung

import { CapgoLLM } from '@capgo/capacitor-llm';
await CapgoLLM.sendMessage({} as { chatId: string; message: string });

Ermittelt den Zustand der Bereitschaft des LLM

import { CapgoLLM } from '@capgo/capacitor-llm';
await CapgoLLM.getReadiness();

Setzt die Modellkonfiguration

  • iOS: Verwende „Apple Intelligence“ als Pfad für das Systemmodell oder gib den Pfad zu einem MediaPipe-Modell an
  • Android: Pfad zu einem MediaPipe-Modell-Datei (in assets- oder files-Verzeichnis)
import { CapgoLLM } from '@capgo/capacitor-llm';
await CapgoLLM.setModel({} as ModelOptions);

Lädt ein Modell von einer URL herunter und speichert es an der entsprechenden Stelle

  • iOS: Heruntergeladen in das Anwendungs-Verzeichnis für Dokumente
  • Android: Heruntergeladen in das Anwendungs-Verzeichnis für Dateien
import { CapgoLLM } from '@capgo/capacitor-llm';
await CapgoLLM.downloadModel({} as DownloadModelOptions);

Modellkonfigurationsoptionen.

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 zum Herunterladen 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 Modellherunterladens.

export interface DownloadModelResult {
/** Path where the model was saved */
path: string;
/** Path where the companion file was saved (if applicable) */
companionPath?: string;
}

Ereignisdaten für Text, der von AI empfangen wurde.

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

Daten für die KI-Vervollständigung.

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

Daten für den Downloadfortschritt.

export interface DownloadProgressEvent {
/** Percentage of download completed (0-100) */
progress: number;
/** Total bytes to download */
totalBytes?: number;
/** Bytes downloaded so far */
downloadedBytes?: number;
}

Daten für Änderungen im Bereitschaftszustand.

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

Diese Seite wurde aus dem Plugin generiert. src/definitions.tsRe-run die Synchronisation, wenn die öffentliche API upstream geändert wird.