Last active
November 30, 2024 02:51
-
-
Save SCJLabs/fb4e8564222a9ed1d1970caa32936615 to your computer and use it in GitHub Desktop.
Use ChatGPT API from the terminal (MacOS, ZSH)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ChatGPT | |
# Ask ChatGPT questions from your terminal. Results are shown in terminal and markdown is formatted with `glow`. | |
# | |
# Requirements: | |
# 1. In terminal, run: `brew install jq glow` | |
# 2. Get your free API key here from: https://platform.openai.com/account/api-keys | |
# 3. Paste in your API key below. | |
# 3. Paste everything in this gist into your `.zshrc` file. Rename aliases to your liking. | |
# 4. Remember to source your `.zshrc` file using `source ~/.zshrc` or restart terminal for changes to take effect. | |
# | |
# How to Use: | |
# * In terminal, run: `c 'some question to chatgpt'` to ask a question. | |
# * In terminal, run: `cc` to view the last answer. | |
# * In terminal, run: `ccc` to view the last answer and have it read out loud. | |
CHAT_GPT_API_KEY='paste_in_your_api_key_here' | |
alias c='f() { | |
curl --silent https://api.openai.com/v1/chat/completions \ | |
-H "Authorization: Bearer $CHAT_GPT_API_KEY" \ | |
-H "Content-Type: application/json" \ | |
-d "{ \"model\": \"gpt-3.5-turbo\", \"messages\": [{\"role\": \"user\", \"content\": \"$@\"}]}" \ | |
| jq -r ".choices[0].message.content" \ | |
| tee ~/Documents/chat.md \ | |
| glow | |
};f' | |
alias cc='glow ~/Documents/chat.md' | |
alias ccc='glow ~/Documents/chat.md && cat ~/Documents/chat.md | say --rate="200" --voice='Samantha'' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This ai assistant bot does not use real time info.
Though this solution works and invokes a chatgpt call, but if you are looking for a bot that can take in real time updates, this is not the solution.