-
-
Save eSlider/b5b509dfcb59dca25e36517b0512de65 to your computer and use it in GitHub Desktop.
OpenAI Chat CLI
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
#!/bin/bash | |
## Install | |
# apt-get install -y jq | |
## Create an key here: https://beta.openai.com/account/api-keys | |
export OPENAI_API_KEY='sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' | |
## AI Model | |
model=text-davinci-003 | |
## Call API and save results | |
response=$(curl -s https://api.openai.com/v1/completions \ | |
-H "Content-Type: application/json" \ | |
-H "Authorization: Bearer $OPENAI_API_KEY" \ | |
-d "{\"model\": \"$model\", \"prompt\": \"$1\", \"temperature\": 0.5, \"max_tokens\": 1024}") | |
## Save prompt into history | |
echo "$1" | jq . >> ~/.openai-gpt-3-history | |
echo ";\n\n\n\n" >> ~/.openai-gpt-3-history | |
## Save result into history | |
echo "$response" | jq . >> ~/.openai-gpt-3-history | |
echo ";\n\n\n\n" >> ~/.openai-gpt-3-history | |
# Show only first result | |
echo "$response" | jq -r .choices[0].text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment