Skip to content

Unofficial PowerShell Module for OpenAI, Azure OpenAI and almost all the GPT services or even local LLMs

License

Notifications You must be signed in to change notification settings

chenxizhang/openai-powershell

Repository files navigation

PowerShell Gallery Version PowerShell Gallery

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.

Prerequisites

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/powershell to install PowerShell on MacOS, then enter pwsh in the terminal to launch PowerShell. Follow the guide here if you encountered any problem.
  • Linux:
    • Follow the guide here to install PowerShell on Linux, then enter pwsh in the terminal to launch PowerShell.

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.

Install the Module

To install the module, run the following command in PowerShell:

Install-Module -Name code365scripts.openai -Scope CurrentUser

You might want to run Set-ExecutionPolicy RemoteSigned -Scope CurrentUser if you get an error when you run the Install-Module cmdlet.

Quick Start

  1. Start a chat experience on your desktop with the chat command, please make sure you set the environment variable OPENAI_API_KEY to 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 set OPENAI_API_ENDPOINT and OPENAI_API_MODEL variables. It supports OpenAI, Azure OpenAI, Databricks, KIMI, Zhipu Qingyan, and a large number of open-source models run by ollama (such as llama3, etc.) and any other platforms and large models compatible with OpenAI services.

    GIF 5-5-2024 10-49-20 PM

  2. Get text completions by using gpt command. You can generate any text based on your own prompt in a single line of command.

    image

    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
  3. Generate images by using the image command. It supports the Azure OpenAI service, OpenAI service, currently using the DALL-E-3 model.

    image

User Manual in details

  1. Start your desktop ChatGPT journey with a simple command
  2. Three basic parameters adapted to mainstream platforms and models
  3. Get Help
  4. Aliases for commands and parameters
  5. System and user prompts
  6. Customizing Settings
  7. Dynamically passing context data
  8. Function calls
  9. What are the limitations of PowerShell 5.1 version?
  10. Using DALL-E-3 to generate images
  11. Using local models
  12. Use environment variables

Telemetry Data Collection and Privacy

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.

Update the Module

To update the module, run the following command in PowerShell:

Update-Module -Name code365scripts.openai

Uninstall the Module

To uninstall the module, run the following command in PowerShell:

Uninstall-Module -Name code365scripts.openai

About

Unofficial PowerShell Module for OpenAI, Azure OpenAI and almost all the GPT services or even local LLMs

Topics

Resources

License

Stars

Watchers

Forks