Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add CLI option --empty-session #922

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/completions/aichat.bash
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ _aichat() {

case "${cmd}" in
aichat)
opts="-m -r -s -a -R -e -c -f -S -h -V --model --prompt --role --session --save-session --agent --rag --serve --execute --code --file --no-stream --dry-run --info --list-models --list-roles --list-sessions --list-agents --list-rags --help --version"
opts="-m -r -s -a -R -e -c -f -S -h -V --model --prompt --role --session --empty-session --save-session --agent --rag --serve --execute --code --file --no-stream --dry-run --info --list-models --list-roles --list-sessions --list-agents --list-rags --help --version"
if [[ ${cur} == -* || ${cword} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down
3 changes: 2 additions & 1 deletion scripts/completions/aichat.fish
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ complete -c aichat -s m -l model -x -a "(aichat --list-models)" -d 'Select a LLM
complete -c aichat -l prompt -d 'Use the system prompt'
complete -c aichat -s r -l role -x -a "(aichat --list-roles)" -d 'Select a role' -r
complete -c aichat -s s -l session -x -a"(aichat --list-sessions)" -d 'Start or join a session' -r
complete -c aichat -l save-session -d 'Forces the session to be saved'
complete -c aichat -l empty-session -d 'Ensure the session is empty'
complete -c aichat -l save-session -d 'Force the session to be saved'
complete -c aichat -s a -l agent -x -a"(aichat --list-agents)" -d 'Start a agent' -r
complete -c aichat -s R -l rag -x -a"(aichat --list-rags)" -d 'Start a RAG' -r
complete -c aichat -l serve -d 'Serve the LLM API and WebAPP'
Expand Down
3 changes: 2 additions & 1 deletion scripts/completions/aichat.nu
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ module completions {
--prompt # Use the system prompt
--role(-r): string@"nu-complete aichat role" # Select a role
--session(-s): string@"nu-complete aichat session" # Start or join a session
--save-session # Forces the session to be saved
--empty-session # Ensure the session is empty
--save-session # Force the session to be saved
--agent(-a): string@"nu-complete aichat agent" # Start a agent
--rag(-R): string@"nu-complete aichat rag" # Start a RAG
--serve # Serve the LLM API and WebAPP
Expand Down
3 changes: 2 additions & 1 deletion scripts/completions/aichat.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ Register-ArgumentCompleter -Native -CommandName 'aichat' -ScriptBlock {
[CompletionResult]::new('--role', '--role', [CompletionResultType]::ParameterName, 'Select a role')
[CompletionResult]::new('-s', '-s', [CompletionResultType]::ParameterName, 'Start or join a session')
[CompletionResult]::new('--session', '--session', [CompletionResultType]::ParameterName, 'Start or join a session')
[CompletionResult]::new('--save-session', '--save-session', [CompletionResultType]::ParameterName, 'Forces the session to be saved')
[CompletionResult]::new('--empty-session', '--empty-session', [CompletionResultType]::ParameterName, 'Ensure the session is empty')
[CompletionResult]::new('--save-session', '--save-session', [CompletionResultType]::ParameterName, 'Force the session to be saved')
[CompletionResult]::new('-a', '-a', [CompletionResultType]::ParameterName, 'Start a agent')
[CompletionResult]::new('--agent', '--agent', [CompletionResultType]::ParameterName, 'Start a agent')
[CompletionResult]::new('-R', '-R', [CompletionResultType]::ParameterName, 'Start a RAG')
Expand Down
3 changes: 2 additions & 1 deletion scripts/completions/aichat.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ _aichat() {
'--role[Select a role]:ROLE:->roles' \
'-s[Start or join a session]:SESSION:->sessions' \
'--session[Start or join a session]:SESSION:->sessions' \
'--save-session[Forces the session to be saved]' \
'--empty-session[Ensure the session is empty]' \
'--save-session[Force the session to be saved]' \
'-a[Start a agent]:AGENT:->agents' \
'--agent[Start a agent]:AGENT:->agents' \
'-R[Start a RAG]:RAG:->rags' \
Expand Down
5 changes: 4 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ pub struct Cli {
/// Start or join a session
#[clap(short = 's', long)]
pub session: Option<Option<String>>,
/// Forces the session to be saved
/// Ensure the session is empty
#[clap(long)]
pub empty_session: bool,
/// Force the session to be saved
#[clap(long)]
pub save_session: bool,
/// Start a agent
Expand Down
2 changes: 1 addition & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ impl Config {
Ok(())
}

pub fn clear_session_messages(&mut self) -> Result<()> {
pub fn empty_session(&mut self) -> Result<()> {
if let Some(session) = self.session.as_mut() {
session.clear_messages();
if let Some(agent) = self.agent.as_ref() {
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ async fn run(config: GlobalConfig, cli: Cli, text: Option<String>) -> Result<()>
if cli.no_stream {
config.write().stream = false;
}
if cli.empty_session {
config.write().empty_session()?;
}
if cli.save_session {
config.write().set_save_session(Some(true));
}
Expand Down
2 changes: 1 addition & 1 deletion src/repl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ impl Repl {
},
".clear" => match args {
Some("messages") => {
self.config.write().clear_session_messages()?;
self.config.write().empty_session()?;
}
_ => unknown_command()?,
},
Expand Down