floneum
kalosm-0.3.0
Floneum使开发使用本地预训练的AI模型的应用程序变得容易。这个Monorepo中有两个主要项目:
Kalosm是Rust预先训练模型的简单界面,可背向floneum。它使其易于与预训练,语言,音频和图像模型进行交互。
Kalosm支持各种模型。这是当前支持的模型的列表:
| 模型 | 方式 | 尺寸 | 描述 | 量化 | CUDA +金属加速 | 例子 |
|---|---|---|---|---|---|---|
| 骆驼 | 文本 | 1B-70B | 通用语言模型 | ✅ | ✅ | 骆驼3聊天 |
| Mistral | 文本 | 7-13b | 通用语言模型 | ✅ | ✅ | Mistral聊天 |
| 皮 | 文本 | 2b-4b | 小型推理的语言模型 | ✅ | ✅ | PHI 3聊天 |
| 耳语 | 声音的 | 20MB-1GB | 音频转录模型 | ✅ | ✅ | 现场耳语转录 |
| rwuerstchen | 图像 | 5GB | 图像生成模型 | ✅ | rwuerstchen图像生成 | |
| 特罗克 | 图像 | 3GB | 光学特征识别模型 | ✅ | 文本识别 | |
| 细分任何东西 | 图像 | 50MB-400MB | 图像分割模型 | 图像分割 | ||
| 伯特 | 文本 | 100MB-1GB | 文本嵌入模型 | ✅ | 语义搜索 |
Kalosm还支持围绕预训练的模型的各种实用程序。其中包括:
Kalosm使用蜡烛机学习库来运行纯生锈模型。它支持量化和加速模型,并在llama.cpp上表现出色:
Mistral 7b
| 加速器 | Kalosm | Llama.cpp |
|---|---|---|
| 金属(M2) | 39 t/s | 27 t/s |
Kalosm用任意解析器支持结构化的生成。它使用自定义解析器引擎和采样器以及结构感知的加速度,使结构的生成比不受控制的文本生成更快。您可以采用任何生锈类型,并添加#[derive(Parse, Schema)]以使其可与结构化生成:
use kalosm :: language :: * ;
/// A fictional character
# [ derive ( Parse , Schema , Clone , Debug ) ]
struct Character {
/// The name of the character
# [ parse ( pattern = "[A-Z][a-z]{2,10} [A-Z][a-z]{2,10}" ) ]
name : String ,
/// The age of the character
# [ parse ( range = 1 ..= 100 ) ]
age : u8 ,
/// A description of the character
# [ parse ( pattern = "[A-Za-z ]{40,200}" ) ]
description : String ,
}
# [ tokio :: main ]
async fn main ( ) {
// First create a model. Chat models tend to work best with structured generation
let model = Llama :: phi_3 ( ) . await . unwrap ( ) ;
// Then create a task with the parser as constraints
let task = Task :: builder_for :: < [ Character ; 10 ] > ( "You generate realistic JSON placeholders for characters" )
. build ( ) ;
// Finally, run the task
let mut stream = task . run ( "Create a list of random characters" , & model ) ;
stream . to_std_out ( ) . await . unwrap ( ) ;
let character = stream . await . unwrap ( ) ;
println ! ( "{character:?}" ) ;
}除了正则表达式外,您还可以提供自己的语法来生成结构化数据。这使您可以将响应限制为所需的任何结构,包括JSON,HTML和XML等复杂数据结构。
此快速启动将使您使用一个简单的聊天机器人启动并运行。让我们开始吧!
Kalosm网站上提供了更完整的Kalosm指南,示例文件夹中提供了示例。
cargo new kalosm-hello-world
cd ./kalosm-hello-world # You can use `--features language,metal`, `--features language,cuda`, or `--features language,mkl` if your machine supports an accelerator
cargo add kalosm --features language
cargo add tokio --features fullmain.rs文件 use kalosm :: language :: * ;
# [ tokio :: main ]
async fn main ( ) -> Result < ( ) , Box < dyn std :: error :: Error > > {
let model = Llama :: phi_3 ( ) . await ? ;
let mut chat = Chat :: builder ( model )
. with_system_prompt ( "You are a pirate called Blackbeard" )
. build ( ) ;
loop {
chat . add_message ( prompt_input ( " n > " ) ? )
. to_std_out ( )
. await ? ;
}
}cargo run --release如果您对任何一个项目都感兴趣,则可以加入不和谐讨论该项目并获得帮助。