2024-04-13 11:50:10 +00:00
|
|
|
using namespace System.Management.Automation
|
|
|
|
using namespace System.Management.Automation.Language
|
|
|
|
|
|
|
|
Register-ArgumentCompleter -Native -CommandName 'aichat' -ScriptBlock {
|
|
|
|
param($wordToComplete, $commandAst, $cursorPosition)
|
|
|
|
|
|
|
|
$commandElements = $commandAst.CommandElements
|
|
|
|
$command = @(
|
|
|
|
'aichat'
|
|
|
|
for ($i = 1; $i -lt $commandElements.Count; $i++) {
|
|
|
|
$element = $commandElements[$i]
|
|
|
|
if ($element -isnot [StringConstantExpressionAst] -or
|
|
|
|
$element.StringConstantType -ne [StringConstantType]::BareWord -or
|
|
|
|
$element.Value.StartsWith('-') -or
|
|
|
|
$element.Value -eq $wordToComplete) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
$element.Value
|
|
|
|
}) -join ';'
|
|
|
|
|
|
|
|
$completions = @(switch ($command) {
|
|
|
|
'aichat' {
|
2024-04-20 13:07:30 +00:00
|
|
|
[CompletionResult]::new('-m', '-m', [CompletionResultType]::ParameterName, 'Select a LLM model')
|
|
|
|
[CompletionResult]::new('--model', '--model', [CompletionResultType]::ParameterName, 'Select a LLM model')
|
2024-04-28 11:18:56 +00:00
|
|
|
[CompletionResult]::new('--prompt', '--prompt', [CompletionResultType]::ParameterName, 'Use the system prompt')
|
2024-04-20 13:07:30 +00:00
|
|
|
[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')
|
|
|
|
[CompletionResult]::new('--session', '--session', [CompletionResultType]::ParameterName, 'Start or join a session')
|
2024-06-13 11:41:54 +00:00
|
|
|
[CompletionResult]::new('--save-session', '--save-session', [CompletionResultType]::ParameterName, 'Forces the session to be saved')
|
2024-06-23 15:09:47 +00:00
|
|
|
[CompletionResult]::new('-a', '-a', [CompletionResultType]::ParameterName, 'Start a agent')
|
2024-06-21 22:54:03 +00:00
|
|
|
[CompletionResult]::new('--agent', '--agent', [CompletionResultType]::ParameterName, 'Start a agent')
|
2024-06-23 15:09:47 +00:00
|
|
|
[CompletionResult]::new('-R', '-R', [CompletionResultType]::ParameterName, 'Start a RAG')
|
2024-06-13 11:41:54 +00:00
|
|
|
[CompletionResult]::new('--rag', '--rag', [CompletionResultType]::ParameterName, 'Start a RAG')
|
2024-05-07 02:17:40 +00:00
|
|
|
[CompletionResult]::new('--serve', '--serve', [CompletionResultType]::ParameterName, 'Serve the LLM API and WebAPP')
|
2024-04-20 13:07:30 +00:00
|
|
|
[CompletionResult]::new('-e', '-e', [CompletionResultType]::ParameterName, 'Execute commands in natural language')
|
|
|
|
[CompletionResult]::new('--execute', '--execute', [CompletionResultType]::ParameterName, 'Execute commands in natural language')
|
|
|
|
[CompletionResult]::new('-c', '-c', [CompletionResultType]::ParameterName, 'Output code only')
|
|
|
|
[CompletionResult]::new('--code', '--code', [CompletionResultType]::ParameterName, 'Output code only')
|
2024-06-23 23:37:50 +00:00
|
|
|
[CompletionResult]::new('-f', '-f', [CompletionResultType]::ParameterName, 'Include files with the message')
|
|
|
|
[CompletionResult]::new('--file', '--file', [CompletionResultType]::ParameterName, 'Include files with the message')
|
|
|
|
[CompletionResult]::new('-S', '-S', [CompletionResultType]::ParameterName, 'Turn off stream mode')
|
|
|
|
[CompletionResult]::new('--no-stream', '--no-stream', [CompletionResultType]::ParameterName, 'Turn off stream mode')
|
|
|
|
[CompletionResult]::new('-w', '-w', [CompletionResultType]::ParameterName, 'Control text wrapping (no, auto, <max-width>)')
|
|
|
|
[CompletionResult]::new('--wrap', '--wrap', [CompletionResultType]::ParameterName, 'Control text wrapping (no, auto, <max-width>)')
|
2024-04-20 13:07:30 +00:00
|
|
|
[CompletionResult]::new('-H', '-H', [CompletionResultType]::ParameterName, 'Turn off syntax highlighting')
|
|
|
|
[CompletionResult]::new('--no-highlight', '--no-highlight', [CompletionResultType]::ParameterName, 'Turn off syntax highlighting')
|
2024-04-13 11:50:10 +00:00
|
|
|
[CompletionResult]::new('--light-theme', '--light-theme', [CompletionResultType]::ParameterName, 'Use light theme')
|
2024-04-20 13:07:30 +00:00
|
|
|
[CompletionResult]::new('--dry-run', '--dry-run', [CompletionResultType]::ParameterName, 'Display the message without sending it')
|
2024-04-20 22:26:29 +00:00
|
|
|
[CompletionResult]::new('--info', '--info', [CompletionResultType]::ParameterName, 'Display information')
|
2024-06-17 11:54:24 +00:00
|
|
|
[CompletionResult]::new('--list-models', '--list-models', [CompletionResultType]::ParameterName, 'List all available chat models')
|
2024-06-13 11:41:54 +00:00
|
|
|
[CompletionResult]::new('--list-roles', '--list-roles', [CompletionResultType]::ParameterName, 'List all roles')
|
|
|
|
[CompletionResult]::new('--list-sessions', '--list-sessions', [CompletionResultType]::ParameterName, 'List all sessions')
|
2024-06-21 22:54:03 +00:00
|
|
|
[CompletionResult]::new('--list-agents', '--list-agents', [CompletionResultType]::ParameterName, 'List all agents')
|
2024-06-13 11:41:54 +00:00
|
|
|
[CompletionResult]::new('--list-rags', '--list-rags', [CompletionResultType]::ParameterName, 'List all RAGs')
|
2024-04-13 11:50:10 +00:00
|
|
|
[CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help')
|
|
|
|
[CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help')
|
|
|
|
[CompletionResult]::new('-V', '-V', [CompletionResultType]::ParameterName, 'Print version')
|
|
|
|
[CompletionResult]::new('--version', '--version', [CompletionResultType]::ParameterName, 'Print version')
|
|
|
|
break
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
function Get-AichatValues($arg) {
|
|
|
|
$(aichat $arg) -split '\n' | ForEach-Object { [CompletionResult]::new($_) }
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($commandElements.Count -gt 1) {
|
|
|
|
$offset=2
|
|
|
|
if ($wordToComplete -eq "") {
|
|
|
|
$offset=1
|
|
|
|
}
|
|
|
|
$flag = $commandElements[$commandElements.Count-$offset].ToString()
|
2024-06-23 15:09:47 +00:00
|
|
|
dump-args $flag ($flag -eq "-R") > /tmp/file1
|
|
|
|
if ($flag -ceq "-m" -or $flag -eq "--model") {
|
2024-04-13 11:50:10 +00:00
|
|
|
$completions = Get-AichatValues "--list-models"
|
2024-06-23 15:09:47 +00:00
|
|
|
} elseif ($flag -ceq "-r" -or $flag -eq "--role") {
|
2024-04-13 11:50:10 +00:00
|
|
|
$completions = Get-AichatValues "--list-roles"
|
2024-06-23 15:09:47 +00:00
|
|
|
} elseif ($flag -ceq "-s" -or $flag -eq "--session") {
|
2024-04-13 11:50:10 +00:00
|
|
|
$completions = Get-AichatValues "--list-sessions"
|
2024-06-23 15:09:47 +00:00
|
|
|
} elseif ($flag -ceq "-a" -or $flag -eq "--agent") {
|
2024-06-21 22:54:03 +00:00
|
|
|
$completions = Get-AichatValues "--list-agents"
|
2024-06-23 15:09:47 +00:00
|
|
|
} elseif ($flag -ceq "-R" -or $flag -eq "--rag") {
|
2024-06-13 11:41:54 +00:00
|
|
|
$completions = Get-AichatValues "--list-rags"
|
2024-06-23 15:09:47 +00:00
|
|
|
} elseif ($flag -ceq "-f" -or $flag -eq "--file") {
|
2024-04-13 11:50:10 +00:00
|
|
|
$completions = @()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
|
|
|
|
Sort-Object -Property ListItemText
|
|
|
|
}
|