aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2023-03-24 00:04:01 +0800
committerHsieh Chin Fan <pham@topo.tw>2023-03-24 00:05:29 +0800
commitf8d6037a989e40425f2faa09c6eb892de0c83509 (patch)
tree22c41cd15d55096ac1f3c8eaa9b1fb2838b93a8a
parentef15e9716a9d5803671e6a4741cacfa42aaf97ed (diff)
Update
-rwxr-xr-xbin/gpt/gpt23
1 files changed, 21 insertions, 2 deletions
diff --git a/bin/gpt/gpt b/bin/gpt/gpt
index 4d0f651..1fa78d7 100755
--- a/bin/gpt/gpt
+++ b/bin/gpt/gpt
@@ -5,18 +5,35 @@
5# https://help.openai.com/en/articles/6654000-best-practices-for-prompt-engineering-with-openai-api 5# https://help.openai.com/en/articles/6654000-best-practices-for-prompt-engineering-with-openai-api
6# - Print token usage when exit 6# - Print token usage when exit
7 7
8# Necessary commands
9stacks=( curl jq )
10
8# User can dynamically change these options for API call 11# User can dynamically change these options for API call
9configurable_options=( behavior temperature max_tokens ) 12configurable_options=( behavior temperature max_tokens )
10 13
11# If script is interupt by SIGINT, simply print leave message 14# If script is interupt by SIGINT, simply print leave message
12trap _print_leave_message INT 15trap _print_leave_message INT
13 16
17_check_stacks() {
18 # Print all available options
19 index=0
20 for command in "${stacks[@]}"; do
21 which "$command" &>/dev/null && continue
22 echo "$command" is needed
23 exit 1
24 done
25}
26
14# Function for printing helper message 27# Function for printing helper message
15_print_helper_message() { 28_print_helper_message() {
16 cat <<EOF 29 cat <<EOF
17Usage: gpt [-h] [-m MODEL] [-m4] [-b BEHAVIOR] [-t temperature] 30Usage: gpt [-h] [-m MODEL] [-m4] [-b BEHAVIOR] [-t temperature]
18 [-M MAX_TOKENS] [-s] [MESSAGE] 31 [-M MAX_TOKENS] [-s] [MESSAGE]
19 32
33Env:
34 OPENAI_API_KEY (Required)
35 Generate API key from https://platform.openai.com/account/api-keys
36
20Options: 37Options:
21 -h, --help show this help message and exit 38 -h, --help show this help message and exit
22 39
@@ -111,10 +128,9 @@ _get_content() {
111} 128}
112 129
113# Check OPENAI API KEY"Department:" 3 1 "" 3 15 25 0 130# Check OPENAI API KEY"Department:" 3 1 "" 3 15 25 0
114[ -z "$OPENAI_API_KEY" ] && OPENAI_API_KEY=$(token openai) 131[ -z "$OPENAI_API_KEY" ] && which token &>/dev/null && OPENAI_API_KEY=$(token openai)
115[ -z "$OPENAI_API_KEY" ] && { echo API KEY not specified; exit 1; } 132[ -z "$OPENAI_API_KEY" ] && { echo API KEY not specified; exit 1; }
116 133
117
118# Parse arguments 134# Parse arguments
119while [ "$#" -gt 0 ]; do 135while [ "$#" -gt 0 ]; do
120 case "$1" in 136 case "$1" in
@@ -154,6 +170,9 @@ while [ "$#" -gt 0 ]; do
154 esac 170 esac
155done 171done
156 172
173# Make sure necessary commands exist
174_check_stacks
175
157# Set variables in API calls 176# Set variables in API calls
158ROUTE=v1/chat/completions 177ROUTE=v1/chat/completions
159model=${model:-gpt-3.5-turbo} 178model=${model:-gpt-3.5-turbo}