diff --git a/src/client/common.rs b/src/client/common.rs index 7959b46f..336450f3 100644 --- a/src/client/common.rs +++ b/src/client/common.rs @@ -52,7 +52,7 @@ macro_rules! register_client { impl $client { pub const NAME: &str = $name; - pub fn init(global_config: $crate::config::GlobalConfig) -> Option> { + pub fn init(global_config: &$crate::config::GlobalConfig) -> Option> { let model = global_config.read().model.clone(); let config = { if let ClientConfig::$config(c) = &global_config.read().clients[model.client_index] { @@ -62,7 +62,7 @@ macro_rules! register_client { } }; Some(Box::new(Self { - global_config, + global_config: global_config.clone(), config, model, })) @@ -75,9 +75,9 @@ macro_rules! register_client { )+ - pub fn init_client(config: $crate::config::GlobalConfig) -> anyhow::Result> { + pub fn init_client(config: &$crate::config::GlobalConfig) -> anyhow::Result> { None - $(.or_else(|| $client::init(config.clone())))+ + $(.or_else(|| $client::init(config)))+ .ok_or_else(|| { let model = config.read().model.clone(); anyhow::anyhow!( diff --git a/src/main.rs b/src/main.rs index 04f873f2..a40745fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,11 +78,11 @@ fn main() -> Result<()> { exit(0); } let no_stream = cli.no_stream; - let client = init_client(config.clone())?; + let client = init_client(&config)?; if stdin().is_terminal() { match text { Some(text) => start_directive(client.as_ref(), &config, &text, no_stream), - None => start_interactive(config), + None => start_interactive(&config), } } else { let mut input = String::new(); @@ -128,8 +128,8 @@ fn start_directive( config.write().save_message(input, &output) } -fn start_interactive(config: GlobalConfig) -> Result<()> { +fn start_interactive(config: &GlobalConfig) -> Result<()> { cl100k_base_singleton(); - let mut repl: Repl = Repl::init(config.clone())?; + let mut repl: Repl = Repl::init(config)?; repl.run() } diff --git a/src/repl/mod.rs b/src/repl/mod.rs index 818a86ac..4f510203 100644 --- a/src/repl/mod.rs +++ b/src/repl/mod.rs @@ -60,17 +60,17 @@ pub struct Repl { } impl Repl { - pub fn init(config: GlobalConfig) -> Result { - let editor = Self::create_editor(&config)?; + pub fn init(config: &GlobalConfig) -> Result { + let editor = Self::create_editor(config)?; - let prompt = ReplPrompt::new(config.clone()); + let prompt = ReplPrompt::new(config); let abort = create_abort_signal(); let clipboard = Clipboard::new().map(RefCell::new); Ok(Self { - config, + config: config.clone(), editor, prompt, clipboard, @@ -228,7 +228,7 @@ impl Repl { } self.config.read().maybe_print_send_tokens(input); let wg = WaitGroup::new(); - let client = init_client(self.config.clone())?; + let client = init_client(&self.config)?; let ret = render_stream( input, client.as_ref(), diff --git a/src/repl/prompt.rs b/src/repl/prompt.rs index b4c90996..827f84da 100644 --- a/src/repl/prompt.rs +++ b/src/repl/prompt.rs @@ -15,8 +15,10 @@ pub struct ReplPrompt { } impl ReplPrompt { - pub fn new(config: GlobalConfig) -> Self { - Self { config } + pub fn new(config: &GlobalConfig) -> Self { + Self { + config: config.clone(), + } } }