You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: PleasePwsh/PleasePwsh.psm1
+19-19Lines changed: 19 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ If this switch is provided, the script will return a brief explanation of the sp
24
24
.EXAMPLE
25
25
PS> Please "Get all files in current directory that are larger than 1 MB"
26
26
27
-
PS> Please -Explain "Get-ChildItem -Path 'C:\'"
27
+
PS> Please -Explain "Get-ChildItem -Path 'C:\'"
28
28
#>
29
29
functionPlease {
30
30
[CmdletBinding()]
@@ -33,18 +33,18 @@ function Please {
33
33
[Alias("e")][switch]$Explain
34
34
35
35
)
36
-
36
+
37
37
Test-ApiKey
38
38
39
39
if ($Explain) {
40
40
$Explanation=Get-CommandExplanation$Prompt
41
-
Write-Host"`u{261D}$Explanation"
41
+
Write-Output"`u{261D}$Explanation"
42
42
$Command=$Prompt
43
43
}
44
44
else {
45
-
$Command=Get-Command$Prompt
45
+
$Command=Get-PwshCommand$Prompt
46
46
if ($Command.contains("I do not know")) {
47
-
Write-Host$Command
47
+
Write-Output$Command
48
48
Return
49
49
}
50
50
}
@@ -54,7 +54,7 @@ function Please {
54
54
55
55
functionTest-ApiKey {
56
56
if ($null-eq$env:OPENAI_API_KEY) {
57
-
Write-Host"`u{1F50E} Api key missing. See https://help.openai.com/en/articles/4936850-where-do-i-find-my-secret-api-key"
57
+
Write-Output"`u{1F50E} Api key missing. See https://help.openai.com/en/articles/4936850-where-do-i-find-my-secret-api-key"
58
58
$Key=Read-Host"Please provide the api key"
59
59
60
60
if ([string]::IsNullOrWhiteSpace($Key)) {
@@ -64,7 +64,7 @@ function Test-ApiKey {
64
64
}
65
65
}
66
66
67
-
functionGet-Command([string]$Prompt) {
67
+
functionGet-PwshCommand([string]$Prompt) {
68
68
$Role="You translate the input given into PowerShell command. You may not use natural language, but only a PowerShell commands as answer. Do not use markdown. Do not quote the whole output. If you do not know the answer, answer only with 'I do not know'"
69
69
70
70
$Payload=@{
@@ -80,9 +80,9 @@ function Get-Command([string]$Prompt) {
0 commit comments