summaryrefslogtreecommitdiff
path: root/bin/common
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2023-03-08 01:34:54 +0100
committerRaymaekers Luca <raymaekers.luca@gmail.com>2023-03-08 01:39:20 +0100
commit2b38ce5ff4754f3edcfea25ea06ca23a7354ae7d (patch)
tree7bd4ba2f83da33a14cf75fa94d565a084d4e0de3 /bin/common
parente5bf705060f230750950571a04a259b8eac48459 (diff)
remade ask to be more versatile
Diffstat (limited to 'bin/common')
-rwxr-xr-xbin/common/ask33
1 files changed, 17 insertions, 16 deletions
diff --git a/bin/common/ask b/bin/common/ask
index 79899cf..140d9f6 100755
--- a/bin/common/ask
+++ b/bin/common/ask
@@ -1,27 +1,27 @@
#!/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 '"' "'")"
+# 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": "text-davinci-003",
- "max_tokens": 1024,
- "temperature": 0
+ "model": "'"$model"'",
+ "max_tokens": '$tokens',
+ "temperature": '$temperature'
}')
output=$(curl -s -X POST \
@@ -31,4 +31,5 @@ output=$(curl -s -X POST \
https://api.openai.com/v1/completions \
| jq -r '.choices[0].text')
+# remove newline
echo "${output:1}"