-
Notifications
You must be signed in to change notification settings - Fork 0
/
aicommand.ps1
79 lines (65 loc) · 2.18 KB
/
aicommand.ps1
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<#
.SYNOPSIS
Powershell/pwsh aicommand
.DESCRIPTION
Powershell script for running aicommand.py
.PARAMETER Executor
Application/executor for executing the generated command (e.g. powershell, bash)
.PARAMETER Provider
AI provider (openai or lmstudio).
.PARAMETER Model
Name of the model to use (e.g. gpt-3, gpt-neo, llama3), model availability is based on provider.
.PARAMETER BaseUrl
AI Provider's base URL.
.PARAMETER ApiKey
API key.
.PARAMETER Prompt
Your prompt describing task/command to produce and execute.
.EXAMPLE
aicommand.ps1 "list of files existing on current directory"
.EXAMPLE
aicommand.ps1 --executor bash "list of files existing on current directory"
.SYNTAX
aicommand.ps1 "<prompt>"
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, Position = 0, ValueFromRemainingArguments = $true)]
[String] $Prompt,
[String] $Executor,
[String] $Provider,
[String] $Model,
[String] $BaseUrl,
[String] $ApiKey
)
$Prompt
$scriptDirectory = Split-Path -Parent $MyInvocation.MyCommand.Definition
$additionalScriptDirectory = Join-Path -Path $scriptDirectory -ChildPath script
$preScriptPath = Join-Path -Path $additionalScriptDirectory -ChildPath aicommand-pre-script.ps1
if (Test-Path -Path $preScriptPath -PathType Leaf) {
. $preScriptPath -ScriptDirectory $scriptDirectory
}
$scriptPath = Join-Path -Path $scriptDirectory -ChildPath aicommand.py
$params = ""
if (-Not [String]::IsNullOrEmpty($Executor)) {
$params = $params + " --executor $Executor"
}
if (-Not [String]::IsNullOrEmpty($Provider)) {
$params = $params + " --provider $Provider"
}
if (-Not [String]::IsNullOrEmpty($Model)) {
$params = $params + " --model $Model"
}
if (-Not [String]::IsNullOrEmpty($BaseUrl)) {
$params = $params + " --base-url $BaseUrl"
}
if (-Not [String]::IsNullOrEmpty($ApiKey)) {
$params = $params + " --api-key $ApiKey"
}
$pythonCommand = "python $scriptPath$params '$Prompt'"
Write-Output $pythonCommand
Invoke-Expression $pythonCommand
$postScriptPath = Join-Path -Path $additionalScriptDirectory -ChildPath aicommand-post-script.ps1
if (Test-Path -Path aicommand-post-script.ps1 -PathType Leaf) {
. $postScriptPath
}