use langfuse_ergonomic::ClientBuilder;
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt::init();
let client = ClientBuilder::from_env()?.build()?;
println!(" Dataset Management Example");
println!("=============================");
println!("\n1. Creating a dataset...");
let dataset = client
.create_dataset()
.name("example-dataset")
.description("An example dataset for testing")
.metadata(json!({
"created_by": "example",
"purpose": "testing"
}))
.input_schema(json!({
"type": "object",
"properties": {
"prompt": {"type": "string"},
"context": {"type": "string"}
}
}))
.expected_output_schema(json!({
"type": "object",
"properties": {
"answer": {"type": "string"},
"confidence": {"type": "number"}
}
}))
.call()
.await?;
println!(
" Created dataset: {}",
serde_json::to_string_pretty(&dataset)?
);
println!("\n2. Listing datasets...");
let datasets = client.list_datasets().page(1).limit(10).call().await?;
println!(" Datasets: {}", serde_json::to_string_pretty(&datasets)?);
println!("\n3. Getting specific dataset...");
match client.get_dataset("example-dataset").await {
Ok(dataset) => {
println!(
" Dataset details: {}",
serde_json::to_string_pretty(&dataset)?
);
}
Err(e) => {
println!(" Could not retrieve dataset: {}", e);
}
}
println!("\n4. Getting dataset runs...");
match client.get_dataset_runs("example-dataset").await {
Ok(runs) => {
println!(" Dataset runs: {}", serde_json::to_string_pretty(&runs)?);
}
Err(e) => {
println!(" Could not retrieve dataset runs: {}", e);
}
}
println!("\n Dataset management example completed!");
Ok(())
}