diff options
| author | sigoden <sigoden@gmail.com> | 2024-10-22 07:38:45 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-22 07:38:45 +0800 |
| commit | c7d85c624b1bd4ab8118ff80d692ee2b40669537 (patch) | |
| tree | 90f1c957645add0f6eb33c9664257407a3d41a57 /src/config | |
| parent | a165fd19e752e3a998dedfe640e9ec838c2737c6 (diff) | |
| download | aichat-c7d85c624b1bd4ab8118ff80d692ee2b40669537.tar.gz | |
refactor: several improvements (#943)
- rename agents_config_dir to agents_data_dir
- do not save empty role name while saving the session
- rename delete keys (roles/sessions/rags/agents => role/session/rag/agent-data)
- improve some printing messages
Diffstat (limited to 'src/config')
| -rw-r--r-- | src/config/agent.rs | 4 | ||||
| -rw-r--r-- | src/config/mod.rs | 32 | ||||
| -rw-r--r-- | src/config/role.rs | 2 | ||||
| -rw-r--r-- | src/config/session.rs | 4 |
4 files changed, 21 insertions, 21 deletions
diff --git a/src/config/agent.rs b/src/config/agent.rs index 9dcf62b..d4af67a 100644 --- a/src/config/agent.rs +++ b/src/config/agent.rs @@ -102,7 +102,7 @@ impl Agent { format!("Failed to save agent config to '{}'", config_path.display()) })?; - println!("✨ Saved agent config to '{}'", config_path.display()); + println!("✨ Saved agent config to '{}'.", config_path.display()); Ok(()) } @@ -114,7 +114,7 @@ impl Agent { .display() .to_string() .into(); - value["config_dir"] = Config::agent_config_dir(&self.name)? + value["data_dir"] = Config::agent_data_dir(&self.name)? .display() .to_string() .into(); diff --git a/src/config/mod.rs b/src/config/mod.rs index 0f3f89e..142f115 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -300,7 +300,7 @@ impl Config { Ok(value) => Ok(PathBuf::from(value)), Err(_) => Self::local_path(MESSAGES_FILE_NAME), }, - Some(agent) => Ok(Self::agent_config_dir(agent.name())?.join(MESSAGES_FILE_NAME)), + Some(agent) => Ok(Self::agent_data_dir(agent.name())?.join(MESSAGES_FILE_NAME)), } } @@ -310,7 +310,7 @@ impl Config { Ok(value) => Ok(PathBuf::from(value)), Err(_) => Self::local_path(SESSIONS_DIR_NAME), }, - Some(agent) => Ok(Self::agent_config_dir(agent.name())?.join(SESSIONS_DIR_NAME)), + Some(agent) => Ok(Self::agent_data_dir(agent.name())?.join(SESSIONS_DIR_NAME)), } } @@ -348,27 +348,27 @@ impl Config { Ok(path) } - pub fn agents_config_dir() -> Result<PathBuf> { + pub fn agents_data_dir() -> Result<PathBuf> { Self::local_path(AGENTS_DIR_NAME) } - pub fn agent_config_dir(name: &str) -> Result<PathBuf> { - match env::var(format!("{}_CONFIG_DIR", normalize_env_name(name))) { + pub fn agent_data_dir(name: &str) -> Result<PathBuf> { + match env::var(format!("{}_DATA_DIR", normalize_env_name(name))) { Ok(value) => Ok(PathBuf::from(value)), - Err(_) => Ok(Self::agents_config_dir()?.join(name)), + Err(_) => Ok(Self::agents_data_dir()?.join(name)), } } pub fn agent_config_file(name: &str) -> Result<PathBuf> { - Ok(Self::agent_config_dir(name)?.join(CONFIG_FILE_NAME)) + Ok(Self::agent_data_dir(name)?.join(CONFIG_FILE_NAME)) } pub fn agent_rag_file(agent_name: &str, rag_name: &str) -> Result<PathBuf> { - Ok(Self::agent_config_dir(agent_name)?.join(format!("{rag_name}.yaml"))) + Ok(Self::agent_data_dir(agent_name)?.join(format!("{rag_name}.yaml"))) } pub fn agent_variables_file(name: &str) -> Result<PathBuf> { - Ok(Self::agent_config_dir(name)?.join(AGENT_VARIABLES_FILE_NAME)) + Ok(Self::agent_data_dir(name)?.join(AGENT_VARIABLES_FILE_NAME)) } pub fn agents_functions_dir() -> Result<PathBuf> { @@ -649,10 +649,10 @@ impl Config { pub fn delete(config: &GlobalConfig, kind: &str) -> Result<()> { let (dir, file_ext) = match kind { - "roles" => (Self::roles_dir()?, Some(".md")), - "sessions" => (config.read().sessions_dir()?, Some(".yaml")), - "rags" => (Self::rags_dir()?, Some(".yaml")), - "agents" => (Self::agents_config_dir()?, None), + "role" => (Self::roles_dir()?, Some(".md")), + "session" => (config.read().sessions_dir()?, Some(".yaml")), + "rag" => (Self::rags_dir()?, Some(".yaml")), + "agent-data" => (Self::agents_data_dir()?, None), _ => bail!("Unknown kind '{kind}'"), }; let names = match read_dir(&dir) { @@ -711,7 +711,7 @@ impl Config { } } } - println!("✨ Successfully deleted {kind}"); + println!("✨ Successfully deleted {kind}."); Ok(()) } @@ -1551,7 +1551,7 @@ impl Config { .map(|v| (format!("{v} "), None)) .collect() } - ".delete" => map_completion_values(vec!["roles", "sessions", "rags", "agents"]), + ".delete" => map_completion_values(vec!["role", "session", "rag", "agent-data"]), _ => vec![], }; filter = args[0] @@ -2122,7 +2122,7 @@ fn create_config_file(config_path: &Path) -> Result<()> { std::fs::set_permissions(config_path, perms)?; } - println!("✨ Saved config file to '{}'\n", config_path.display()); + println!("✨ Saved config file to '{}'.\n", config_path.display()); Ok(()) } diff --git a/src/config/role.rs b/src/config/role.rs index 9b9f46d..8c56f0c 100644 --- a/src/config/role.rs +++ b/src/config/role.rs @@ -167,7 +167,7 @@ impl Role { })?; if is_repl { - println!("✨ Saved role to '{}'", role_path.display()); + println!("✨ Saved role to '{}'.", role_path.display()); } if role_name != self.name { diff --git a/src/config/session.rs b/src/config/session.rs index 2ad517c..717188b 100644 --- a/src/config/session.rs +++ b/src/config/session.rs @@ -240,7 +240,7 @@ impl Session { self.top_p = role.top_p(); self.use_tools = role.use_tools(); self.model = role.model().clone(); - self.role_name = Some(role.name().to_string()); + self.role_name = convert_option_string(role.name()); self.role_prompt = role.prompt().to_string(); self.dirty = true; } @@ -349,7 +349,7 @@ impl Session { })?; if is_repl { - println!("✨ Saved session to '{}'", session_path.display()); + println!("✨ Saved session to '{}'.", session_path.display()); } if self.name() != session_name { |
