diff options
| author | sigoden <sigoden@gmail.com> | 2024-11-05 07:24:56 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-05 07:24:56 +0800 |
| commit | 0a324b6ddd4b89cc61a8dd15eeb06d60273308fa (patch) | |
| tree | 2ee36bea4579e413770f80b6861e4b0697b544dd /src/config/agent.rs | |
| parent | 79973a2d7d4cb296438fcc62c56871fe933d7789 (diff) | |
| download | aichat-0a324b6ddd4b89cc61a8dd15eeb06d60273308fa.tar.gz | |
refactor: users can choose whether to initialize the agent RAG (#968)
Diffstat (limited to 'src/config/agent.rs')
| -rw-r--r-- | src/config/agent.rs | 35 |
1 files changed, 22 insertions, 13 deletions
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"); } } } |
