跳过内容

开始使用

终端窗口
bun add @capgo/capacitor-llm
bunx cap sync
import { CapgoLLM } from '@capgo/capacitor-llm';

创建新聊天会话

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

在特定聊天会话中发送消息给 AI

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

获取 LLM 的就绪状态

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

设置模型配置

  • iOS:使用“Apple Intelligence”作为系统模型路径,或者提供MediaPipe模型路径
  • Android:MediaPipe模型文件路径(在assets或files目录)
import { CapgoLLM } from '@capgo/capacitor-llm';
await CapgoLLM.setModel({} as ModelOptions);

downloadModel

下载模型

下载一个模型并将其保存到适当的位置

  • iOS:下载到应用的文档目录
  • Android:下载到应用的文件目录
import { CapgoLLM } from '@capgo/capacitor-llm';
await CapgoLLM.downloadModel({} as DownloadModelOptions);

类型参考

类型参考

ModelOptions

模型选项

模型配置选项。

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

下载模型选项

下载模型的选项。

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

下载模型结果

模型下载结果。

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

复制到剪贴板

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

复制到剪贴板

AI完成事件数据。

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

DownloadProgressEvent

下载进度事件

下载进度事件数据。

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

ReadinessChangeEvent

就绪状态变化事件

就绪状态变化事件数据。

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

真实数据来源

真实数据来源

此页面由插件生成。 src/definitions.ts当公共API上游更改时,请重新同步。