Rig 是一个 Rust 库,用于构建可扩展、模块化且高效的 LLM 驱动应用程序。
您可以在官方文档和 crate API 参考中找到更多信息。
use rig::{completion::Prompt, providers::openai};
#[tokio::main]
async fn main() {
// Create OpenAI client and model
// This requires the `OPENAI_API_KEY` environment variable to be set.
let openai_client = openai::Client::from_env();
let gpt4 = openai_client.agent("gpt-4").build();
// Prompt the model and print its response
let response = gpt4
.prompt("Who are you?")
.await
.expect("Failed to prompt GPT-4");
println!("GPT-4: {response}");
}
https://github.com/0xPlaygrounds/rig
Statum 是一个用于构建有限状态机的零样板 Rust 库,支持编译时状态转换验证。
为什么选择 Statum?
use statum::{state, machine};
#[state]
pub enum TaskState {
New,
InProgress,
Complete,
}
#[machine]
struct Task<S: TaskState> {
id: String,
name: String,
}
impl Task<New> {
fn start(self) -> Task<InProgress> {
self.transition()
}
}
impl Task<InProgress> {
fn complete(self) -> Task<Complete> {
self.transition()
}
}
fn main() {
let task = Task::new("task-1".to_owned(), "Important Task".to_owned())
.start()
.complete();
}
https://github.com/eboody/statum
--
From 日报小组 Mike
社区学习交流平台订阅:
原文作者:Rust语言中文社区;如有侵权,请联系管理员删除。