refactor: throw error if using non-exist RAG in CMD mode (#917)

pull/920/head
sigoden 1 week ago committed by GitHub
parent 4bc74f7e90
commit a3e2c2a147
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -32,6 +32,9 @@ impl Agent {
) -> Result<Self> {
let functions_dir = Config::agent_functions_dir(name)?;
let definition_file_path = functions_dir.join("index.yaml");
if !definition_file_path.exists() {
bail!("Unknown agent `{name}`");
}
let functions_file_path = functions_dir.join("functions.json");
let variables_path = Config::agent_variables_file(name)?;
let rag_path = Config::agent_rag_file(name, "rag")?;

@ -205,7 +205,7 @@ impl Default for Config {
agent: None,
model: Default::default(),
functions: Default::default(),
working_mode: WorkingMode::Command,
working_mode: WorkingMode::Cmd,
last_message: None,
}
}
@ -1199,6 +1199,9 @@ impl Config {
Some(name) => {
let rag_path = config.read().rag_file(name)?;
if !rag_path.exists() {
if config.read().working_mode.is_cmd() {
bail!("Unknown RAG '{name}'")
}
Rag::init(config, name, &rag_path, &[], abort_signal).await?
} else {
Rag::load(config, name, &rag_path)?
@ -1376,7 +1379,7 @@ impl Config {
pub fn apply_prelude(&mut self) -> Result<()> {
let prelude = match self.working_mode {
WorkingMode::Command => self.prelude.as_ref(),
WorkingMode::Cmd => self.prelude.as_ref(),
WorkingMode::Repl => self.repl_prelude.as_ref().or(self.prelude.as_ref()),
WorkingMode::Serve => return Ok(()),
};
@ -2043,12 +2046,15 @@ pub fn load_env_file() -> Result<()> {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum WorkingMode {
Command,
Cmd,
Repl,
Serve,
}
impl WorkingMode {
pub fn is_cmd(&self) -> bool {
*self == WorkingMode::Cmd
}
pub fn is_repl(&self) -> bool {
*self == WorkingMode::Repl
}

@ -50,7 +50,7 @@ async fn main() -> Result<()> {
} else if text.is_none() && cli.file.is_empty() {
WorkingMode::Repl
} else {
WorkingMode::Command
WorkingMode::Cmd
};
setup_logger(working_mode.is_serve())?;
let config = Arc::new(RwLock::new(Config::init(working_mode)?));

@ -26,5 +26,5 @@ pub async fn render_stream(
}
pub fn render_error(err: anyhow::Error) {
eprintln!("{}", error_text(&pretty_error(&err)));
eprint!("{}", error_text(&pretty_error(&err)));
}

Loading…
Cancel
Save