vibesort-rs
Sort arrays using Large Language Models (LLMs).
Installation
Add this to your Cargo.toml:
[dependencies]
vibesort-rs = "0.2.2"
tokio = { version = "1.48", features = ["rt", "macros"] }
Usage
Sorting Numbers
use vibesort_rs::Vibesort;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let sorter = Vibesort::new(
"your-api-key",
"gpt-5",
"https://api.openai.com/v1",
);
let numbers = vec![3, 1, 4, 1, 5, 9, 2, 6];
let sorted = sorter.sort(&numbers).await?;
println!("{:?}", sorted);
Ok(())
}
Sorting Strings
For sorting string arrays, you can use the convenient sort_str method:
use vibesort_rs::Vibesort;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let sorter = Vibesort::new(
"your-api-key",
"gpt-5",
"https://api.openai.com/v1",
);
let words = vec!["banana", "apple", "cherry"];
let sorted = sorter.sort_str(&words).await?;
println!("{:?}", sorted);
Ok(())
}
Requirements
- An API key for an LLM service (OpenAI, Anthropic, or any compatible API)
- The API must support OpenAI's chat completion format
Error Handling
use vibesort_rs::{Vibesort, VibesortError};
match sorter.sort(&numbers).await {
Ok(sorted) => println!("Sorted: {:?}", sorted),
Err(VibesortError::ApiError(msg)) => eprintln!("API error: {}", msg),
Err(e) => eprintln!("Error: {}", e),
}
License
This project is licensed under the MIT License. See the LICENSE file for details.