pub mod folder;
#[cfg(feature = "remote-sources")]
pub mod ftp;
#[cfg(feature = "remote-sources")]
pub mod sftp;
use crate::config::SourceKind;
#[cfg(not(feature = "remote-sources"))]
use crate::RagError;
use crate::{RagConfig, Result};
use async_trait::async_trait;
use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct SourceRef {
pub uri: String,
pub name: String,
pub rel_path: String,
}
#[async_trait]
pub trait DocumentSource: Send + Sync {
async fn list(&self) -> Result<Vec<SourceRef>>;
async fn fetch(&self, r: &SourceRef) -> Result<Vec<u8>>;
}
pub fn from_config(cfg: &RagConfig) -> Result<Arc<dyn DocumentSource>> {
match cfg.source {
SourceKind::Folder => Ok(Arc::new(folder::FolderSource::new(&cfg.source_path))),
SourceKind::Ftp => {
#[cfg(feature = "remote-sources")]
{
Ok(Arc::new(ftp::FtpSource::from_config(cfg)?))
}
#[cfg(not(feature = "remote-sources"))]
{
Err(RagError::FeatureDisabled(
"ftp".into(),
"remote-sources".into(),
))
}
}
SourceKind::Sftp => {
#[cfg(feature = "remote-sources")]
{
Ok(Arc::new(sftp::SftpSource::from_config(cfg)?))
}
#[cfg(not(feature = "remote-sources"))]
{
Err(RagError::FeatureDisabled(
"sftp".into(),
"remote-sources".into(),
))
}
}
}
}