From d645046d2d729a55345e18f97fefcab545086f53 Mon Sep 17 00:00:00 2001 From: sigoden Date: Sat, 22 Jun 2024 06:54:03 +0800 Subject: refactor: rename bot to agent (#628) --- src/config/agent.rs | 260 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/config/bot.rs | 260 -------------------------------------------------- src/config/input.rs | 16 ++-- src/config/mod.rs | 142 +++++++++++++-------------- src/config/session.rs | 4 +- 5 files changed, 341 insertions(+), 341 deletions(-) create mode 100644 src/config/agent.rs delete mode 100644 src/config/bot.rs (limited to 'src/config') diff --git a/src/config/agent.rs b/src/config/agent.rs new file mode 100644 index 0000000..91a38b4 --- /dev/null +++ b/src/config/agent.rs @@ -0,0 +1,260 @@ +use super::*; + +use crate::{ + client::Model, + function::{Functions, FunctionsFilter, SELECTED_ALL_FUNCTIONS}, +}; + +use anyhow::{Context, Result}; +use std::{fs::read_to_string, path::Path}; + +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Serialize)] +pub struct Agent { + name: String, + config: AgentConfig, + definition: AgentDefinition, + #[serde(skip)] + functions: Functions, + #[serde(skip)] + rag: Option>, + #[serde(skip)] + model: Model, +} + +impl Agent { + pub async fn init( + config: &GlobalConfig, + name: &str, + abort_signal: AbortSignal, + ) -> Result { + let definition_path = Config::agent_definition_file(name)?; + let functions_path = Config::agent_functions_file(name)?; + let rag_path = Config::agent_rag_file(name)?; + let embeddings_dir = Config::agent_embeddings_dir(name)?; + let definition = AgentDefinition::load(&definition_path)?; + let functions = if functions_path.exists() { + Functions::init(&functions_path)? + } else { + Functions::default() + }; + let agent_config = config + .read() + .agents + .iter() + .find(|v| v.name == name) + .cloned() + .unwrap_or_else(|| AgentConfig::new(name)); + let model = { + let config = config.read(); + match agent_config.model_id.as_ref() { + Some(model_id) => Model::retrieve_chat(&config, model_id)?, + 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 agent 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 + }; + + Ok(Self { + name: name.to_string(), + config: agent_config, + definition, + functions, + rag, + model, + }) + } + + pub fn export(&self) -> Result { + let mut value = serde_json::json!(self); + value["functions_dir"] = Config::agent_source_dir(&self.name)? + .display() + .to_string() + .into(); + value["config_dir"] = Config::agent_config_dir(&self.name)? + .display() + .to_string() + .into(); + let data = serde_yaml::to_string(&value)?; + Ok(data) + } + + pub fn banner(&self) -> String { + self.definition.banner() + } + + pub fn name(&self) -> &str { + &self.name + } + + pub fn config(&self) -> &AgentConfig { + &self.config + } + + pub fn functions(&self) -> &Functions { + &self.functions + } + + pub fn definition(&self) -> &AgentDefinition { + &self.definition + } + + pub fn rag(&self) -> Option> { + self.rag.clone() + } + + pub fn conversation_staters(&self) -> &[String] { + &self.definition.conversation_starters + } +} + +impl RoleLike for Agent { + fn to_role(&self) -> Role { + let mut role = Role::new("", &self.definition.instructions); + role.sync(self); + role + } + + fn model(&self) -> &Model { + &self.model + } + + fn model_mut(&mut self) -> &mut Model { + &mut self.model + } + + fn temperature(&self) -> Option { + self.config.temperature + } + + fn top_p(&self) -> Option { + self.config.top_p + } + + fn functions_filter(&self) -> Option { + if self.functions.is_empty() { + None + } else { + Some(SELECTED_ALL_FUNCTIONS.into()) + } + } + + fn set_model(&mut self, model: &Model) { + self.config.model_id = Some(model.id()); + self.model = model.clone(); + } + + fn set_temperature(&mut self, value: Option) { + self.config.temperature = value; + } + + fn set_top_p(&mut self, value: Option) { + self.config.top_p = value; + } + + fn set_functions_filter(&mut self, _value: Option) {} +} + +#[derive(Debug, Clone, Default, Deserialize, Serialize)] +pub struct AgentConfig { + pub name: String, + #[serde(rename(serialize = "model", deserialize = "model"))] + pub model_id: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub temperature: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub top_p: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub dangerously_functions_filter: Option, +} + +impl AgentConfig { + pub fn new(name: &str) -> Self { + Self { + name: name.to_string(), + ..Default::default() + } + } +} + +#[derive(Debug, Clone, Default, Deserialize, Serialize)] +pub struct AgentDefinition { + pub name: String, + #[serde(default)] + pub description: String, + #[serde(default)] + pub version: String, + pub instructions: String, + #[serde(default)] + pub conversation_starters: Vec, +} + +impl AgentDefinition { + pub fn load(path: &Path) -> Result { + let contents = read_to_string(path) + .with_context(|| format!("Failed to read agent index file at '{}'", path.display()))?; + let definition: Self = serde_yaml::from_str(&contents) + .with_context(|| format!("Failed to load agent at '{}'", path.display()))?; + Ok(definition) + } + + fn banner(&self) -> String { + let AgentDefinition { + name, + description, + version, + conversation_starters, + .. + } = self; + let starters = if conversation_starters.is_empty() { + String::new() + } else { + let starters = conversation_starters + .iter() + .map(|v| format!("- {v}")) + .collect::>() + .join("\n"); + format!( + r#" + +## Conversation Starters +{starters}"# + ) + }; + format!( + r#"# {name} {version} +{description}{starters}"# + ) + } +} + +pub fn list_agents() -> Vec { + list_agents_impl().unwrap_or_default() +} + +fn list_agents_impl() -> Result> { + let base_dir = Config::functions_dir()?; + let contents = read_to_string(base_dir.join("agents.txt"))?; + let agents = contents + .split('\n') + .filter_map(|line| { + let line = line.trim(); + if line.is_empty() { + None + } else { + Some(line.to_string()) + } + }) + .collect(); + Ok(agents) +} diff --git a/src/config/bot.rs b/src/config/bot.rs deleted file mode 100644 index 7177f92..0000000 --- a/src/config/bot.rs +++ /dev/null @@ -1,260 +0,0 @@ -use super::*; - -use crate::{ - client::Model, - function::{Functions, FunctionsFilter, SELECTED_ALL_FUNCTIONS}, -}; - -use anyhow::{Context, Result}; -use std::{fs::read_to_string, path::Path}; - -use serde::{Deserialize, Serialize}; - -#[derive(Debug, Clone, Serialize)] -pub struct Bot { - name: String, - config: BotConfig, - definition: BotDefinition, - #[serde(skip)] - functions: Functions, - #[serde(skip)] - rag: Option>, - #[serde(skip)] - model: Model, -} - -impl Bot { - pub async fn init( - config: &GlobalConfig, - name: &str, - abort_signal: AbortSignal, - ) -> Result { - let definition_path = Config::bot_definition_file(name)?; - let functions_path = Config::bot_functions_file(name)?; - let rag_path = Config::bot_rag_file(name)?; - let embeddings_dir = Config::bot_embeddings_dir(name)?; - let definition = BotDefinition::load(&definition_path)?; - let functions = if functions_path.exists() { - Functions::init(&functions_path)? - } else { - Functions::default() - }; - let bot_config = config - .read() - .bots - .iter() - .find(|v| v.name == name) - .cloned() - .unwrap_or_else(|| BotConfig::new(name)); - let model = { - let config = config.read(); - match bot_config.model_id.as_ref() { - Some(model_id) => Model::retrieve_chat(&config, model_id)?, - 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 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 - }; - - Ok(Self { - name: name.to_string(), - config: bot_config, - definition, - functions, - rag, - model, - }) - } - - pub fn export(&self) -> Result { - let mut value = serde_json::json!(self); - value["functions_dir"] = Config::bot_source_dir(&self.name)? - .display() - .to_string() - .into(); - value["config_dir"] = Config::bot_config_dir(&self.name)? - .display() - .to_string() - .into(); - let data = serde_yaml::to_string(&value)?; - Ok(data) - } - - pub fn banner(&self) -> String { - self.definition.banner() - } - - pub fn name(&self) -> &str { - &self.name - } - - pub fn config(&self) -> &BotConfig { - &self.config - } - - pub fn functions(&self) -> &Functions { - &self.functions - } - - pub fn definition(&self) -> &BotDefinition { - &self.definition - } - - pub fn rag(&self) -> Option> { - self.rag.clone() - } - - pub fn conversation_staters(&self) -> &[String] { - &self.definition.conversation_starters - } -} - -impl RoleLike for Bot { - fn to_role(&self) -> Role { - let mut role = Role::new("", &self.definition.instructions); - role.sync(self); - role - } - - fn model(&self) -> &Model { - &self.model - } - - fn model_mut(&mut self) -> &mut Model { - &mut self.model - } - - fn temperature(&self) -> Option { - self.config.temperature - } - - fn top_p(&self) -> Option { - self.config.top_p - } - - fn functions_filter(&self) -> Option { - if self.functions.is_empty() { - None - } else { - Some(SELECTED_ALL_FUNCTIONS.into()) - } - } - - fn set_model(&mut self, model: &Model) { - self.config.model_id = Some(model.id()); - self.model = model.clone(); - } - - fn set_temperature(&mut self, value: Option) { - self.config.temperature = value; - } - - fn set_top_p(&mut self, value: Option) { - self.config.top_p = value; - } - - fn set_functions_filter(&mut self, _value: Option) {} -} - -#[derive(Debug, Clone, Default, Deserialize, Serialize)] -pub struct BotConfig { - pub name: String, - #[serde(rename(serialize = "model", deserialize = "model"))] - pub model_id: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub temperature: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub top_p: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub dangerously_functions_filter: Option, -} - -impl BotConfig { - pub fn new(name: &str) -> Self { - Self { - name: name.to_string(), - ..Default::default() - } - } -} - -#[derive(Debug, Clone, Default, Deserialize, Serialize)] -pub struct BotDefinition { - pub name: String, - #[serde(default)] - pub description: String, - #[serde(default)] - pub version: String, - pub instructions: String, - #[serde(default)] - pub conversation_starters: Vec, -} - -impl BotDefinition { - pub fn load(path: &Path) -> Result { - let contents = read_to_string(path) - .with_context(|| format!("Failed to read bot index file at '{}'", path.display()))?; - let definition: Self = serde_yaml::from_str(&contents) - .with_context(|| format!("Failed to load bot at '{}'", path.display()))?; - Ok(definition) - } - - fn banner(&self) -> String { - let BotDefinition { - name, - description, - version, - conversation_starters, - .. - } = self; - let starters = if conversation_starters.is_empty() { - String::new() - } else { - let starters = conversation_starters - .iter() - .map(|v| format!("- {v}")) - .collect::>() - .join("\n"); - format!( - r#" - -## Conversation Starters -{starters}"# - ) - }; - format!( - r#"# {name} {version} -{description}{starters}"# - ) - } -} - -pub fn list_bots() -> Vec { - list_bots_impl().unwrap_or_default() -} - -fn list_bots_impl() -> Result> { - let base_dir = Config::functions_dir()?; - let contents = read_to_string(base_dir.join("bots.txt"))?; - let bots = contents - .split('\n') - .filter_map(|line| { - let line = line.trim(); - if line.is_empty() { - None - } else { - Some(line.to_string()) - } - }) - .collect(); - Ok(bots) -} diff --git a/src/config/input.rs b/src/config/input.rs index b9b1746..b0b0bd9 100644 --- a/src/config/input.rs +++ b/src/config/input.rs @@ -38,12 +38,12 @@ pub struct Input { rag_name: Option, role: Role, with_session: bool, - with_bot: bool, + with_agent: bool, } impl Input { pub fn from_str(config: &GlobalConfig, text: &str, role: Option) -> Self { - let (role, with_session, with_bot) = resolve_role(&config.read(), role); + let (role, with_session, with_agent) = resolve_role(&config.read(), role); Self { config: config.clone(), text: text.to_string(), @@ -56,7 +56,7 @@ impl Input { rag_name: None, role, with_session, - with_bot, + with_agent, } } @@ -102,7 +102,7 @@ impl Input { } } - let (role, with_session, with_bot) = resolve_role(&config.read(), role); + let (role, with_session, with_agent) = resolve_role(&config.read(), role); Ok(Self { config: config.clone(), text: texts.join("\n"), @@ -115,7 +115,7 @@ impl Input { rag_name: None, role, with_session, - with_bot, + with_agent, }) } @@ -289,8 +289,8 @@ impl Input { } } - pub fn with_bot(&self) -> bool { - self.with_bot + pub fn with_agent(&self) -> bool { + self.with_agent } pub fn summary(&self) -> String { @@ -361,7 +361,7 @@ fn resolve_role(config: &Config, role: Option) -> (Role, bool, bool) { None => ( config.extract_role(), config.session.is_some(), - config.bot.is_some(), + config.agent.is_some(), ), } } diff --git a/src/config/mod.rs b/src/config/mod.rs index 97a6017..9cd69c5 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,9 +1,9 @@ -mod bot; +mod agent; mod input; mod role; mod session; -pub use self::bot::{list_bots, Bot, BotConfig}; +pub use self::agent::{list_agents, Agent, AgentConfig}; pub use self::input::Input; pub use self::role::{Role, RoleLike, CODE_ROLE, EXPLAIN_SHELL_ROLE, SHELL_ROLE}; use self::session::Session; @@ -46,7 +46,7 @@ const RAGS_DIR_NAME: &str = "rags"; const FUNCTIONS_DIR_NAME: &str = "functions"; const FUNCTIONS_FILE_NAME: &str = "functions.json"; const FUNCTIONS_BIN_DIR_NAME: &str = "bin"; -const BOTS_DIR_NAME: &str = "bots"; +const BOTS_DIR_NAME: &str = "agents"; const BOT_DEFINITION_FILE_NAME: &str = "index.yaml"; const BOT_EMBEDDINGS_DIR: &str = "embeddings"; const BOT_RAG_FILE_NAME: &str = "rag.bin"; @@ -75,7 +75,7 @@ And answer according to the language of the user's question. Given the context information, answer the query. Query: __INPUT__"#; -const LEFT_PROMPT: &str = "{color.green}{?session {?bot {bot}#}{session}{?role /}}{!session {?bot {bot}}}{role}{?rag @{rag}}{color.cyan}{?session )}{!session >}{color.reset} "; +const LEFT_PROMPT: &str = "{color.green}{?session {?agent {agent}#}{session}{?role /}}{!session {?agent {agent}}}{role}{?rag @{rag}}{color.cyan}{?session )}{!session >}{color.reset} "; const RIGHT_PROMPT: &str = "{color.purple}{?session {?consume_tokens {consume_tokens}({consume_percent}%)}{!consume_tokens {consume_tokens}}}{color.reset}"; #[derive(Debug, Clone, Deserialize)] @@ -99,8 +99,8 @@ pub struct Config { pub buffer_editor: Option, pub function_calling: bool, pub dangerously_functions_filter: Option, - pub bot_prelude: Option, - pub bots: Vec, + pub agent_prelude: Option, + pub agents: Vec, pub rag_embedding_model: Option, pub rag_rerank_model: Option, pub rag_chunk_size: Option, @@ -125,7 +125,7 @@ pub struct Config { #[serde(skip)] pub rag: Option>, #[serde(skip)] - pub bot: Option, + pub agent: Option, #[serde(skip)] pub model: Model, #[serde(skip)] @@ -155,8 +155,8 @@ impl Default for Config { buffer_editor: None, function_calling: false, dangerously_functions_filter: None, - bot_prelude: None, - bots: vec![], + agent_prelude: None, + agents: vec![], rag_embedding_model: None, rag_rerank_model: None, rag_chunk_size: None, @@ -176,7 +176,7 @@ impl Default for Config { role: None, session: None, rag: None, - bot: None, + agent: None, model: Default::default(), functions: Default::default(), working_mode: WorkingMode::Command, @@ -250,22 +250,22 @@ impl Config { } pub fn messages_file(&self) -> Result { - match &self.bot { + match &self.agent { None => match env::var(get_env_name("messages_file")) { Ok(value) => Ok(PathBuf::from(value)), Err(_) => Self::local_path(MESSAGES_FILE_NAME), }, - Some(bot) => Ok(Self::bot_config_dir(bot.name())?.join(MESSAGES_FILE_NAME)), + Some(agent) => Ok(Self::agent_config_dir(agent.name())?.join(MESSAGES_FILE_NAME)), } } pub fn sessions_dir(&self) -> Result { - match &self.bot { + match &self.agent { None => match env::var(get_env_name("sessions_dir")) { Ok(value) => Ok(PathBuf::from(value)), Err(_) => Self::local_path(SESSIONS_DIR_NAME), }, - Some(bot) => Ok(Self::bot_config_dir(bot.name())?.join(SESSIONS_DIR_NAME)), + Some(agent) => Ok(Self::agent_config_dir(agent.name())?.join(SESSIONS_DIR_NAME)), } } @@ -296,7 +296,7 @@ impl Config { } pub fn rag_file(&self, name: &str) -> Result { - let path = if self.bot.is_none() { + let path = if self.agent.is_none() { Self::rags_dir()?.join(format!("{name}.bin")) } else { Self::rags_dir()? @@ -306,35 +306,35 @@ impl Config { Ok(path) } - pub fn bots_dir() -> Result { - match env::var(get_env_name("bots_dir")) { + pub fn agents_dir() -> Result { + match env::var(get_env_name("agents_dir")) { Ok(value) => Ok(PathBuf::from(value)), Err(_) => Self::local_path(BOTS_DIR_NAME), } } - pub fn bot_config_dir(name: &str) -> Result { - Ok(Self::bots_dir()?.join(name)) + pub fn agent_config_dir(name: &str) -> Result { + Ok(Self::agents_dir()?.join(name)) } - pub fn bot_rag_file(name: &str) -> Result { - Ok(Self::bot_config_dir(name)?.join(BOT_RAG_FILE_NAME)) + pub fn agent_rag_file(name: &str) -> Result { + Ok(Self::agent_config_dir(name)?.join(BOT_RAG_FILE_NAME)) } - pub fn bot_source_dir(name: &str) -> Result { + pub fn agent_source_dir(name: &str) -> Result { Ok(Self::functions_dir()?.join(BOTS_DIR_NAME).join(name)) } - pub fn bot_functions_file(name: &str) -> Result { - Ok(Self::bot_source_dir(name)?.join(FUNCTIONS_FILE_NAME)) + pub fn agent_functions_file(name: &str) -> Result { + Ok(Self::agent_source_dir(name)?.join(FUNCTIONS_FILE_NAME)) } - pub fn bot_definition_file(name: &str) -> Result { - Ok(Self::bot_source_dir(name)?.join(BOT_DEFINITION_FILE_NAME)) + pub fn agent_definition_file(name: &str) -> Result { + Ok(Self::agent_source_dir(name)?.join(BOT_DEFINITION_FILE_NAME)) } - pub fn bot_embeddings_dir(name: &str) -> Result { - Ok(Self::bot_source_dir(name)?.join(BOT_EMBEDDINGS_DIR)) + pub fn agent_embeddings_dir(name: &str) -> Result { + Ok(Self::agent_source_dir(name)?.join(BOT_EMBEDDINGS_DIR)) } pub fn state(&self) -> StateFlags { @@ -346,7 +346,7 @@ impl Config { flags |= StateFlags::SESSION; } } - if self.bot.is_some() { + if self.agent.is_some() { flags |= StateFlags::BOT; } if self.role.is_some() { @@ -361,8 +361,8 @@ impl Config { pub fn current_model(&self) -> &Model { if let Some(session) = self.session.as_ref() { session.model() - } else if let Some(bot) = self.bot.as_ref() { - bot.model() + } else if let Some(agent) = self.agent.as_ref() { + agent.model() } else if let Some(role) = self.role.as_ref() { role.model() } else { @@ -373,8 +373,8 @@ impl Config { pub fn role_like_mut(&mut self) -> Option<&mut dyn RoleLike> { if let Some(session) = self.session.as_mut() { Some(session) - } else if let Some(bot) = self.bot.as_mut() { - Some(bot) + } else if let Some(agent) = self.agent.as_mut() { + Some(agent) } else if let Some(role) = self.role.as_mut() { Some(role) } else { @@ -385,8 +385,8 @@ impl Config { pub fn extract_role(&self) -> Role { let mut role = if let Some(session) = self.session.as_ref() { session.to_role() - } else if let Some(bot) = self.bot.as_ref() { - bot.to_role() + } else if let Some(agent) = self.agent.as_ref() { + agent.to_role() } else if let Some(role) = self.role.as_ref() { role.clone() } else { @@ -404,8 +404,8 @@ impl Config { } pub fn info(&self) -> Result { - if let Some(bot) = &self.bot { - let output = bot.export()?; + if let Some(agent) = &self.agent { + let output = agent.export()?; if let Some(session) = &self.session { let session = session .export()? @@ -466,7 +466,7 @@ impl Config { ("roles_file", display_path(&Self::roles_file()?)), ("functions_dir", display_path(&Self::functions_dir()?)), ("rags_dir", display_path(&Self::rags_dir()?)), - ("bots_dir", display_path(&Self::bots_dir()?)), + ("agents_dir", display_path(&Self::agents_dir()?)), ("sessions_dir", display_path(&self.sessions_dir()?)), ("messages_file", display_path(&self.messages_file()?)), ]; @@ -613,8 +613,8 @@ impl Config { } pub fn use_role_obj(&mut self, role: Role) -> Result<()> { - if self.bot.is_some() { - bail!("Cannot perform this action because you are using a bot") + if self.agent.is_some() { + bail!("Cannot perform this action because you are using a agent") } if let Some(session) = self.session.as_mut() { session.guard_empty()?; @@ -696,7 +696,7 @@ impl Config { if let Some(session) = session.as_mut() { if session.is_empty() { if let Some((input, output)) = &self.last_message { - if self.bot.is_some() == input.with_bot() { + if self.agent.is_some() == input.with_agent() { let ans = Confirm::new( "Start a session that incorporates the last question and answer?", ) @@ -840,8 +840,8 @@ impl Config { rag: Option<&str>, abort_signal: AbortSignal, ) -> Result<()> { - if config.read().bot.is_some() { - bail!("Cannot perform this action because you are using a bot") + if config.read().agent.is_some() { + bail!("Cannot perform this action because you are using a agent") } let rag = match rag { None => { @@ -911,49 +911,49 @@ impl Config { .replace("__INPUT__", text) } - pub async fn use_bot( + pub async fn use_agent( config: &GlobalConfig, name: &str, session: Option<&str>, abort_signal: AbortSignal, ) -> Result<()> { if !config.read().function_calling { - bail!("Before using the bot, please configure function calling first."); + bail!("Before using the agent, please configure function calling first."); } - if config.read().bot.is_some() { - bail!("Already in a bot, please run '.exit bot' first to exit the current bot."); + if config.read().agent.is_some() { + bail!("Already in a agent, please run '.exit agent' first to exit the current agent."); } - let bot = Bot::init(config, name, abort_signal).await?; - config.write().rag = bot.rag(); - config.write().bot = Some(bot); + let agent = Agent::init(config, name, abort_signal).await?; + config.write().rag = agent.rag(); + config.write().agent = Some(agent); let session = session .map(|v| v.to_string()) - .or_else(|| config.read().bot_prelude.clone()); + .or_else(|| config.read().agent_prelude.clone()); if let Some(session) = session { config.write().use_session(Some(&session))?; } Ok(()) } - pub fn bot_info(&self) -> Result { - if let Some(bot) = &self.bot { - bot.export() + pub fn agent_info(&self) -> Result { + if let Some(agent) = &self.agent { + agent.export() } else { - bail!("No bot") + bail!("No agent") } } - pub fn bot_banner(&self) -> Result { - if let Some(bot) = &self.bot { - Ok(bot.banner()) + pub fn agent_banner(&self) -> Result { + if let Some(agent) = &self.agent { + Ok(agent.banner()) } else { - bail!("No bot") + bail!("No agent") } } - pub fn exit_bot(&mut self) -> Result<()> { + pub fn exit_agent(&mut self) -> Result<()> { self.exit_session()?; - if self.bot.take().is_some() { + if self.agent.take().is_some() { self.rag.take(); self.last_message = None; } @@ -995,8 +995,8 @@ impl Config { if self.function_calling { let filter = role.functions_filter(); if let Some(filter) = filter { - functions = match &self.bot { - Some(bot) => bot.functions().select(&filter), + functions = match &self.agent { + Some(agent) => agent.functions().select(&filter), None => self.functions.select(&filter), }; if !model.supports_function_calling() { @@ -1014,8 +1014,8 @@ impl Config { if get_env_bool("no_dangerously_functions") { return false; } - let dangerously_functions_filter = match &self.bot { - Some(bot) => bot.config().dangerously_functions_filter.as_ref(), + let dangerously_functions_filter = match &self.agent { + Some(agent) => agent.config().dangerously_functions_filter.as_ref(), None => self.dangerously_functions_filter.as_ref(), }; match dangerously_functions_filter { @@ -1054,9 +1054,9 @@ impl Config { .map(|v| (v, None)) .collect(), ".rag" => self.list_rags().into_iter().map(|v| (v, None)).collect(), - ".bot" => list_bots().into_iter().map(|v| (v, None)).collect(), - ".starter" => match &self.bot { - Some(bot) => bot + ".agent" => list_agents().into_iter().map(|v| (v, None)).collect(), + ".starter" => match &self.agent { + Some(agent) => agent .conversation_staters() .iter() .map(|v| (v.clone(), None)) @@ -1212,8 +1212,8 @@ impl Config { if let Some(rag) = &self.rag { output.insert("rag", rag.name().to_string()); } - if let Some(bot) = &self.bot { - output.insert("bot", bot.name().to_string()); + if let Some(agent) = &self.agent { + output.insert("agent", agent.name().to_string()); } if self.highlight { @@ -1277,7 +1277,7 @@ impl Config { let timestamp = now(); let summary = input.summary(); let input_markdown = input.render(); - let scope = if self.bot.is_none() { + let scope = if self.agent.is_none() { let role_name = if input.role().is_derived() { None } else { diff --git a/src/config/session.rs b/src/config/session.rs index 726249c..3330f22 100644 --- a/src/config/session.rs +++ b/src/config/session.rs @@ -77,10 +77,10 @@ impl Session { session.name = name.to_string(); session.path = Some(path.display().to_string()); - if let Some(bot) = &config.bot { + if let Some(agent) = &config.agent { session .role_prompt - .clone_from(&bot.definition().instructions); + .clone_from(&agent.definition().instructions); } Ok(session) -- cgit v1.2.3