summaryrefslogtreecommitdiffstats
path: root/src/repl/handler.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2023-10-26 19:19:22 +0800
committersigoden <sigoden@gmail.com>2023-10-26 19:19:22 +0800
commit66fd547c0fac30d98565a92d93824237a4813669 (patch)
tree332ca0d0927739de69ff4e7b8ac589f4f001f9f1 /src/repl/handler.rs
parent7d8564cafb45afc4bccb666a310615b164800a9a (diff)
downloadaichat-66fd547c0fac30d98565a92d93824237a4813669.tar.gz
refactor: improve code quanity
remove tokio::runtime::Runtime from client
Diffstat (limited to 'src/repl/handler.rs')
-rw-r--r--src/repl/handler.rs13
1 files changed, 4 insertions, 9 deletions
diff --git a/src/repl/handler.rs b/src/repl/handler.rs
index 53cdd98..e512cb5 100644
--- a/src/repl/handler.rs
+++ b/src/repl/handler.rs
@@ -1,4 +1,4 @@
-use crate::client::Client;
+use crate::client::init_client;
use crate::config::SharedConfig;
use crate::print_now;
use crate::render::render_stream;
@@ -26,7 +26,6 @@ pub enum ReplCmd {
#[allow(clippy::module_name_repetitions)]
pub struct ReplCmdHandler {
- client: Box<dyn Client>,
config: SharedConfig,
reply: RefCell<String>,
abort: SharedAbortSignal,
@@ -34,14 +33,9 @@ pub struct ReplCmdHandler {
impl ReplCmdHandler {
#[allow(clippy::unnecessary_wraps)]
- pub fn init(
- client: Box<dyn Client>,
- config: SharedConfig,
- abort: SharedAbortSignal,
- ) -> Result<Self> {
+ pub fn init(config: SharedConfig, abort: SharedAbortSignal) -> Result<Self> {
let reply = RefCell::new(String::new());
Ok(Self {
- client,
config,
reply,
abort,
@@ -57,9 +51,10 @@ impl ReplCmdHandler {
}
self.config.read().maybe_print_send_tokens(&input);
let wg = WaitGroup::new();
+ let client = init_client(self.config.clone())?;
let ret = render_stream(
&input,
- self.client.as_ref(),
+ client.as_ref(),
&self.config,
true,
self.abort.clone(),