orch
是一个用于构建基于语言模型的应用程序和代理的Rust编程语言库。它主要为magic-cli项目而构建,但也可以在其他场景中使用。
[!注意]
如果该项目获得关注,它可以被编译为其他语言(如Python)的插件或独立的WebAssembly模块。
cargo add orch cargo add orch_response
或者,将orch
作为依赖项添加到你的Cargo.toml
文件中:
[dependencies] orch = "*" # 替换为最新版本 orch_response = "*" # 替换为最新版本
use orch::execution::*; use orch::lm::*; #[tokio::main] async fn main() { let lm = OllamaBuilder::new().try_build().unwrap(); let executor = TextExecutorBuilder::new().with_lm(&lm).try_build().unwrap(); let response = executor.execute("2+2等于多少?").await.expect("执行失败"); println!("{}", response.content); }
use orch::execution::*; use orch::lm::*; use tokio_stream::StreamExt; #[tokio::main] async fn main() { let lm = OllamaBuilder::new().try_build().unwrap(); let executor = TextExecutorBuilder::new().with_lm(&lm).try_build().unwrap(); let mut response = executor.execute_stream("2+2等于多少?").await.expect("执行失败"); while let Some(chunk) = response.stream.next().await { match chunk { Ok(chunk) => print!("{chunk}"), Err(e) => { println!("错误:{e}"); break; } } } println!(); }