From 4161eaa6c3ea0b6a10bd70d36f47bbbae0ae209c Mon Sep 17 00:00:00 2001 From: sigoden Date: Fri, 10 Mar 2023 07:02:44 +0800 Subject: [PATCH] fix: cli specify role is not applied when conversation_first set true (#57) close #56 --- src/config/mod.rs | 10 +++++++--- src/main.rs | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index 644d162..ebbd909 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -82,13 +82,17 @@ impl Config { let mut config: Config = serde_yaml::from_str(&content) .with_context(|| format!("Invalid config at {}", config_path.display()))?; config.load_roles()?; - if config.conversation_first { - config.start_conversation()?; - } Ok(config) } + pub fn on_repl(&mut self) -> Result<()> { + if self.conversation_first { + self.start_conversation()?; + } + Ok(()) + } + pub fn find_role(&self, name: &str) -> Option { self.roles.iter().find(|v| v.name == name).cloned() } diff --git a/src/main.rs b/src/main.rs index b940053..b198d14 100644 --- a/src/main.rs +++ b/src/main.rs @@ -98,6 +98,7 @@ fn start_directive( fn start_interactive(client: ChatGptClient, config: SharedConfig) -> Result<()> { cl100k_base_singleton(); + config.lock().on_repl()?; let mut repl = Repl::init(config.clone())?; repl.run(client, config) }