From 5efb44c644cf211f64e241ebf961abc36d9a51e1 Mon Sep 17 00:00:00 2001 From: sigoden Date: Wed, 4 Dec 2024 06:56:25 +0800 Subject: feat: `--file/.file` accept file formats in document_loaders (#1033) --- src/config/input.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src/config/input.rs') diff --git a/src/config/input.rs b/src/config/input.rs index fa6f00c..42bb8ec 100644 --- a/src/config/input.rs +++ b/src/config/input.rs @@ -90,7 +90,9 @@ impl Input { texts.push(String::new()); } for (path, contents) in files { - texts.push(format!("====== PATH: {path} ======\n{contents}\n")); + texts.push(format!( + "============ PATH: {path} ============\n\n{contents}\n" + )); } let (role, with_session, with_agent) = resolve_role(&config.read(), role); Ok(Self { @@ -392,9 +394,10 @@ async fn load_documents( data_urls.insert(sha256(&data_url), file_path); medias.push(data_url) } else { - let text = read_file(&file_path) + let document = load_file(&loaders, &file_path) + .await .with_context(|| format!("Unable to read file '{file_path}'"))?; - files.push((file_path, text)); + files.push((file_path, document.contents)); } } for file_url in remote_urls { @@ -459,12 +462,3 @@ fn read_media_to_data_url(image_path: &str) -> Result { Ok(data_url) } - -fn read_file>(file_path: P) -> Result { - let file_path = file_path.as_ref(); - - let mut text = String::new(); - let mut file = File::open(file_path)?; - file.read_to_string(&mut text)?; - Ok(text) -} -- cgit v1.2.3