跳过主要内容
返回到插件
@capgo/capacitor-llm
教程
由github.com/Cap-go

LLM

在Apple Intelligence和MLX支持下,使用本地设备运行大型语言模型

指南

LLM教程

使用@capgo/capacitor-llm

用于与设备语言模型进行交互的LLM插件接口。

安装

bun add @capgo/capacitor-llm
bunx cap sync

此插件暴露的内容

  • createChat - 创建一个新的聊天会话。
  • sendMessage - 在特定聊天会话中发送消息给AI。
  • getReadiness - 获取LLM的就绪状态。
  • setModel - 设置模型配置 - iOS: 使用 "Apple Intelligence" 作为系统模型路径,或者提供 MediaPipe 模型路径 - Android: 在 assets 或 files 目录中的 MediaPipe 模型文件路径。

示例用法

createChat

创建一个新的聊天会话。

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

await CapgoLLM.createChat();

sendMessage

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

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

await CapgoLLM.sendMessage({} as { chatId: string; message: string });

getReadiness

获取 LLM 的就绪状态。

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

await CapgoLLM.getReadiness();

setModel

设置模型配置 - iOS: 使用 "Apple Intelligence" 作为系统模型路径,或者提供 MediaPipe 模型路径 - Android: 在 assets 或 files 目录中的 MediaPipe 模型文件路径。

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

await CapgoLLM.setModel({} as ModelOptions);

全局参考