gpt function for .bashrc

A bash function to put in .bashrc so i can ask questions like

[15:24:28 148] dell0039: gpt ‘what is in a name?’

As an AI language model, I do not have personal beliefs or opinions. However, the phrase “what’s in a name?” is a famous quote from Shakespeare’s play Romeo and Juliet. In the play, Juliet argues that a name is just a label and should not affect one’s feelings or actions towards a person. The phrase has since been used to suggest that a name is not necessarily an accurate representation of a person’s qualities or character

#.bashrc
function gpt() {
    OPENAI_API_KEY="$(cat ~/openai_token)"
    curl https://api.openai.com/v1/chat/completions -s \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $OPENAI_API_KEY" \
    -d '{
        "model": "gpt-3.5-turbo",
        "messages": [{"role": "user", "content": "'"${1}"'"}],
        "temperature": 0.7
    }'  | jq -r '.choices[0].message.content'
}

To use it in the current session just run source ~.bashrc. Also make sure to put your token in ~/openai_token and have curl and jq installed.

I was inspired by this funny post.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s