blob: 140d9f671148995a87160995ec408906e3a84158 (
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
  | 
#!/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\"" "  '")"
API_KEY="$(pass tokens/openai-api)"
model="text-ada-001"
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}"
  |