OpenAI

PowerShell でOpenAI のChatGPT を利用する。Excelにも出力できるよ。

はじめに

PowerShellでChatGPTを利用する方法を紹介します。

すでにPowerShellのモジュールを作成している人がいるので利用させてもらいます。

GitHub - dfinke/PowerShellAI: PowerShell AI module for OpenAI GPT-3 and DALL-E
GitHub - dfinke/PowerShellAI: PowerShell AI module for OpenAI GPT-3 and DALL-E

PowerShell AI module for OpenAI GPT-3 and DALL-E. Contribute to dfinke/PowerShellAI development by c ...

github.com

PowerShellAIをインストール

Install-Module -Name PowerShellAI でインストールします。

PS C:\Users\azureuser> Install-Module -Name PowerShellAI 

NuGet provider is required to continue
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet
provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
'C:\Users\azureuser\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by
running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install
and import the NuGet provider now?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): y

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
'PSGallery'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): y

OpenAIのAPIキーを取得します。

Set-OpenAIKey でAPIキーを設定します。

PS C:\Users\azureuser> Set-OpenAIKey

cmdlet Set-OpenAIKey at command pipeline position 1
Supply values for the following parameters:
Key: ***************************************************

 

Get-GPT3Completion で会話を始めることができます。

PS C:\Users\azureuser> Get-GPT3Completion "hello"

Hi there! How can I help you?
PS C:\Users\azureuser> Get-GPT3Completion "What is your name?"

My name is John.

突然、Johnと答えるChatGPTでした。

Excelに出力

Install-Module -Name ImportExcel でExcelに出力することができるようになります。

PS C:\Users\azureuser> Install-Module -Name ImportExcel

Untrusted repository
You are installing the modules from an untrusted repository. If you trust
this repository, change its InstallationPolicy value by running the
Set-PSRepository cmdlet. Are you sure you want to install the modules from
'PSGallery'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help
(default is "N"):y

New-Spreadsheet でExcelに出力できます。

PS C:\Users\azureuser> New-Spreadsheet 'population of india, china, usa, euroupe'

 

勝手に開きます。

まとめ

PowerShellでもChatGPTを利用することができます。モジュールを利用すると簡単に使えました。

-OpenAI
-