use std::io::Write;
use anyhow::Result;
use goldenfile::Mint;
use llmchain::DocumentLoader;
use llmchain::DocumentPath;
use llmchain::GithubPRLoader;
#[tokio::test]
async fn test_github_pr_loader() -> Result<()> {
let token = std::env::var("L_GITHUB_TOKEN").expect("L_GITHUB_TOKEN is not set");
let curdir = std::env::current_dir()?.to_str().unwrap().to_string();
let testdata_dir = format!("{}/tests/testdata/loaders", curdir);
let github_pr_loader = GithubPRLoader::create("datafuselabs", "databend", &token);
let documents = github_pr_loader
.load(DocumentPath::from_list(vec![
11450, 11451, 11452, 11453, 11454, 11455, 11456, 11457, 11458, 11459, 11460,
]))
.await?;
let mut mint = Mint::new(&testdata_dir);
let golden_path = "github/github_pr_loader.golden";
let mut file = mint.new_goldenfile(golden_path)?;
for (i, doc) in documents.iter().enumerate() {
writeln!(
file,
"part={}, len={}, md5={}, path:{}",
i,
doc.content.len(),
doc.content_md5,
doc.path
)?;
writeln!(
file,
"------------------------------------------------------------"
)?;
writeln!(file, "{}", doc.content)?;
}
Ok(())
}