summaryrefslogtreecommitdiffstats
path: root/src/repl/handler.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2023-03-09 10:39:28 +0800
committerGitHub <noreply@github.com>2023-03-09 10:39:28 +0800
commita62e461e38482ade15c6826e656393d5f867488a (patch)
treebb8c0d76e6863e761f273059744bee722c0ab260 /src/repl/handler.rs
parenta7f2da156c0692121e35dbe20bdacc76baadd5c4 (diff)
downloadaichat-a62e461e38482ade15c6826e656393d5f867488a.tar.gz
feat: support conversation (#48)
Diffstat (limited to 'src/repl/handler.rs')
-rw-r--r--src/repl/handler.rs28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/repl/handler.rs b/src/repl/handler.rs
index 1b2eb20..979fc5e 100644
--- a/src/repl/handler.rs
+++ b/src/repl/handler.rs
@@ -16,7 +16,9 @@ pub enum ReplCmd {
UpdateConfig(String),
Prompt(String),
ClearRole,
- Info,
+ ViewInfo,
+ StartConversation,
+ EndConversatoin,
}
pub struct ReplCmdHandler {
@@ -61,10 +63,11 @@ impl ReplCmdHandler {
wg.wait();
let buffer = ret?;
self.config.lock().save_message(&input, &buffer)?;
+ self.config.lock().record_conversation(&input, &buffer)?;
*self.reply.borrow_mut() = buffer;
}
ReplCmd::SetRole(name) => {
- let output = self.config.lock().change_role(&name);
+ let output = self.config.lock().change_role(&name)?;
print_now!("{}\n\n", output.trim_end());
}
ReplCmd::ClearRole => {
@@ -72,21 +75,24 @@ impl ReplCmdHandler {
print_now!("\n");
}
ReplCmd::Prompt(prompt) => {
- self.config.lock().create_temp_role(&prompt);
+ self.config.lock().create_temp_role(&prompt)?;
print_now!("\n");
}
- ReplCmd::Info => {
+ ReplCmd::ViewInfo => {
let output = self.config.lock().info()?;
print_now!("{}\n\n", output.trim_end());
}
ReplCmd::UpdateConfig(input) => {
- let output = self.config.lock().update(&input)?;
- let output = output.trim();
- if output.is_empty() {
- print_now!("\n");
- } else {
- print_now!("{}\n\n", output);
- }
+ self.config.lock().update(&input)?;
+ print_now!("\n");
+ }
+ ReplCmd::StartConversation => {
+ self.config.lock().start_conversation()?;
+ print_now!("\n");
+ }
+ ReplCmd::EndConversatoin => {
+ self.config.lock().end_conversation();
+ print_now!("\n");
}
}
Ok(())