3 个不稳定版本
0.3.0 | 2024年7月26日 |
---|---|
0.1.1 | 2024年7月23日 |
0.1.0 | 2024年7月21日 |
#1275 在 网络编程
每月397次 下载
27KB
600 行
ollama-rest.rs
异步 Rust 对 Ollama REST API 的绑定,使用 reqwest、tokio、serde 和 chrono。
安装
cargo add [email protected]
特性
名称 | 状态 |
---|---|
完成度 | 工作 ✅ |
嵌入 | 工作 ✅ |
模型创建 | 工作 ✅ |
模型删除 | 工作 ✅ |
模型拉取 | 工作 ✅ |
模型复制 | 工作 ✅ |
本地模型 | 工作 ✅ |
运行模型 | 工作 ✅ |
模型推送 | 实验性 🧪 |
工具 | 实验性 🧪 |
直观查看
查看此示例的 源代码。
use std::io::Write;
use ollama_rest::{models::generate::{GenerationRequest, GenerationResponse}, Ollama};
use serde_json::json;
// By default checking Ollama at 127.0.0.1:11434
let ollama = Ollama::default();
let request = serde_json::from_value::<GenerationRequest>(json!({
"model": "llama3",
"prompt": "Why is the sky blue?",
})).unwrap();
let mut stream = ollama.generate_streamed(&request).await.unwrap();
while let Some(Ok(res)) = stream.next().await {
if !res.done {
print!("{}", res.response);
// Flush stdout for each word to allow realtime output
std::io::stdout().flush().unwrap();
}
}
println!();
依赖
~7–18MB
~258K SLoC