This is an unofficial OpenAI PowerShell module that allows you to get text completion or start a chat experience or generate image directly in PowerShell. You can use OpenAI Service, Azure OpenAI Service and almost all the GPT services and even the local LLMs in a consistent way, You can easily automate those batch processing tasks, scheduled tasks, and heavy manual tasks in one or two lines of commands.
This module is compatible with PowerShell 5.1 and above, and if you are using PowerShell Core (6.x+), it can be used on all platforms including Windows, MacOS, and Linux.
To use this module, you must install PowerShell. It is included by default in Windows. If you are using MacOS or Linux, you can install it using the following guide:
- MacOS:
- Run
brew install powershell/tap/powershellto install PowerShell on MacOS, then enterpwshin the terminal to launch PowerShell. Follow the guide here if you encountered any problem.
- Run
- Linux:
- Follow the guide here to install PowerShell on Linux, then enter
pwshin the terminal to launch PowerShell.
- Follow the guide here to install PowerShell on Linux, then enter
You will also need to prepare your API key, which is essential before using the module. A basic understanding of LLM models is also necessary. Most OpenAI services, Azure OpenAI services, and many services similar to OpenAI require a subscription and are not free. The good news is we also support local LLM if you have a powerful GPU machine, which can offer additional functionality.
To install the module, run the following command in PowerShell:
Install-Module -Name code365scripts.openai -Scope CurrentUserYou might want to run Set-ExecutionPolicy RemoteSigned -Scope CurrentUser if you get an error when you run the Install-Module cmdlet.
-
Start a chat experience on your desktop with the
chatcommand, please make sure you set the environment variableOPENAI_API_KEYto your API key before running the command. If you are using Azure OpenAI service or other platform or LLMs rather than OpenAI service, you might want to setOPENAI_API_ENDPOINTandOPENAI_API_MODELvariables. It supportsOpenAI,Azure OpenAI,Databricks,KIMI,Zhipu Qingyan, and a large number of open-source models run byollama(such as llama3, etc.) and any other platforms and large models compatible with OpenAI services. -
Get text completions by using
gptcommand. You can generate any text based on your own prompt in a single line of command.Imagine you need to classify the customer feedback by using GPT technology, then you write back the result in the CSV file. You can achieve the goal with just a single line of code as below.
Import-Csv surveyresult.csv ` | Select-Object Eamil,Feedback, ` @{l="Category";e={gpt -system classifyprompt.md -prompt $_.Feedback}} ` | Export-Csv surveyresult.csv
-
Generate images by using the
imagecommand. It supports the Azure OpenAI service, OpenAI service, currently using theDALL-E-3model.
- Start your desktop ChatGPT journey with a simple command
- Three basic parameters adapted to major platforms and models
- Get Help
- Aliases for commands and parameters
- System and user prompts
- Customizing Settings
- Dynamically passing context data
- Function calls
- What are the limitations of PowerShell 5.1 version?
- Using DALL-E-3 to generate images
- Using local models
- Use environment variables
- Use AAD authentication
- Use in Github Action
We collect telemetry data to help improve the module. The collected data includes command name, alias, service provider, module version, and PowerShell version. You can view the source code here. No personal or input data is collected. If you do not wish to send telemetry data, you can set the environment variable DISABLE_TELEMETRY_OPENAI_POWERSHELL to true.
To update the module, run the following command in PowerShell:
Update-Module -Name code365scripts.openaiTo uninstall the module, run the following command in PowerShell:
Uninstall-Module -Name code365scripts.openai
