3 个不稳定版本

0.3.0 2024年7月26日
0.1.1 2024年7月23日
0.1.0 2024年7月21日

#1275网络编程

Download history 211/week @ 2024-07-19 177/week @ 2024-07-26 9/week @ 2024-08-02

每月397次 下载

MIT 许可证

27KB
600

ollama-rest.rs

异步 Rust 对 Ollama REST API 的绑定,使用 reqwesttokioserdechrono

安装

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!();

或者,创建自己的聊天机器人界面!查看 此示例(命令行界面)和 此示例(REST API)。

依赖

~7–18MB
~258K SLoC