-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenai-shell
executable file
·40 lines (35 loc) · 1.05 KB
/
openai-shell
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
39
40
#!/bin/bash
###
engine=${engine-curie}
## Can be any of the following:
### (ascending in complexity/cost/speed/specialization):
#### ada, babbage, curie, davinci
SK=$(cat $HOME/.oaisk)
ai_request() {
curl -sS https://api.openai.com/v1/engines/$1 \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $SK" \
-d "$2"
}
completion_tool() {
prompt="$1"
# Our desired added token count + our initial prompt token count
max_tokens=$(expr $2 + $(wc -w <<<"$prompt"))
echo $max_tokens
json='{"prompt": "'$prompt'", "max_tokens": '$max_tokens'}'
response=$(ai_request "$engine/completions" "$json")
text=$(jq -r '.choices[] | .text' <<<$response)
echo $prompt$text
}
answer_tool() {
#TODO
prompt="$1"
# Our desired added token count + our initial prompt token count
max_tokens=$(expr $2 + $(wc -w <<<"$prompt"))
echo $max_tokens
json='{"prompt": "'$prompt'", "max_tokens": '$max_tokens'}'
response=$(ai_request "$engine/completions" "$json")
text=$(jq -r '.choices[] | .text' <<<$response)
echo $prompt$text
}
completion_tool "$1" "$2"