diff options
| author | sigoden <sigoden@gmail.com> | 2024-12-04 06:56:25 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-04 06:56:25 +0800 |
| commit | 5efb44c644cf211f64e241ebf961abc36d9a51e1 (patch) | |
| tree | 530e2e89716206107a75ec6b189dbdb19c57469a /src/config/input.rs | |
| parent | e86a9f3ee93d6ea0d19e0af04c5a63b41ca72582 (diff) | |
| download | aichat-5efb44c644cf211f64e241ebf961abc36d9a51e1.tar.gz | |
feat: `--file/.file` accept file formats in document_loaders (#1033)
Diffstat (limited to 'src/config/input.rs')
| -rw-r--r-- | src/config/input.rs | 18 |
1 files changed, 6 insertions, 12 deletions
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<String> { Ok(data_url) } - -fn read_file<P: AsRef<Path>>(file_path: P) -> Result<String> { - 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) -} |
