OpenAI at your Fingertips! ✨
using PowerShell
• Documentation •
- I created a new module called PowerShellAIAssistant.
- You can get it:
Install-Module -Name PowerShellAIAssistant - Highly recommend you check it out.
You can just type 'ai "your question here"' and it will return an answer.
The module exposes a lot of handy functions that interact directly with the new Assistants API, so you can also build scripts or spin up and manage different assistants/threads yourself.
The Assistants API is a tool that lets you create your own AI assistants in your applications.
Think of it as building a digital helper that can follow instructions and use different tools and knowledge to answer questions or solve problems.
It has three types of tools for different tasks like coding, information retrieval, and executing specific functions.
OpenAI is adding more, and you'll also be able to add your own tools to customize your assistant's abilities.
All can programmatically automate via PowerShell.
PowerShellAI is a community-maintained PowerShell module designed to simplify the use of OpenAI's GPT-3 language model and DALL-E API. It empowers users to effortlessly build complex language-powered applications, regardless of their level of experience.
PowerShellAI is cross-platform and runs seamlessly on Windows, Linux, and MacOS.
Getting started with PowerShellAI is easy. Simply install the module from the gallery using the following command:
Install-Module -Name PowerShellAI
The repository includes a comprehensive list of functions that enable users to interact with GPT-3 and DALL-E, along with examples of how to use them at the command line or in scripts.
The video demos showcase the many possibilities of the module and how you can leverage its functions to best suit your needs.
Whether you're a seasoned developer or just getting started with AI, PowerShellAI is a valuable tool that can help you unlock the full potential of OpenAI's GPT-3 and DALL-E.
Welcome to the PowerShell Artificial Intelligence repository! Here, you will find a collection of powerful PowerShell scripts that will enable you to easily integrate AI into your projects and take them to the next level. Imagine being able to interact directly with OpenAI's GPT AI with just a few simple commands. With this module, it's now possible.
By using this module, you'll have the ability to add cutting-edge AI functionality to your projects without needing to have a deep understanding of the underlying technology. This means you can stay focused on what you do best while still being able to work with the latest and greatest.
In the PowerShell console:
Install-Module -Name PowerShellAIGet/Create your OpenAI API key from https://platform.openai.com/account/api-keys and then set as secure string with Set-OpenAIKey or as plain text with $env:OpenAIKey.
| PS Script | Description | Location |
|---|---|---|
| ai | Experimental AI function that you can pipe all sorts of things into and get back a completion | ai.ps1 |
| copilot | Makes the request to GPT, parses the response and displays it in a box and then prompts the user to run the code or not. | copilot.ps1 |
Get-GPT3Completion - alias gpt |
Get a completion from the OpenAI GPT-3 API | Get-GPT3Completion.ps1 |
| Invoke-AIErrorHelper | Helper function let ChatGPT add more info about errors | Invoke-AIErrorHelper.ps1 |
| Invoke-AIExplain | Utilizes the OpenAI GPT-3 API to offer explanations for the most recently run command, and more. | Invoke-AIExplain.ps1 |
| Get-OpenAIEdit | Given a prompt and an instruction, the model will return an edited version of the prompt | Get-OpenAIEdit.ps1 |
| Get-DalleImage | Get an image from the OpenAI DALL-E API | Get-DalleImage.ps1 |
| Get-AOAIDalleImage | Get an image from the Azure OpenAI DALL-E API | Get-AOAIDalleImage.ps1 |
| Set-DalleImageAsWallpaper | Set the image from the OpenAI DALL-E API as the wallpaper | Set-DalleImageAsWallpaper.ps1 |
| Get-OpenAIUsage | Returns a billing summary of OpenAI API usage for your organization | |
| Disable-AIShortCutKey | Disable the ctrl+g shortcut key go getting completions | Disable-AIShortCutKey.ps1 |
| Enable-AIShortCutKey | Enable the ctrl+g | Enable-AIShortCutKey.ps1 |
| PS Script | Description | Location |
|---|---|---|
| ai | Experimental AI function that you can pipe all sorts of things into and get back a completion | ai.ps1 |
| copilot | Makes the request to GPT, parses the response and displays it in a box and then prompts the user to run the code or not. | copilot.ps1 |
Get-GPT3Completion - alias gpt |
Get a completion from the OpenAI GPT-3 API | Get-GPT3Completion.ps1 |
| Invoke-AIErrorHelper | Helper function let ChatGPT add more info about errors | Invoke-AIErrorHelper.ps1 |
| Invoke-AIExplain | Utilizes the OpenAI GPT-3 API to offer explanations for the most recently run command, and more. | Invoke-AIExplain.ps1 |
| Get-OpenAIEdit | Given a prompt and an instruction, the model will return an edited version of the prompt | Get-OpenAIEdit.ps1 |
| Get-DalleImage | Get an image from the OpenAI DALL-E API | Get-DalleImage.ps1 |
| Set-DalleImageAsWallpaper | Set the image from the OpenAI DALL-E API as the wallpaper | Set-DalleImageAsWallpaper.ps1 |
| Get-OpenAIUsage | Returns a billing summary of OpenAI API usage for your organization | |
| Disable-AIShortCutKey | Disable the ctrl+g shortcut key go getting completions | Disable-AIShortCutKey.ps1 |
| Enable-AIShortCutKey | Enable the ctrl+g | Enable-AIShortCutKey.ps1 |
| Notebook | Description | Location |
|---|---|---|
| OpenAI Settings | A notebook shows how to get OpenAI dashboard info | Settings.ipynb |
Here are some videos of PowerShellAI in action:
set-chatAPIProvider AzureOpenAI# Setting AzureOpenAI parameters
Set-AzureOpenAI -ApiKey 'API Key' -Endpoint https://endpoint.azure-api.net -DeploymentName gpt-35-turbo-16k -ApiVersion 2023-03-15-previewSet-ChatAPIProvider OpenAI# Fetch 'OpenAIKey' which is stored in the System environment variables
$pass = [Environment]::GetEnvironmentVariable('OpenAIKey', 'Machine')# Set 'OpenAIKey'
Set-OpenAIKey -Key ($pass | ConvertTo-SecureString -AsPlainText -Force)Note: One of the above chat API provider has to be set before executing any of the below commands.
Note: You can use the
gptalias forGet-GPT3Completion
Get-GPT3Completion "list of planets only names as json"
[
"Mercury",
"Venus",
"Earth",
"Mars",
"Jupiter",
"Saturn",
"Uranus",
"Neptune"
]Get-GPT3Completion "list of planets only names as xml"
<?xml version="1.0" encoding="UTF-8"?>
<planets>
<planet>Mercury</planet>
<planet>Venus</planet>
<planet>Earth</planet>
<planet>Mars</planet>
<planet>Jupiter</planet>
<planet>Saturn</planet>
<planet>Uranus</planet>
<planet>Neptune</planet>
</planets> Get-GPT3Completion "first 5 US presidents and terms as markdown table"
| President | Term |
|----------|------|
| George Washington | 1789-1797 |
| John Adams | 1797-1801 |
| Thomas Jefferson | 1801-1809 |
| James Madison | 1809-1817 |
| James Monroe | 1817-1825 |Copy and pasted into this README.md:
| President | Term |
|---|---|
| George Washington | 1789-1797 |
| John Adams | 1797-1801 |
| Thomas Jefferson | 1801-1809 |
| James Madison | 1809-1817 |
| James Monroe | 1817-1825 |
The ai function calls that allows piping and prompting text. This is useful for chaining commands together.
ai "list of planets only names as json"["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"]ai "list of planets only names as json" | ai 'convert to xml'<?xml version="1.0" encoding="UTF-8"?>
<Planets>
<Planet>Mercury</Planet>
<Planet>Venus</Planet>
<Planet>Earth</Planet>
<Planet>Mars</Planet>
<Planet>Jupiter</Planet>
<Planet>Saturn</Planet>
<Planet>Uranus</Planet>
<Planet>Neptune</Planet>
</Planets>ai "list of planets only names as json" | ai 'convert to xml' | ai 'convert to powershell'[xml]$xml = @"
<?xml version="1.0" encoding="UTF-8"?>
<Planets>
<Planet>Mercury</Planet>
<Planet>Venus</Planet>
<Planet>Earth</Planet>
<Planet>Mars</Planet>
<Planet>Jupiter</Planet>
<Planet>Saturn</Planet>
<Planet>Uranus</Planet>
<Planet>Neptune</Planet>
</Planets>
"@
$xml.Planets.PlanetPipe the output of git status to ai to create a commit message.
git status | ai "create a detailed git message"Commit message:
Added PowerShellAI.psd1, README.md, changelog.md, and Public/ai.ps1 to dcf-spike-piping-to-ai-function branch. Updated PowerShellAI.psd1 and README.md with new changes. Added changelog.md to track changes. Added Public/ai.ps1 to enable piping to AI function.
Thank you to Clem Messerli for posting a great prompt to show copilot in action.
Check out the video of copilot in action
If you get an error after executing some PowerShell. You can now ask ChatGPT for help. The new Invoke-AIErrorInsights function will take the last error message and ask ChatGPT for help.
You can also use the alias ieh.
Unlike completions, edits takes two inputs: the text to edit and an instruction. Here the model is set to code-davinci-edit-001 because we're working with PowerShell code.
- Here you're passing in the string (
InputText) that is a PowerShell function. - The
instructionis toadd a comment-based help detailed description
Get-OpenAIEdit -InputText @'
function greet {
param($n)
"Hello $n"
}
'@ -Instruction 'add comment-based help detailed description'The GPT AI returns:
<#
.SYNOPSIS
Greet someone
.DESCRIPTION
This function greets someone
.PARAMETER n
The name of the person to greet
.EXAMPLE
greet -n "John"
.NOTES
This is a note
#>
function greet {
param($n)
"Hello $n"
}Creates a new spreadsheet from a prompt
Note: This requires the ImportExcel module to be installed
Install-Module -Name ImportExcelIn action:
New-Spreadsheet 'population of india, china, usa, euroupe'Try it out: New-Spreadsheet "list of first 5 US presidents name, term"
The DALL-E API provides access to two different models for generating images from textual descriptions: DALL-E 2 and DALL-E 3. Each model has its own features and capabilities, and usage might differ slightly.
To generate images using DALL-E 2, you can utilize the Get-DalleImage function with the following parameters specific to DALL-E 2:
Get-DalleImage -Description "<description>" -Size "1024" -ModelVersion "2"The -Size parameter specifies the image dimensions and supports 256, 512, or 1024 (where the image will be square), and the -ModelVersion should be set to "2".
For generating images with DALL-E 3, the function accepts different parameters that provide more options for the output image:
Get-DalleImage -Description "<description>" -Orientation "landscape" -Quality "hd" -Style "natural" -ModelVersion "3"In DALL-E 3, -Orientation determines the aspect ratio and size of the image (landscape will produce 1792x1024, portrait 1024x1792, and square 1024x1024). The -Quality parameter allows you to specify image quality as either "hd" (high definition) or "standard", and the -Style parameter lets you choose the visual style of the image - "natural" for realistic images or "vivid" for more dramatic imagery. The -ModelVersion should be set to "3".
For both versions, replace <description> with a text description of the image you want to generate. The generated image will be saved to a temporary file, and the path to this file will be returned by the function.
Azure OpenAI DALL-E provides additional options for text to image generation. Images will by default be put in an Images directory under your script path.
- Use -Images to specify how many images to generate for the same description
- Use -Raw to return the raw image data and not output to a PNG file
Get-AOAIDalleImage -Description "a painting of the Sydney Opera house in the style of Rembrant on a sunny day"Get-AOAIDalleImage -Description "a painting of the Sydney Opera house in the style of Rembrant on a sunny day" -Images 3









