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如果您對任何一個項目都感興趣,則可以加入不和諧討論該項目並獲得幫助。