use web2llm::{FetchMode, Web2llm, Web2llmConfig};
#[tokio::main]
async fn main() {
let config = Web2llmConfig {
max_tokens: 300, fetch_mode: FetchMode::Static,
..Default::default()
};
let client = Web2llm::new(config).unwrap();
let url = "https://en.wikipedia.org/wiki/Rust_(programming_language)";
println!("Fetching and chunking {}...", url);
match client.fetch(url).await {
Ok(result) => {
println!("\nSuccess! Divided into {} chunks.", result.chunks.len());
println!("Total estimated tokens: {}\n", result.total_tokens());
for chunk in result.chunks.iter().take(5) {
println!("--------------------------------------------------");
println!(
"CHUNK #{} (Tokens: {}, Score: {:.2})",
chunk.index, chunk.tokens, chunk.score
);
println!("--------------------------------------------------");
let snippet: String = chunk.content.chars().take(150).collect();
println!("{}...", snippet);
println!();
}
if result.chunks.len() > 5 {
println!("... and {} more chunks.", result.chunks.len() - 5);
}
}
Err(e) => eprintln!("Error: {}", e),
}
}