https://github.com/aandreba/rustygen
https://github.com/aandreba/rustygen
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/aandreba/rustygen
- Owner: Aandreba
- License: mit
- Created: 2023-12-11T14:42:15.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-12-11T18:44:04.000Z (over 2 years ago)
- Last Synced: 2025-07-04T11:48:41.604Z (11 months ago)
- Language: Rust
- Size: 48.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rustygen - A Rusty version of autogen
## Examples
**Basic**
```rust
use rustygen::{assistants::gpt::ChatGPT, record::ChatRecord, Conversation, MainConversation};
use libopenai::Client;
#[tokio::main]
async fn main() -> color_eyre::Result<()> {
let _ = color_eyre::install();
dotenv::dotenv()?;
let client = Client::new(None, None)?;
let mut conversation = MainConversation::::new()
.agent(String::from("Tell me about yourself"))
.agent(ChatGPT::new("gpt-3.5-turbo", client));
println!("{:#?}", conversation.play().await?);
return Ok(());
}
```
**Chess**
```rust
use rustygen::{
agent::Agent,
assistants::{
chess::ChessEngine,
gpt::{ChessError, ChessGPT},
},
Conversation, MainConversation,
};
use chess::Action;
use libopenai::Client;
use std::time::Duration;
#[tokio::main]
async fn main() -> color_eyre::Result<()> {
let _ = color_eyre::install();
dotenv::dotenv()?;
let client = Client::new(None, None)?;
let mut i = 0;
let mut conversation = MainConversation::::new()
.while_loop(|game| {
println!("Round {i}");
i += 1;
game.result().is_none()
})
.agent(ChessEngine::new("./stockfish-ubuntu-x86-64", Duration::from_secs(1)).await?)
.agent(
ChessGPT::new("gpt-3.5-turbo", client, 5).catch(|e| async move {
match e {
// Fall back to Stockfish whenever ChatGPT fails generating a legal move
ChessError::NoLegalMoveFound => {
println!("Resorting to Stockfish for GPT's move");
Ok(
ChessEngine::new("./stockfish-ubuntu-x86-64", Duration::from_secs(1))
.await
.unwrap(),
)
}
e => Err(e),
}
}),
)
.end_while();
let mut game = chess::Game::new();
if let Err(e) = conversation.play_with(&mut game).await {
eprintln!("{e}");
}
for action in game.actions() {
match action {
Action::MakeMove(x) => println!("{x}"),
other => println!("{other:?}"),
}
}
println!("{}", game.current_position().to_string());
return Ok(());
}
```