Passer au contenu

Démarrage

Fenêtre de terminal
bun add @capgo/capacitor-llm
bunx cap sync
import { CapgoLLM } from '@capgo/capacitor-llm';

Crée une nouvelle session de discussion

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

Envoie un message à l'IA dans une session de discussion spécifique

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

Obtient l'état de disponibilité du LLM

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

Configure la configuration du modèle

  • iOS : Utilisez « Intelligence d'Apple » en tant que chemin pour le modèle système, ou fournissez un chemin vers le modèle MediaPipe
  • Android : Chemin vers un fichier de modèle MediaPipe (dans le répertoire des assets ou des fichiers)
import { CapgoLLM } from '@capgo/capacitor-llm';
await CapgoLLM.setModel({} as ModelOptions);

Télécharge un modèle à partir d'une URL et le sauvegarde dans le bon emplacement

  • iOS : Télécharge dans le répertoire des documents de l'application
  • Android : Télécharge dans le répertoire des fichiers de l'application
import { CapgoLLM } from '@capgo/capacitor-llm';
await CapgoLLM.downloadModel({} as DownloadModelOptions);

Options de configuration du modèle.

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

Options pour télécharger un modèle.

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

Résultat du téléchargement du modèle.

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

Données d’événement pour le texte reçu de l’IA.

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

Données d'événement pour la complétion de l'IA.

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

Données d'événement pour le progrès de téléchargement.

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

Données d'événement pour les changements de statut de disponibilité.

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

Cette page est générée à partir du plugin’s src/definitions.tsRe-réexécutez la synchronisation lorsque les données publiques API changent en amont.