diff options
Diffstat (limited to 'src/config')
| -rw-r--r-- | src/config/bot.rs | 20 | ||||
| -rw-r--r-- | src/config/mod.rs | 24 | ||||
| -rw-r--r-- | src/config/session.rs | 3 |
3 files changed, 26 insertions, 21 deletions
diff --git a/src/config/bot.rs b/src/config/bot.rs index e1e1df6..e02cce7 100644 --- a/src/config/bot.rs +++ b/src/config/bot.rs @@ -53,22 +53,14 @@ impl Bot { None => config.current_model().clone(), } }; - let rag = if rag_path.exists() { Some(Arc::new(Rag::load(config, "rag", &rag_path)?)) } else if embeddings_dir.is_dir() { - println!("The bot has an embeddings directory, RAG is initializing..."); - let ans = Confirm::new("The bot attached embeddings, init RAG?") - .with_default(true) - .prompt()?; - if ans { - let doc_path = embeddings_dir.display().to_string(); - Some(Arc::new( - Rag::init(config, "rag", &rag_path, &[doc_path], abort_signal).await?, - )) - } else { - None - } + println!("The bot uses an embeddings directory, initializing RAG..."); + let doc_path = embeddings_dir.display().to_string(); + Some(Arc::new( + Rag::init(config, "rag", &rag_path, &[doc_path], abort_signal).await?, + )) } else { None }; @@ -121,7 +113,7 @@ impl Bot { self.rag.clone() } - pub fn converstaion_staters(&self) -> &[String] { + pub fn conversation_staters(&self) -> &[String] { &self.definition.conversation_starters } } diff --git a/src/config/mod.rs b/src/config/mod.rs index b1eb41f..571bf2c 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -442,7 +442,20 @@ impl Config { } pub fn info(&self) -> Result<String> { - if let Some(session) = &self.session { + if let Some(bot) = &self.bot { + let output = bot.export()?; + if let Some(session) = &self.session { + let session = session + .export()? + .split('\n') + .map(|v| format!(" {v}")) + .collect::<Vec<_>>() + .join("\n"); + Ok(format!("{output}session:\n{session}")) + } else { + Ok(output) + } + } else if let Some(session) = &self.session { session.export() } else if let Some(role) = &self.role { role.export() @@ -896,6 +909,7 @@ impl Config { pub async fn use_bot( config: &GlobalConfig, name: &str, + session: Option<&str>, abort_signal: AbortSignal, ) -> Result<()> { if !config.read().function_calling { @@ -904,11 +918,13 @@ impl Config { if config.read().bot.is_some() { bail!("Already in a bot, please run '.exit bot' first to exit the current bot."); } - let prelude = config.read().bot_prelude.clone(); let bot = Bot::init(config, name, abort_signal).await?; config.write().rag = bot.rag(); config.write().bot = Some(bot); - if let Some(session) = prelude { + let session = session + .map(|v| v.to_string()) + .or_else(|| config.read().bot_prelude.clone()); + if let Some(session) = session { config.write().use_session(Some(&session))?; } Ok(()) @@ -1033,7 +1049,7 @@ impl Config { ".bot" => list_bots().into_iter().map(|v| (v, None)).collect(), ".starter" => match &self.bot { Some(bot) => bot - .converstaion_staters() + .conversation_staters() .iter() .map(|v| (v.clone(), None)) .collect(), diff --git a/src/config/session.rs b/src/config/session.rs index 2aff467..38855cc 100644 --- a/src/config/session.rs +++ b/src/config/session.rs @@ -126,9 +126,6 @@ impl Session { } pub fn export(&self) -> Result<String> { - if self.path.is_none() { - bail!("Not found session '{}'", self.name) - } let mut data = json!({ "path": self.path, "model": self.model().id(), |
