Lompat ke Konten

Mulai

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

API Ringkasan

Ringkasan API

createChat

Buat Obrolan

Membuat sesi obrolan baru

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

sendMessage

Kirim Pesan

Mengirim pesan ke AI di sesi obrolan tertentu

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

getReadiness

Periksa Kesiapan

Mendapatkan status kesiapan LLM

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

setModel

Atur Model

Mengatur konfigurasi model

  • iOS: Gunakan "Inteligensi Apple" sebagai jalur untuk model sistem, atau berikan jalur ke model MediaPipe
  • Android: Jalur ke file model MediaPipe (di direktori aset atau file)
import { CapgoLLM } from '@capgo/capacitor-llm';
await CapgoLLM.setModel({} as ModelOptions);

Mengunduh model dari URL dan menyimpannya ke lokasi yang tepat

  • iOS: Mengunduh ke direktori dokumen aplikasi
  • Android: Mengunduh ke direktori file aplikasi
import { CapgoLLM } from '@capgo/capacitor-llm';
await CapgoLLM.downloadModel({} as DownloadModelOptions);

Opsi pengaturan model.

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

Opsi untuk mengunduh model.

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

Hasil pengunduhan model.

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

Data acara teks yang diterima dari AI.

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

Data acara selesai AI.

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

Data acara untuk kemajuan download.

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

Data acara untuk perubahan status kesiapan.

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

Halaman ini dihasilkan dari plugin’s src/definitions.ts. Re-run sinkronisasi ketika publik API berubah di atas.