From d19590d84386454b3a5e73fc98e1d65ea0e5d53c Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Mon, 3 Apr 2023 12:58:44 +0800 Subject: Improve gpt --- X11/openbox/rc.xml | 10 ++++++++++ bin/gpt/gpt | 7 +++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/X11/openbox/rc.xml b/X11/openbox/rc.xml index b549074..eeddf6a 100644 --- a/X11/openbox/rc.xml +++ b/X11/openbox/rc.xml @@ -653,6 +653,16 @@ + + + alacritty --hold --title GPT \ + -o "window.dimensions.columns=70" \ + -o "window.dimensions.lines=30" \ + -e ~/helper/bin/gpt/gpt + + + + color-gpick diff --git a/bin/gpt/gpt b/bin/gpt/gpt index 0383dd0..a3bfa48 100755 --- a/bin/gpt/gpt +++ b/bin/gpt/gpt @@ -5,6 +5,7 @@ # https://help.openai.com/en/articles/6654000-best-practices-for-prompt-engineering-with-openai-api # - Cowork with https://github.com/openai/chatgpt-retrieval-plugin # - History for prompt +# - Mac/BSD compatible # Necessary commands stacks=( curl jq sed ) @@ -29,6 +30,7 @@ _print_helper_message() { cat < Env: OPENAI_API_KEY Generate API key from https://platform.openai.com/account/api-keys @@ -206,7 +208,7 @@ _process_completion() { # Check OPENAI API KEY in env # Exit with 6 (configuration issue) if it is not set -[ -z "$OPENAI_API_KEY" ] && which token &>/dev/null && OPENAI_API_KEY=$(token openai) +[ -z "$OPENAI_API_KEY" ] && OPENAI_API_KEY=$(cat $XDG_CONFIG_HOME/openai/key) [ -z "$OPENAI_API_KEY" ] && { echo API KEY not specified; exit 6; } # Parse arguments @@ -285,7 +287,8 @@ stream=${stream:-false} INDEX= # Prepare for chat session -cache=$(mktemp -t gpt.XXXXXX) && touch "$cache" +CACHE_DIR=${CACHE_DIR:-/tmp} +cache=$(mktemp -t gpt.XXXXXX -p ${CACHE_DIR}) && touch "$cache" #trap "rm $cache" EXIT session=() -- cgit v1.2.3-70-g09d2