summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-06-17 19:54:24 +0800
committerGitHub <noreply@github.com>2024-06-17 19:54:24 +0800
commitb965c63be05c726c996ece298d6f5f2514a19316 (patch)
treedecc1e021caa638de171e0fb94e6e4f5b3e39f63
parent62b297e8bb09e257a61154afddc4017e48bd12f3 (diff)
downloadaichat-b965c63be05c726c996ece298d6f5f2514a19316.tar.gz
refactor: minor improvement (#611)
-rw-r--r--README.md2
-rw-r--r--scripts/completions/aichat.fish2
-rw-r--r--scripts/completions/aichat.nu2
-rw-r--r--scripts/completions/aichat.ps12
-rw-r--r--scripts/completions/aichat.zsh2
-rw-r--r--src/cli.rs2
-rw-r--r--src/config/mod.rs16
-rw-r--r--src/config/session.rs8
-rw-r--r--src/repl/mod.rs2
9 files changed, 23 insertions, 15 deletions
diff --git a/README.md b/README.md
index 977d7d8..0d0adcf 100644
--- a/README.md
+++ b/README.md
@@ -140,7 +140,7 @@ Options:
--light-theme Use light theme
--dry-run Display the message without sending it
--info Display information
- --list-models List all available models
+ --list-models List all available chat models
--list-roles List all available roles
--list-sessions List all available sessions
-h, --help Print help
diff --git a/scripts/completions/aichat.fish b/scripts/completions/aichat.fish
index d05b4e6..8761b1d 100644
--- a/scripts/completions/aichat.fish
+++ b/scripts/completions/aichat.fish
@@ -15,7 +15,7 @@ complete -c aichat -s S -l no-stream -d 'Turns off stream mode'
complete -c aichat -l light-theme -d 'Use light theme'
complete -c aichat -l dry-run -d 'Display the message without sending it'
complete -c aichat -l info -d 'Display information'
-complete -c aichat -l list-models -d 'List all available models'
+complete -c aichat -l list-models -d 'List all available chat models'
complete -c aichat -l list-roles -d 'List all roles'
complete -c aichat -l list-sessions -d 'List all sessions'
complete -c aichat -l list-bots -d 'List all bots'
diff --git a/scripts/completions/aichat.nu b/scripts/completions/aichat.nu
index ec4b083..c09626b 100644
--- a/scripts/completions/aichat.nu
+++ b/scripts/completions/aichat.nu
@@ -53,7 +53,7 @@ module completions {
--light-theme # Use light theme
--dry-run # Display the message without sending it
--info # Display information
- --list-models # List all available models
+ --list-models # List all available chat models
--list-roles # List all roles
--list-sessions # List all sessions
--list-bots # List all bots
diff --git a/scripts/completions/aichat.ps1 b/scripts/completions/aichat.ps1
index 093f53f..cf6cdd4 100644
--- a/scripts/completions/aichat.ps1
+++ b/scripts/completions/aichat.ps1
@@ -47,7 +47,7 @@ Register-ArgumentCompleter -Native -CommandName 'aichat' -ScriptBlock {
[CompletionResult]::new('--light-theme', '--light-theme', [CompletionResultType]::ParameterName, 'Use light theme')
[CompletionResult]::new('--dry-run', '--dry-run', [CompletionResultType]::ParameterName, 'Display the message without sending it')
[CompletionResult]::new('--info', '--info', [CompletionResultType]::ParameterName, 'Display information')
- [CompletionResult]::new('--list-models', '--list-models', [CompletionResultType]::ParameterName, 'List all available models')
+ [CompletionResult]::new('--list-models', '--list-models', [CompletionResultType]::ParameterName, 'List all available chat models')
[CompletionResult]::new('--list-roles', '--list-roles', [CompletionResultType]::ParameterName, 'List all roles')
[CompletionResult]::new('--list-sessions', '--list-sessions', [CompletionResultType]::ParameterName, 'List all sessions')
[CompletionResult]::new('--list-bots', '--list-bots', [CompletionResultType]::ParameterName, 'List all bots')
diff --git a/scripts/completions/aichat.zsh b/scripts/completions/aichat.zsh
index ae39481..b57b575 100644
--- a/scripts/completions/aichat.zsh
+++ b/scripts/completions/aichat.zsh
@@ -42,7 +42,7 @@ _aichat() {
'--light-theme[Use light theme]' \
'--dry-run[Display the message without sending it]' \
'--info[Display information]' \
-'--list-models[List all available models]' \
+'--list-models[List all available chat models]' \
'--list-roles[List all roles]' \
'--list-sessions[List all sessions]' \
'--list-bots[List all bots]' \
diff --git a/src/cli.rs b/src/cli.rs
index 651d23a..e9e0323 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -54,7 +54,7 @@ pub struct Cli {
/// Display information
#[clap(long)]
pub info: bool,
- /// List all available models
+ /// List all available chat models
#[clap(long)]
pub list_models: bool,
/// List all roles
diff --git a/src/config/mod.rs b/src/config/mod.rs
index cb510ef..41e449a 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -583,7 +583,8 @@ impl Config {
}
pub fn use_prompt(&mut self, prompt: &str) -> Result<()> {
- let role = Role::new(TEMP_ROLE_NAME, prompt);
+ let mut role = Role::new(TEMP_ROLE_NAME, prompt);
+ role.set_model(&self.model);
self.use_role_obj(role)
}
@@ -705,9 +706,8 @@ impl Config {
pub fn exit_session(&mut self) -> Result<()> {
if let Some(mut session) = self.session.take() {
- let is_repl = self.working_mode == WorkingMode::Repl;
let sessions_dir = self.sessions_dir()?;
- session.exit(&sessions_dir, is_repl)?;
+ session.exit(&sessions_dir, self.working_mode.is_repl())?;
self.last_message = None;
}
Ok(())
@@ -723,7 +723,7 @@ impl Config {
};
let session_path = self.session_file(&name)?;
if let Some(session) = self.session.as_mut() {
- session.save(&session_path)?;
+ session.save(&session_path, self.working_mode.is_repl())?;
}
Ok(())
}
@@ -933,8 +933,8 @@ impl Config {
}
pub fn exit_bot(&mut self) -> Result<()> {
+ self.exit_session()?;
if self.bot.take().is_some() {
- self.exit_session()?;
self.rag.take();
self.last_message = None;
}
@@ -1420,6 +1420,12 @@ pub enum WorkingMode {
Serve,
}
+impl WorkingMode {
+ pub fn is_repl(&self) -> bool {
+ *self == WorkingMode::Repl
+ }
+}
+
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct StateFlags: u32 {
diff --git a/src/config/session.rs b/src/config/session.rs
index 2149ba5..726249c 100644
--- a/src/config/session.rs
+++ b/src/config/session.rs
@@ -312,12 +312,12 @@ impl Session {
}
}
let session_path = session_dir.join(format!("{}.yaml", self.name()));
- self.save(&session_path)?;
+ self.save(&session_path, is_repl)?;
}
Ok(())
}
- pub fn save(&mut self, session_path: &Path) -> Result<()> {
+ pub fn save(&mut self, session_path: &Path, is_repl: bool) -> Result<()> {
if let Some(sessions_dir) = session_path.parent() {
if !sessions_dir.exists() {
create_dir_all(sessions_dir).with_context(|| {
@@ -338,7 +338,9 @@ impl Session {
)
})?;
- println!("✨ Saved session to '{}'", session_path.display());
+ if is_repl {
+ println!("✨ Saved session to '{}'", session_path.display());
+ }
self.dirty = false;
diff --git a/src/repl/mod.rs b/src/repl/mod.rs
index ca718b5..1214fb5 100644
--- a/src/repl/mod.rs
+++ b/src/repl/mod.rs
@@ -350,7 +350,7 @@ Tips: use <tab> to autocomplete conversation starter text.
".copy" => {
let config = self.config.read();
self.copy(config.last_reply())
- .with_context(|| "Failed to copy the last output")?;
+ .with_context(|| "Failed to copy the last response")?;
}
".exit" => match args {
Some("role") => {