feat: add CLI option `--empty-session` (#922)

pull/923/head
sigoden 4 days ago committed by GitHub
parent 349c236472
commit aaea0ff702
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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

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

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

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

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

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

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

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

@ -475,7 +475,7 @@ impl Repl {
},
".clear" => match args {
Some("messages") => {
self.config.write().clear_session_messages()?;
self.config.write().empty_session()?;
}
_ => unknown_command()?,
},

Loading…
Cancel
Save