mirror of
https://github.com/0xacx/chatGPT-shell-cli.git
synced 2025-02-23 02:55:29 +00:00
28 lines
714 B
Bash
Executable File
28 lines
714 B
Bash
Executable File
#!/bin/bash
|
|
echo -e "Welcome to chatgpt. You can quit with '\033[36mexit\033[0m'."
|
|
running=true
|
|
|
|
while $running; do
|
|
echo -e "\nEnter a prompt:"
|
|
read prompt
|
|
|
|
if [ "$prompt" == "exit" ]; then
|
|
running=false
|
|
else
|
|
# escape quotation marks
|
|
escaped_prompt=$(echo "$prompt" | sed 's/"/\\"/g')
|
|
# request to OpenAI API
|
|
response=$(curl https://api.openai.com/v1/completions \
|
|
-sS \
|
|
-H 'Content-Type: application/json' \
|
|
-H "Authorization: Bearer $OPENAI_TOKEN" \
|
|
-d '{
|
|
"model": "text-davinci-003",
|
|
"prompt": "'"${escaped_prompt}"'",
|
|
"max_tokens": 1000,
|
|
"temperature": 0.7
|
|
}' | jq -r '.choices[].text' | sed '1,2d')
|
|
|
|
echo -e "\n\033[36mchatgpt \033[0m${response}"
|
|
fi
|
|
done |