diff options
| author | sigoden <sigoden@gmail.com> | 2024-06-13 19:41:54 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-13 19:41:54 +0800 |
| commit | f9847475b8eae99a70f16dc63bac67da2632474a (patch) | |
| tree | 032c9eb02540cf8644a2df103d8a45dfc54557be /src/config/mod.rs | |
| parent | 255b194bcc538b2557caa60c5b607b4c4bfc0abd (diff) | |
| download | aichat-f9847475b8eae99a70f16dc63bac67da2632474a.tar.gz | |
feat: add rag and bot related cli options (#595)
Diffstat (limited to 'src/config/mod.rs')
| -rw-r--r-- | src/config/mod.rs | 24 |
1 files changed, 20 insertions, 4 deletions
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(), |
