-
Notifications
You must be signed in to change notification settings - Fork 17
/
i-ask.sh
38 lines (28 loc) · 872 Bytes
/
i-ask.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
if [ -z "$OPENAI_API_KEY" ]; then
echo "WARNING: OPENAI_API_KEY environment variable is not set."
exit 1
fi
if [ "$(uname)" == "Darwin" ]; then
# This is a Mac, so use Homebrew
echo "Installing jq with Homebrew..."
brew install jq
else
# Assume this is a Linux system and use apt-get
echo "Installing jq with apt-get..."
sudo apt-get update
sudo apt-get install jq
fi
OPENAI_API_KEY=$OPENAI_API_KEY
QUERY=$1
RESPONSE=$(curl -s https://api.openai.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "system", "content": "'"$QUERY"'"}]
}')
CONTENT=$(echo $RESPONSE | jq -r '.choices[0].message.content')
header="\xF0\x9F\x98\x84"
output="${header}\n\n$CONTENT\n\n"
echo -e "\n" "$output"