跳过内容

开始

GitHub

您可以使用我们的 AI 助手设置来安装插件。使用以下命令将 Capgo 技能添加到您的 AI 工具中:

终端窗口
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

然后使用以下提示:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-llm` plugin in my project.

如果您更喜欢手动设置,请按照以下命令安装插件并遵循以下平台特定的说明:

终端窗口
bun add @capgo/capacitor-llm
bunx cap sync

导入

导入
import { CapgoLLM } from '@capgo/capacitor-llm';

API概述

API概述

createChat

创建会话

创建会话

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

sendMessage

创建会话

发送消息

import { CapgoLLM } from '@capgo/capacitor-llm';
await CapgoLLM.sendMessage({
chatId: 'chat-id-123',
message: 'Hello from Capacitor',
});

getReadiness

获取准备状态

获取LLM的就绪状态

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

设置模型配置

  • iOS:使用"Apple Intelligence"作为系统模型路径,或者提供MediaPipe模型路径
  • Android:assets或files目录下的MediaPipe模型文件路径
import { CapgoLLM } from '@capgo/capacitor-llm';
await CapgoLLM.setModel({
path: 'path/to/file',
modelType: 'task',
});

从URL下载模型并将其保存到适当位置

  • iOS:下载到应用的文档目录
  • Android:下载到应用的文件目录
import { CapgoLLM } from '@capgo/capacitor-llm';
const result = await CapgoLLM.downloadModel({ url: 'https://example.com' });
console.log(result);

类型参考

类型参考

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

下载模型结果

从AI事件中获取文本

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

TextFromAiEvent

模型下载结果

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

AiFinishedEvent

AiFinishedEvent

AI完成事件数据

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

DownloadProgressEvent

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

ReadinessChangeEvent

就绪状态变化事件数据

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

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

如果您正在使用 开始使用 来规划仪表板和 API 操作,请将其连接到 使用 @capgo/capacitor-llm 使用 @capgo/capacitor-llm API 简介 API Overview 简介 为简介中的实现细节 API 键 为API 键中的实现细节,并 设备 为设备的实现细节。