PowerGPT
1.0.4
編寫 shell 腳本可能既困難又無聊。即使您對 PowerShell 一無所知,該模組也將幫助您在幾秒鐘內完成 Windows 終端中的任何常見任務/批次。
只需像這樣輸入並執行PowerGPT
,GPT 模型就會為您完成剩下的工作:
$ PowerGPT " list all files in current folder with created date "
Will execute script:
-----
Get-ChildItem | Select-Object Name , CreationTime
-----
即使對於 PowerShell 專家來說,輸入幾個單字並讓 AI 模型完成髒活肯定聽起來是更好的方法;)
該腳本純粹在 PowerSell 中實現,並打包為 PowerShell 模組。
-Chat
操作的支援。優點:更便宜、更快。缺點:無法產生像text-davinnci-3
模型那樣的建議。Invoke-RestMethod
編碼,以便現在大多數語言都可以工作。 $ PowerGPT -Chat "列出所有文件"
我们使用`Get-ChildItem`来列出所有文件。
```
Get-ChildItem -Path "C:" -Recurse -File
```
这将列出C盘下所有文件,包括子文件夹中的文件。如果要列出当前文件夹下的所有文件,可以将`-Path`参数设置为`.`。
Will execute script:
-----
Get-ChildItem -Path "C:" -Recurse -File
-----
Install-Module PowerGPT
您需要一個 OpenAI API 金鑰才能使用此模組。該命令將在首次使用時要求輸入 API 金鑰。若要重設 API 金鑰,請使用-ResetConfig
選項。
基本用法:
$ PowerGPT " list all files in current folder with created date "
Will execute script:
-----
Get-ChildItem | Select-Object Name , CreationTime
-----
continue ?([ y ]es , [ n ]o):
$ PowerGPT " extract compressed.tar.gz "
Will execute script:
-----
# Extract compressed.tar.gz in Windows using PowerShell
# First, check if the tar command is available
if ( ! ( Get-Command tar - ErrorAction SilentlyContinue)) {
# If not, install the tar command
Invoke-WebRequest - Uri " http://gnuwin32.sourceforge.net/downlinks/tar.exe.zip " - OutFile " tar.exe.zip "
Expand-Archive - Path " tar.exe.zip " - DestinationPath " $ env: ProgramFiles GnuWin32 "
# Add the tar command to the PATH
$ env: Path += " ; $ env: ProgramFiles GnuWin32 "
}
# Extract the compressed.tar.gz file
tar - xvzf compressed.tar.gz
-----
continue ?([ y ]es , [ n ]o):
$ PowerGPT " print the first line of all the files that begin with poet_ in current folder "
Will execute script:
-----
Get-ChildItem - Path . - Filter " poet_* " | ForEach-Object { Get-Content $_ .FullName | Select-Object - First 1 }
-----
continue ?([ y ]es , [ n ]o):
對於複雜的任務,該工具將表現得智慧並為使用者提供選擇:
$ PowerGPT " print first lines and last lines for each file in current folder "
The description is too vague , do you mean:
[ 0 ] For each file in current directory , print the first line and then print the last line of the file.
[ 1 ] For each file in current directory , print the first line of the file. After that , for each file , print the last line of the file.
Choose one description that matches your task: : 1
Will execute script:
-----
Get-ChildItem | ForEach-Object {
$file = $_ .FullName
Write-Host " First line of $file : "
Get-Content $file - TotalCount 1
}
Get-ChildItem | ForEach-Object {
$file = $_ .FullName
Write-Host " Last line of $file : "
Get-Content $file - Tail 1
}
-----
continue ?([ y ]es , [ n ]o)
它也可以使用其他語言的公共庫編寫腳本:
$ PowerGPT " retrieve AzureDevops artifact for a build " - ShellVariant C #
The description is a little vague , do you mean:
[ 0 ] Use AzureDevops REST API to retrieve the artifact for a build.
[ 1 ] Use AzureDevops SDK to retrieve the artifact for a build.
Choose one description that matches your task , or [ n ]o: 0
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
var organization = " your_organization " ;
var project = " your_project " ;
var buildId = " your_build_id " ;
var token = " your_token " ;
var client = new HttpClient();
client.DefaultRequestHeaders.Add( " Authorization " , $ " Bearer {token} " );
var url = $ " https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/artifacts?api-version=5.1 " ;
var response = await client.GetAsync(url);
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}