Skip to content

Commit

Permalink
feat: add cli option --rebuild-rag (#1074)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden authored Jan 4, 2025
1 parent 1a07be7 commit bb648d6
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 1 deletion.
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 -e -c -f -S -h -V --model --prompt --role --session --empty-session --save-session --agent --agent-variable --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 -e -c -f -S -h -V --model --prompt --role --session --empty-session --save-session --agent --agent-variable --rag --rebuild-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
1 change: 1 addition & 0 deletions scripts/completions/aichat.fish
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ complete -c aichat -l save-session -d 'Ensure the new conversation is saved to t
complete -c aichat -s a -l agent -x -a "(aichat --list-agents)" -d 'Start a agent' -r
complete -c aichat -l agent-variable -d 'Set agent variables'
complete -c aichat -l rag -x -a"(aichat --list-rags)" -d 'Start a RAG' -r
complete -c aichat -l rebuild-rag -d 'Rebuild the RAG to sync document changes'
complete -c aichat -l serve -d 'Serve the LLM API and WebAPP'
complete -c aichat -s e -l execute -d 'Execute commands in natural language'
complete -c aichat -s c -l code -d 'Output code only'
Expand Down
1 change: 1 addition & 0 deletions scripts/completions/aichat.nu
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module completions {
--agent(-a): string@"nu-complete aichat agent" # Start a agent
--agent-variable # Set agent variables
--rag: string@"nu-complete aichat rag" # Start a RAG
--rebuild-rag # Rebuild the RAG to sync document changes
--serve # Serve the LLM API and WebAPP
--execute(-e) # Execute commands in natural language
--code(-c) # Output code only
Expand Down
1 change: 1 addition & 0 deletions scripts/completions/aichat.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Register-ArgumentCompleter -Native -CommandName 'aichat' -ScriptBlock {
[CompletionResult]::new('--agent', '--agent', [CompletionResultType]::ParameterName, 'Start a agent')
[CompletionResult]::new('--agent-variable', '--agent-variable', [CompletionResultType]::ParameterName, 'Set agent variables')
[CompletionResult]::new('--rag', '--rag', [CompletionResultType]::ParameterName, 'Start a RAG')
[CompletionResult]::new('--rebuild-rag', '--rebuild-rag', [CompletionResultType]::ParameterName, 'Rebuild the RAG to sync document changes')
[CompletionResult]::new('--serve', '--serve', [CompletionResultType]::ParameterName, 'Serve the LLM API and WebAPP')
[CompletionResult]::new('-e', '-e', [CompletionResultType]::ParameterName, 'Execute commands in natural language')
[CompletionResult]::new('--execute', '--execute', [CompletionResultType]::ParameterName, 'Execute commands in natural language')
Expand Down
1 change: 1 addition & 0 deletions scripts/completions/aichat.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ _aichat() {
'--agent[Start a agent]:AGENT:->agents' \
'--agent-variable[Set agent variables]' \
'--rag[Start a RAG]:RAG:->rags' \
'--rebuild-rag[Rebuild the RAG to sync document changes]' \
'--serve[Serve the LLM API and WebAPP]' \
'-e[Execute commands in natural language]' \
'--execute[Execute commands in natural language]' \
Expand Down
3 changes: 3 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ pub struct Cli {
/// Start a RAG
#[clap(long)]
pub rag: Option<String>,
/// Rebuild the RAG to sync document changes
#[clap(long)]
pub rebuild_rag: bool,
/// Serve the LLM API and WebAPP
#[clap(long, value_name = "ADDRESS")]
pub serve: Option<Option<String>>,
Expand Down
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ async fn run(config: GlobalConfig, cli: Cli, text: Option<String>) -> Result<()>
return Ok(());
}
let is_repl = config.read().working_mode.is_repl();
if cli.rebuild_rag {
Config::rebuild_rag(&config, abort_signal.clone()).await?;
if is_repl {
return Ok(());
}
}
if cli.execute && !is_repl {
if cfg!(target_os = "macos") && !stdin().is_terminal() {
bail!("Unable to read the pipe for shell execution on MacOS")
Expand Down

0 comments on commit bb648d6

Please sign in to comment.