Getting Started
复制一个包含安装步骤和本插件的完整 Markdown 指南的配置提示。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-llm`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/llm/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
安装
标题:安装bun add @capgo/capacitor-llmbunx cap sync导入
标题:导入import { CapgoLLM } from '@capgo/capacitor-llm';API 概述
标题:API 概述createChat
标题:createChat创建新聊天会话
import { CapgoLLM } from '@capgo/capacitor-llm';
await CapgoLLM.createChat();sendMessage
sendMessage的标题将消息发送到特定聊天会话中的AI
import { CapgoLLM } from '@capgo/capacitor-llm';
await CapgoLLM.sendMessage({} as { chatId: string; message: string });getReadiness
getReadiness的标题获取LLM的就绪状态
import { CapgoLLM } from '@capgo/capacitor-llm';
await CapgoLLM.getReadiness();setModel
setModel的标题设置模型配置
- iOS:使用“Apple Intelligence”作为系统模型的路径,或者提供MediaPipe模型的路径
- Android:assets或files目录中的MediaPipe模型文件路径
import { CapgoLLM } from '@capgo/capacitor-llm';
await CapgoLLM.setModel({} as ModelOptions);downloadModel
下载模型从 URL 下载模型并将其保存到适当的位置
- 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;}TextFromAiEvent
名为“从AI获取文本事件”从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
名为“AI完成事件”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
名为“ReadinessChangeEvent”的部分就绪状态变化的事件数据
export interface ReadinessChangeEvent { /** The readiness status */ readiness: string;}真实来源
名为“真实来源”的部分本页是根据插件生成的 src/definitions.ts当公共API在上游发生变化时,重新运行同步。
从开始就继续
名为“从开始就继续”的部分如果您正在使用 开始 为计划仪表板和API操作,连接它 使用@capgo/capacitor-llm 使用@capgo/capacitor-llm的本地能力 API概述 查看API概述的实现细节 介绍 查看介绍的实现细节 API密钥 查看API密钥的实现细节 设备 查看设备的实现细节