From f8d6037a989e40425f2faa09c6eb892de0c83509 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Fri, 24 Mar 2023 00:04:01 +0800 Subject: Update --- bin/gpt/gpt | 23 +++++++++++++++++++++-- 1 file 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 @@ # https://help.openai.com/en/articles/6654000-best-practices-for-prompt-engineering-with-openai-api # - Print token usage when exit +# Necessary commands +stacks=( curl jq ) + # User can dynamically change these options for API call configurable_options=( behavior temperature max_tokens ) # If script is interupt by SIGINT, simply print leave message trap _print_leave_message INT +_check_stacks() { + # Print all available options + index=0 + for command in "${stacks[@]}"; do + which "$command" &>/dev/null && continue + echo "$command" is needed + exit 1 + done +} + # Function for printing helper message _print_helper_message() { cat </dev/null && OPENAI_API_KEY=$(token openai) [ -z "$OPENAI_API_KEY" ] && { echo API KEY not specified; exit 1; } - # Parse arguments while [ "$#" -gt 0 ]; do case "$1" in @@ -154,6 +170,9 @@ while [ "$#" -gt 0 ]; do esac done +# Make sure necessary commands exist +_check_stacks + # Set variables in API calls ROUTE=v1/chat/completions model=${model:-gpt-3.5-turbo} -- cgit v1.2.3-70-g09d2