blob: 79899cf4eff6bcb0555c6bd6ff5c7971a880c252 (
plain)
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
|
#!/bin/sh
if [ -z "$1" ]
then
echo -n ">"
read prompt
elif [ "$1" = "-1" ]
then
shift
prompt=$1
test -z "$1" || exit 1
else
prompt="$@"
fi
prompt="$(echo "$prompt" | tr "\n\t" ' ' | tr '"' "'")"
API_KEY="$(pass tokens/openai-api)"
data=$(echo \
'{
"prompt": "'"$prompt"'",
"model": "text-davinci-003",
"max_tokens": 1024,
"temperature": 0
}')
output=$(curl -s -X POST \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $API_KEY" \
-d "$data" \
https://api.openai.com/v1/completions \
| jq -r '.choices[0].text')
echo "${output:1}"
|