一个 Swift 库,可以在 Apple 平台设备上本地运行 Alpaca-LoRA 预测,以实现类似 ChatGPT 的应用程序。
它基本上是 alpaca.cpp 的一个封装器,为其提供了一个简单的 Swift API。
import AlpacaChat
// Load model and instantiate a chat.
let model = try await Model.load(from: URL(fileURLWithPath: "model.bin"))
let chat = Chat(model: model)
// Ask users to get prompt.
let prompt = readLine()!
// Run prediction and print tokens.
for try await token in chat.predictTokens(for: prompt) {
print(token)
}
阅读 alpaca.cpp、alpaca-lora 和 llma.cpp,然后创建 4 位量化的 ggml
模型 bin 文件。
例如,将其放置在 /Applications/AlpacaChatApp/Resouces/model.bin
中,然后构建并运行应用程序。
请参阅实际的命令行和 SwiftUI 应用程序以了解用法。
一个可以在 macOS 上运行的命令行聊天应用程序。
要构建,请使用 Xcode 或直接使用 swift
命令。
$ cd Applications/AlpacaChatCLI
$ swift build -c release
$ .build/release/AlpacaChatCLI -m /path/to/model.bin
一个可以在 iOS 设备上运行的 SwiftUI 聊天应用程序。
要在真机设备上构建并运行应用程序,您需要创建自己的 AppID 和允许扩展内存使用权限的 provisioning profile。
放置 /Applications/AlpacaChatApp/Configurations/Local.xcconfig
以提供用于签名的本地开发配置。
您可能需要更改 scheme 以使用 Release 配置进行运行,否则可能会非常慢。