This script sends a prompt to the OpenAI API and receives a response using the text-davinci-003 model.
- jq command-line JSON processor
Using Homebrew:
brew install jq
sudo apt-get update && sudo apt-get install jq
sudo yum install jq
- Place the TerminalGPT.sh script in a directory of your choice.
- Make the script executable:
chmod +x /path/to/your/TerminalGPT.sh
Replace /path/to/your/ with the actual path to the directory containing the TerminalGPT.sh script.
- Open your shell's configuration file: For Bash: ~/.bashrc For Zsh: ~/.zshrc
- Add the following lines at the end of the file:
# OpenAI TerminalGPT Script
alias chat="/path/to/your/openai_request.sh"
export OPENAI_API_KEY="your_api_key_here"
Replace /path/to/your/ with the actual path to the directory containing the openai_request.sh script, and your_api_key_here with your actual OpenAI API key.
- Save the file and close the editor.
- Reload the shell's configuration file: For Bash: source ~/.bashrc For Zsh: source ~/.zshrc
To use the script, simply call the chat alias followed by your prompt:
chat How are you today?
The script will send the prompt to the OpenAI API and display the message in the terminal.