refactor: minor improvement (#611)

pull/613/head
sigoden 3 months ago committed by GitHub
parent 62b297e8bb
commit b965c63be0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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

@ -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'

@ -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

@ -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')

@ -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]' \

@ -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

@ -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 {

@ -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;

@ -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") => {

Loading…
Cancel
Save