Created
March 2, 2023 08:40
-
-
Save amn41/0b82b7e78778f3d0c7aa99869bd218f2 to your computer and use it in GitHub Desktop.
chatGPT on the command line - add to your bashrc/zshrc
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
function gpt() { | |
local url="https://api.openai.com/v1/chat/completions" | |
local model="gpt-3.5-turbo" | |
local body="{\"model\":\"$model\", \"messages\":[{\"role\": \"user\", \"content\": \"$1\"}]}" | |
local headers="Content-Type: application/json" | |
local auth="Authorization: Bearer ${OPENAI_API_KEY}" | |
curl -s -H "$headers" -H "$auth" -d "$body" "$url" \ | |
| jq -r '.choices[0].message.content' | |
} |
yes, that's right.
I got the following error:
❯ gpt "hello"
gpt:8: command not found: jq
But really nice idea btw. 👍
@hecker, it looks like jq is not installed on your system. its a tool to parse json. you can install jq like this.
brew install jq # if you are on mac
sudo apt install jq -y # if you are on ubuntu.
I have exported my Open AI API token as an environment variable (OPENAI_API_KEY
). Then I added the function to my .zshrc
. After running ~/.zshrc
and running gpt "hello"
subsequently I am always getting a NULL
return value. How to fix this?
I have the same problem @himalayasharma but when I debug the return I realize that I got the message:
"You exceeded your current quota, please check your plan and billing details.". Check if you have quota too. 😄
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice,
just confirming, this wouldn't handle multi-turn conversations, right? if we want that we need to store the history in the "messages" attribute of the body. correct?