blob: 9fb04cea0df03d385df5739931f568a1c426e4c6 (
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
35
36
|
#!/bin/sh
# requirements
which pass jq > /dev/null ||
exit 1
# input
test -z "${inp:=$@}" &&
inp="$(cat /dev/stdin)"
# \n\t -> ' ' && "->'
prompt="$(echo "$inp" | tr "\n\t\"" " '")"
test -z "$prompt" && exit 1
API_KEY="$(pass tokens/openai-api)"
model="text-davinci-003"
tokens="1024"
temperature=0
data=$(echo \
'{
"prompt": "'"$prompt"'",
"model": "'"$model"'",
"max_tokens": '$tokens',
"temperature": '$temperature'
}')
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')
# remove newline
echo "${output:1}"
|