feat: add `--prompt` option (#454)

pull/455/head
sigoden 2 weeks ago committed by GitHub
parent 4b205c4bac
commit d9b8eabf23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -19,7 +19,7 @@ _aichat() {
case "${cmd}" in
aichat)
opts="-m -r -s -e -c -f -H -S -w -h -V --model --role --session --save-session --serve --execute --code --file --no-highlight --no-stream --wrap --light-theme --dry-run --info --list-models --list-roles --list-sessions --help --version"
opts="-m -r -s -e -c -f -H -S -w -h -V --model --prompt --role --session --save-session --serve --execute --code --file --no-highlight --no-stream --wrap --light-theme --dry-run --info --list-models --list-roles --list-sessions --help --version"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
@ -49,6 +49,10 @@ _aichat() {
COMPREPLY=($(compgen -W "$("$1" --list-models)" -- "${cur}"))
return 0
;;
--prompt)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
-r|--role)
COMPREPLY=($(compgen -W "$("$1" --list-roles)" -- "${cur}"))
return 0

@ -1,4 +1,5 @@
complete -c aichat -s m -l model -x -a "(aichat --list-models)" -d 'Select a LLM model' -r
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 -s f -l file -d 'Include files with the message' -r -F

@ -25,6 +25,7 @@ module completions {
# All-in-one chat and copilot CLI that integrates 10+ AI platforms
export extern aichat [
--model(-m): string@"nu-complete aichat model" # Select a LLM model
--prompt # Use the system prompt
--role(-r): string@"nu-complete aichat role" # Select a role
--session(-s): string@"nu-complete aichat role" # Start or join a session
--save-session # Forces the session to be saved

@ -22,6 +22,7 @@ Register-ArgumentCompleter -Native -CommandName 'aichat' -ScriptBlock {
'aichat' {
[CompletionResult]::new('-m', '-m', [CompletionResultType]::ParameterName, 'Select a LLM model')
[CompletionResult]::new('--model', '--model', [CompletionResultType]::ParameterName, 'Select a LLM model')
[CompletionResult]::new('--prompt', '--prompt', [CompletionResultType]::ParameterName, 'Use the system prompt')
[CompletionResult]::new('-r', '-r', [CompletionResultType]::ParameterName, 'Select a role')
[CompletionResult]::new('--role', '--role', [CompletionResultType]::ParameterName, 'Select a role')
[CompletionResult]::new('-s', '-s', [CompletionResultType]::ParameterName, 'Start or join a session')

@ -16,6 +16,7 @@ _aichat() {
local context curcontext="$curcontext" state line
local common=(
'-m+[Select a LLM model]:MODEL:->models' \
'--prompt=[Use the system prompt]:PROMPT: ' \
'--model=[Select a LLM model]:MODEL:->models' \
'-r+[Select a role]:ROLE:->roles' \
'--role=[Select a role]:ROLE:->roles' \

@ -6,6 +6,9 @@ pub struct Cli {
/// Select a LLM model
#[clap(short, long)]
pub model: Option<String>,
/// Use the system prompt
#[clap(long)]
pub prompt: Option<String>,
/// Select a role
#[clap(short, long)]
pub role: Option<String>,

@ -80,7 +80,9 @@ async fn main() -> Result<()> {
if cli.dry_run {
config.write().dry_run = true;
}
if let Some(name) = &cli.role {
if let Some(prompt) = &cli.prompt {
config.write().set_prompt(prompt)?;
} else if let Some(name) = &cli.role {
config.write().set_role(name)?;
} else if cli.execute {
config.write().set_role(SHELL_ROLE)?;

@ -32,7 +32,7 @@ lazy_static! {
ReplCommand::new(".model", "Change the current LLM", State::all()),
ReplCommand::new(
".prompt",
"Make a temporary role using a prompt",
"Create a temporary role using a custom prompt",
State::able_change_role()
),
ReplCommand::new(

Loading…
Cancel
Save