Ask-GPT is a PowerShell module that provides a command-line interface to interact with GPT models from OpenAI.
- Query GPT models using various parameters such as model type, temperature, and more.
- Stream responses directly to the console.
- Maintain history of queries and responses.
To install the Ask-GPT module, download the Ask-GPT.psm1
file and import the module using PowerShell:
Import-Module /path/to/Ask-GPT.psm1
To pipe input directly to Ask-GPT:
"what is 2+2?" | Ask-GPT
To use the shorter gpt
alias for piping, first set up an alias in your shell:
Set-Alias -Name gpt -Value Ask-GPT
Then you can pipe to the alias:
"what is 2+2?" | gpt
Example command to query GPT:
Ask-GPT -Prompt "Your question here" -Model "gpt-4"
Or using the shorter alias:
gpt "Your question here"
- PowerShell 7.5.0 or later
- OpenAI API key set in environment variables:
OPENAI_PERSONAL_API_KEY
(checked first) OROPENAI_API_KEY
(fallback if personal key not found)
- Obtain an API key from the OpenAI platform.
- Set environment variables using either of the methods below:
- Single Session: Run this in your PowerShell session:
$env:OPENAI_PERSONAL_API_KEY = 'YOUR_KEY_HERE'
- Permanent (MacOS/Linux): Add the following line to your
.zshrc
or.bashrc
file:export OPENAI_PERSONAL_API_KEY='YOUR_KEY_HERE'
- Permanent (Windows): Run the following PowerShell command to set it persistently:
[System.Environment]::SetEnvironmentVariable('OPENAI_PERSONAL_API_KEY', 'YOUR_KEY_HERE', [System.EnvironmentVariableTarget]::User)
- Single Session: Run this in your PowerShell session:
- Verify the setup:
echo $env:OPENAI_PERSONAL_API_KEY
- OPENAI_PERSONAL_API_KEY is checked first
- OPENAI_API_KEY is the fallback option if the personal key isn't set
- API Key Errors:
- Ensure API keys are correctly set as environment variables. Recheck using:
echo $env:OPENAI_PERSONAL_API_KEY
- Verify you can access the OpenAI platform directly.
- Ensure API keys are correctly set as environment variables. Recheck using:
- Module Issues:
- Ensure PowerShell 7.5.0+ for best ANSI support.
- Run
Invoke-ScriptAnalyzer
for script compliance.
- Open a GitHub issue with detailed logs.
- Send an email to [email protected].
We appreciate your interest in contributing to Ask-GPT!
- Fork the repository on GitHub.
- Create a new feature branch from
main
. - Develop your feature and cross-check against PSScriptAnalyzer.
- Submit a pull request with a clear description of changes.
Please adhere to the Code of Conduct when contributing.
For suggestions, feel free to open an issue or a discussion on GitHub.