This shell script provides a command-line interface to interact with OpenAI's GPT models, allowing users to have conversations and get AI-generated responses directly in their terminal.
- Interact with OpenAI's GPT models through the command line
- Maintain conversation history across multiple interactions
- Clear conversation history when needed
- Bash shell
curl
for making HTTP requestsjq
for JSON parsing- An OpenAI API key
- Clone this repository or download the script file.
- Make the script executable:
chmod +x ai.sh
- Set up your OpenAI API key as an environment variable:
For permanent setup, add this line to your
export OPENAI_API_KEY='your-api-key-here'
~/.bashrc
or~/.zshrc
file. - You may want to copy the script into your path:
sudo cp ai.sh /usr/local/bin/ai
./ai.sh "Your prompt or question here"
./ai.sh --clear-history
The script uses the following configuration:
- Model: GPT-4o-mini (can be changed in the script)
- History file:
~/.conversation_history.txt
You can modify these settings by editing the script.
If you encounter any issues:
- Ensure your OpenAI API key is correctly set.
- Check that you have the latest versions of
curl
andjq
installed. - Verify that the
~/.conversation_history.txt
is writable
Contributions, issues, and feature requests are welcome.