summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2023-10-30 13:36:08 +0800
committerGitHub <noreply@github.com>2023-10-30 13:36:08 +0800
commitba3cc4f15dd4b7457bbcacc64fcdbdbb0362d473 (patch)
tree0689264c52b226c9fe88b1fb6730715a74b5a2a0
parent2f9121e515150981ac061389656c33eea577c336 (diff)
downloadaichat-ba3cc4f15dd4b7457bbcacc64fcdbdbb0362d473.tar.gz
feat: deprecate history file (#179)
-rw-r--r--README.md76
-rw-r--r--src/config/mod.rs5
-rw-r--r--src/main.rs1
-rw-r--r--src/repl/init.rs22
-rw-r--r--src/repl/mod.rs19
-rw-r--r--src/term.rs32
6 files changed, 45 insertions, 110 deletions
diff --git a/README.md b/README.md
index 174e719..a6c4a7e 100644
--- a/README.md
+++ b/README.md
@@ -131,33 +131,12 @@ aichat has a powerful Chat REPL.
The Chat REPL supports:
-- Emacs keybinding
+- Emacs/Vi keybinding
- Command autocompletion
-- History search
-- Fish-style history autosuggestion hints
- Edit/paste multiline input
- Undo support
-### Multi-line input
-
-AIChat supports bracketed paste, so you can paste multi-lines text directly.
-
-AIChat also provides `.edit` command for multi-lines editing.
-
-```
-〉.edit convert json below to toml
-{
- "an": [
- "arbitrarily",
- "nested"
- ],
- "data": "structure"
-}
-```
-
-> Submit the multi-line text with `Ctrl+S`.
-
-### `.help` - Print help message
+### `.help` - print help message
```
〉.help
@@ -171,15 +150,13 @@ AIChat also provides `.edit` command for multi-lines editing.
.copy Copy the last output to the clipboard
.read Read the contents of a file and submit
.edit Multi-line editing (CTRL+S to finish)
-.history Print the REPL history
-.clear history Clear the REPL history
.help Print this help message
.exit Exit the REPL
Press Ctrl+C to abort readline, Ctrl+D to exit the REPL
```
-### `.info` - View current configuration information
+### `.info` - view current configuration information
```
〉.info
@@ -196,7 +173,27 @@ dry_run false
vi_keybindings true
```
-### `.set` - Modify the configuration temporarily
+### `.edit` - multiline editing
+
+AIChat supports bracketed paste, so you can paste multi-lines text directly.
+
+AIChat also provides `.edit` command for multi-lines editing.
+
+```
+〉.edit convert json below to toml
+{
+ "an": [
+ "arbitrarily",
+ "nested"
+ ],
+ "data": "structure"
+}
+```
+
+> Submit the multi-line text with `Ctrl+S`.
+
+
+### `.set` - modify the configuration temporarily
```
〉.set dry_run true
@@ -205,14 +202,17 @@ vi_keybindings true
〉.set temperature 1.2
```
-### `.model` - Choose a model
+
+### `.model` - choose a model
```
> .model openai:gpt-4
> .model localai:gpt4all-j
```
-### `.role` - Let the AI play a role
+> You can easily enter enter model name using autocomplete.
+
+### `.role` - let the AI play a role
Select a role:
@@ -239,7 +239,7 @@ emoji〉.clear role
Hello there! How can I assist you today?
```
-## Session - context-aware conversation
+## `.session` - context-aware conversation
By default, aichat behaves in a one-off request/response manner.
@@ -248,10 +248,10 @@ You should run aichat with `-s/--session` or use the `.session` command to start
```
〉.session
-temp)1 to 5, odd only 4089
+temp)1 to 5, odd only 4089
1, 3, 5
-temp)to 7 4070
+temp)to 7 4070
1, 3, 5, 7
temp).clear session
@@ -260,11 +260,13 @@ temp).clear session
```
```sh
-aichat --list-sessions # List sessions.
-aichat -s # Start with a new temp session.
-aichat -s temp # Reuses previous temp session.
-aichat -s rust # Reuses session named rust. If it does not exist, create a new session named rust.
-aichat -s rust --info # Show session details.
+aichat --list-sessions # List sessions.
+aichat -s # Start REPL with a new temp session
+aichat -s temp # Use temp session
+aichat -s temp --info # Show session details
+aichat -r shell -s # Create a session with a role
+aichat -m openai:gpt-4-32k -s # Create a session with a model
+aichat -s sh unzip a file # Run session in command mode
```
## License
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 4437833..695dad5 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -27,7 +27,6 @@ use std::{
const CONFIG_FILE_NAME: &str = "config.yaml";
const ROLES_FILE_NAME: &str = "roles.yaml";
-const HISTORY_FILE_NAME: &str = "history.txt";
const MESSAGES_FILE_NAME: &str = "messages.md";
const SESSIONS_DIR_NAME: &str = "sessions";
@@ -221,10 +220,6 @@ impl Config {
)
}
- pub fn history_file() -> Result<PathBuf> {
- Self::local_path(HISTORY_FILE_NAME)
- }
-
pub fn messages_file() -> Result<PathBuf> {
Self::local_path(MESSAGES_FILE_NAME)
}
diff --git a/src/main.rs b/src/main.rs
index a71a2b5..a7850b5 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,7 +3,6 @@ mod client;
mod config;
mod render;
mod repl;
-mod term;
#[macro_use]
mod utils;
diff --git a/src/repl/init.rs b/src/repl/init.rs
index 60fce00..420f596 100644
--- a/src/repl/init.rs
+++ b/src/repl/init.rs
@@ -2,13 +2,13 @@ use super::{
highlighter::ReplHighlighter, prompt::ReplPrompt, validator::ReplValidator, REPL_COMMANDS,
};
-use crate::config::{Config, SharedConfig};
+use crate::config::SharedConfig;
-use anyhow::{Context, Result};
+use anyhow::Result;
use reedline::{
default_emacs_keybindings, default_vi_insert_keybindings, default_vi_normal_keybindings,
- ColumnarMenu, DefaultCompleter, EditMode, Emacs, FileBackedHistory, KeyCode, KeyModifiers,
- Keybindings, Reedline, ReedlineEvent, ReedlineMenu, Vi,
+ ColumnarMenu, DefaultCompleter, EditMode, Emacs, KeyCode, KeyModifiers, Keybindings, Reedline,
+ ReedlineEvent, ReedlineMenu, Vi,
};
const MENU_NAME: &str = "completion_menu";
@@ -27,7 +27,6 @@ impl Repl {
let completer = Self::create_completer(&config, &commands);
let highlighter = ReplHighlighter::new(config.clone(), commands);
- let history = Self::create_history()?;
let menu = Self::create_menu();
let edit_mode: Box<dyn EditMode> = if config.read().keybindings.is_vi() {
let mut normal_keybindings = default_vi_normal_keybindings();
@@ -43,7 +42,6 @@ impl Repl {
let mut editor = Reedline::create()
.with_completer(Box::new(completer))
.with_highlighter(Box::new(highlighter))
- .with_history(history)
.with_menu(menu)
.with_edit_mode(edit_mode)
.with_quick_completions(true)
@@ -75,11 +73,6 @@ impl Repl {
);
keybindings.add_binding(
KeyModifiers::CONTROL,
- KeyCode::Char('l'),
- ReedlineEvent::ExecuteHostCommand(".clear screen".into()),
- );
- keybindings.add_binding(
- KeyModifiers::CONTROL,
KeyCode::Char('s'),
ReedlineEvent::Submit,
);
@@ -89,11 +82,4 @@ impl Repl {
let completion_menu = ColumnarMenu::default().with_name(MENU_NAME);
ReedlineMenu::EngineCompleter(Box::new(completion_menu))
}
-
- fn create_history() -> Result<Box<FileBackedHistory>> {
- Ok(Box::new(
- FileBackedHistory::with_file(1000, Config::history_file()?)
- .with_context(|| "Failed to setup history file")?,
- ))
- }
}
diff --git a/src/repl/mod.rs b/src/repl/mod.rs
index a6f173a..7a665ea 100644
--- a/src/repl/mod.rs
+++ b/src/repl/mod.rs
@@ -11,15 +11,14 @@ pub use self::init::Repl;
use crate::config::SharedConfig;
use crate::print_now;
-use crate::term;
-use anyhow::{Context, Result};
+use anyhow::Result;
use fancy_regex::Regex;
use lazy_static::lazy_static;
use reedline::Signal;
use std::rc::Rc;
-pub const REPL_COMMANDS: [(&str, &str); 14] = [
+pub const REPL_COMMANDS: [(&str, &str); 12] = [
(".info", "Print system-wide information"),
(".set", "Modify the configuration temporarily"),
(".model", "Choose a model"),
@@ -30,8 +29,6 @@ pub const REPL_COMMANDS: [(&str, &str); 14] = [
(".copy", "Copy the last output to the clipboard"),
(".read", "Read the contents of a file and submit"),
(".edit", "Multi-line editing (CTRL+S to finish)"),
- (".history", "Print the REPL history"),
- (".clear history", "Clear the REPL history"),
(".help", "Print this help message"),
(".exit", "Exit the REPL"),
];
@@ -102,22 +99,10 @@ impl Repl {
dump_repl_help();
}
".clear" => match args {
- Some("screen") => term::clear_screen(0)?,
- Some("history") => {
- self.editor
- .history_mut()
- .clear()
- .with_context(|| "Failed to clear history")?;
- print_now!("\n");
- }
Some("role") => handler.handle(ReplCmd::ClearRole)?,
Some("session") => handler.handle(ReplCmd::EndSession)?,
_ => dump_unknown_command(),
},
- ".history" => {
- self.editor.print_history()?;
- print_now!("\n");
- }
".model" => match args {
Some(name) => handler.handle(ReplCmd::SetModel(name.to_string()))?,
None => print_now!("Usage: .model <name>\n\n"),
diff --git a/src/term.rs b/src/term.rs
deleted file mode 100644
index 84449f4..0000000
--- a/src/term.rs
+++ /dev/null
@@ -1,32 +0,0 @@
-use anyhow::Result;
-use crossterm::{
- cursor, queue, style,
- terminal::{self, disable_raw_mode, enable_raw_mode, ClearType},
-};
-use std::io::{self, Stdout, Write};
-
-pub fn clear_screen(keep_lines: u16) -> Result<()> {
- enable_raw_mode()?;
- let mut stdout = io::stdout();
-
- let ret = clear_screen_inner(&mut stdout, keep_lines);
-
- // restore terminal
- disable_raw_mode()?;
-
- ret
-}
-
-fn clear_screen_inner(writer: &mut Stdout, keep_lines: u16) -> Result<()> {
- let (_, h) = terminal::size()?;
- queue!(
- writer,
- style::Print("\n".repeat((h - 2).into())),
- terminal::ScrollUp(2),
- cursor::MoveTo(0, 0),
- terminal::Clear(ClearType::FromCursorDown),
- terminal::ScrollUp(keep_lines),
- )?;
- writer.flush()?;
- Ok(())
-}