From 0a324b6ddd4b89cc61a8dd15eeb06d60273308fa Mon Sep 17 00:00:00 2001 From: sigoden Date: Tue, 5 Nov 2024 07:24:56 +0800 Subject: refactor: users can choose whether to initialize the agent RAG (#968) --- src/config/agent.rs | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'src/config/agent.rs') diff --git a/src/config/agent.rs b/src/config/agent.rs index a062bea..39c913a 100644 --- a/src/config/agent.rs +++ b/src/config/agent.rs @@ -62,20 +62,29 @@ impl Agent { let rag = if rag_path.exists() { Some(Arc::new(Rag::load(config, "rag", &rag_path)?)) } else if !definition.documents.is_empty() { - println!("The agent has the documents, initializing RAG..."); - let mut document_paths = vec![]; - for path in &definition.documents { - if is_url(path) { - document_paths.push(path.to_string()); - } else { - let new_path = safe_join_path(&functions_dir, path) - .ok_or_else(|| anyhow!("Invalid document path: '{path}'"))?; - document_paths.push(new_path.display().to_string()) + let mut ans = false; + if *IS_STDOUT_TERMINAL { + ans = Confirm::new("The agent has the documents, init RAG?") + .with_default(true) + .prompt()?; + } + if ans { + let mut document_paths = vec![]; + for path in &definition.documents { + if is_url(path) { + document_paths.push(path.to_string()); + } else { + let new_path = safe_join_path(&functions_dir, path) + .ok_or_else(|| anyhow!("Invalid document path: '{path}'"))?; + document_paths.push(new_path.display().to_string()) + } } + let rag = + Rag::init(config, "rag", &rag_path, &document_paths, abort_signal).await?; + Some(Arc::new(rag)) + } else { + None } - Some(Arc::new( - Rag::init(config, "rag", &rag_path, &document_paths, abort_signal).await?, - )) } else { None }; @@ -375,7 +384,7 @@ fn init_variables( .prompt()?; variable.value = value; } else { - bail!("Failed to init agent variables in the script mode."); + bail!("Failed to init agent variables in non-interactive mode"); } } } -- cgit v1.2.3