forked from StartAutomating/PowerShellAI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnable-AIShortCutKey.ps1
More file actions
35 lines (29 loc) · 1.02 KB
/
Enable-AIShortCutKey.ps1
File metadata and controls
35 lines (29 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function Enable-AIShortCutKey {
<#
.SYNOPSIS
Enable the Ctrl+g shortcut key for getting completions
.EXAMPLE
Enable-AIShortCutKey
#>
Set-PSReadLineKeyHandler -Key Ctrl+g `
-BriefDescription OpenAICli `
-LongDescription "Calls Open AI on the current buffer" `
-ScriptBlock {
param($key, $arg)
$line = $null
$cursor = $null
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)
$prompt = "Using PowerShell, just code: $($line)"
$output = Get-GPT3Completion $prompt -max_tokens 256
$output = $output -replace "`r", ""
# check if output is not null
if ($null -ne $output) {
foreach ($str in $output) {
if ($null -ne $str -and $str -ne "") {
[Microsoft.PowerShell.PSConsoleReadLine]::AddLine()
[Microsoft.PowerShell.PSConsoleReadLine]::Insert($str)
}
}
}
}
}