Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
nicarq committed Dec 20, 2024
1 parent fc8add6 commit b045994
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::error::LLMProviderError;
use super::execution::prompts::general_prompts::JobPromptGenerator;
use super::job_manager::JobManager;
use super::llm_stopper::LLMStopper;
use shinkai_embedding::embedding_generator::EmbeddingGenerator;
use shinkai_message_primitives::schemas::llm_providers::common_agent_llm_provider::ProviderOrAgent;
use shinkai_message_primitives::shinkai_utils::shinkai_logging::{shinkai_log, ShinkaiLogLevel, ShinkaiLogOption};
use shinkai_sqlite::SqliteManager;
Expand Down
3 changes: 2 additions & 1 deletion shinkai-libs/shinkai-fs/src/file_parser/file_parser.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use shinkai_embedding::embedding_generator::EmbeddingGenerator;

use super::file_parser_types::TextGroup;
use super::local_parsing::LocalFileParser;

use crate::embedding_generator::EmbeddingGenerator;
use crate::shinkai_fs_error::ShinkaiFsError;
use std::{future::Future, pin::Pin};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::file_parser::ShinkaiFileParser;
use super::file_parser_types::TextGroup;
use crate::embedding_generator::EmbeddingGenerator;
use crate::shinkai_fs_error::ShinkaiFsError;
use keyphrases::KeyPhraseExtractor;
use regex::Regex;
use shinkai_embedding::embedding_generator::EmbeddingGenerator;
use std::collections::HashMap;
use std::{future::Future, pin::Pin};

Expand Down
1 change: 1 addition & 0 deletions shinkai-libs/shinkai-fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
pub mod shinkai_fs_error;
pub mod shinkai_file_manager;
pub mod shinkai_file_manager_ops;
pub mod file_parser;
16 changes: 14 additions & 2 deletions shinkai-libs/shinkai-fs/src/shinkai_file_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use shinkai_sqlite::SqliteManager;
use shinkai_message_primitives::schemas::shinkai_fs::ParsedFile;

use crate::shinkai_fs_error::ShinkaiFsError;
use crate::file_parser::ShinkaiFileParser;
use crate::embedding_generator::EmbeddingGenerator;

pub struct ShinkaiFileManager;

Expand All @@ -30,11 +32,12 @@ pub enum FileProcessingMode {
impl ShinkaiFileManager {
/// Process file: If not in DB, add it. If supported, generate chunks.
/// If already processed, consider checking if file changed (not implemented here).
pub fn process_file(
pub async fn process_file(
path: ShinkaiPath,
base_dir: &Path,
sqlite_manager: &SqliteManager,
mode: FileProcessingMode,
generator: &dyn EmbeddingGenerator,
) -> Result<(), ShinkaiFsError> {
let rel_path = Self::compute_relative_path(&path, base_dir)?;
let parsed_file = if let Some(pf) = sqlite_manager.get_parsed_file_by_rel_path(&rel_path)? {
Expand Down Expand Up @@ -67,9 +70,18 @@ impl ShinkaiFileManager {
match mode {
FileProcessingMode::Auto => {
// Implement logic for Auto mode
let file_buffer = fs::read(path.as_path())?;
let text_groups = ShinkaiFileParser::process_file_into_text_groups(
file_buffer,
rel_path.clone(),
1024, // Example max_node_text_size
VRSourceReference::from_file(&rel_path, TextChunkingStrategy::V1)?,
).await?;
// Further processing...
}
FileProcessingMode::NoParsing => {
// Implement logic for NoParsing mode
// NoParsing mode: Skip parsing logic
// You might still want to update metadata or perform other tasks
}
FileProcessingMode::MustParse => {
// Implement logic for MustParse mode
Expand Down
4 changes: 1 addition & 3 deletions shinkai-libs/shinkai-fs/src/shinkai_file_manager_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,9 @@ impl ShinkaiFileManager {
#[cfg(test)]
mod tests {
use super::*;
use shinkai_embedding::model_type::{EmbeddingModelType, OllamaTextEmbeddingsInference};
use std::fs::{self, File};
use std::io::Read;
use std::path::PathBuf;
use tempfile::{tempdir, NamedTempFile};
use tempfile::tempdir;

#[test]
fn test_remove_empty_folder() {
Expand Down

0 comments on commit b045994

Please sign in to comment.