LLMFarm_core.swift

LLMFarm_core Swift 库用于处理大型语言模型 (LLM)。它允许您使用特定参数加载不同的 LLM。
基于 ggmlllama.cpp,作者是 Georgi Gerganov

也使用了来自以下项目的源代码:

特性

推理模型

采样方法

安装

git clone https://github.com/guinmoon/llmfarm_core.swift

Swift Package Manager

使用 Xcode(文件 > 添加包...)或将其添加到项目的 Package.swift 文件中,将 llmfarm_core 添加到您的项目中

dependencies: [
  .package(url: "https://github.com/guinmoon/llmfarm_core.swift")
]

构建和调试

要调试 llmfarm_core 包,请不要忘记在 Package.swift 中注释掉 .unsafeFlags(["-Ofast"])。请记住,调试版本比发布版本慢。

要构建支持 QKK_64 的版本,请在 Package.swift 中取消注释 .unsafeFlags(["-DGGML_QKK_64"])

用法

更多示例请参见 examples 目录

示例:从提示生成输出

import Foundation
import llmfarm_core

let maxOutputLength = 256
var total_output = 0

func mainCallback(_ str: String, _ time: Double) -> Bool {
    print("\(str)",terminator: "")
    total_output += str.count
    if(total_output>maxOutputLength){
        return true
    }
    return false
}

var input_text = "State the meaning of life."

let ai = AI(_modelPath: "llama-2-7b.q4_K_M.gguf",_chatName: "chat")
var params:ModelContextParams = .default
params.use_metal = true

try? ai.loadModel(ModelInference.LLama_gguf,contextParams: params)
ai.model.promptFormat = .LLaMa

let output = try? ai.model.predict(input_text, mainCallback)

基于此库的项目

一个在 iOS 和 MacOS 上本地运行 LLaMA 和其他大型语言模型的应用程序。