diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2023-04-03 12:58:44 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2023-04-03 12:58:44 +0800 |
| commit | d19590d84386454b3a5e73fc98e1d65ea0e5d53c (patch) | |
| tree | 03b370a8d664f245762d825a49eec74b1a886d2e | |
| parent | 82c0218092eba079c440b891df21e31b5c5ee610 (diff) | |
Improve gpt
| -rw-r--r-- | X11/openbox/rc.xml | 10 | ||||
| -rwxr-xr-x | 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 | |||
| @@ -654,6 +654,16 @@ | |||
| 654 | </keybind> | 654 | </keybind> |
| 655 | <keybind key="W-g"> | 655 | <keybind key="W-g"> |
| 656 | <action name="Execute"> | 656 | <action name="Execute"> |
| 657 | <command> | ||
| 658 | alacritty --hold --title GPT \ | ||
| 659 | -o "window.dimensions.columns=70" \ | ||
| 660 | -o "window.dimensions.lines=30" \ | ||
| 661 | -e ~/helper/bin/gpt/gpt | ||
| 662 | </command> | ||
| 663 | </action> | ||
| 664 | </keybind> | ||
| 665 | <keybind key="W-S-g"> | ||
| 666 | <action name="Execute"> | ||
| 657 | <command>color-gpick</command> | 667 | <command>color-gpick</command> |
| 658 | </action> | 668 | </action> |
| 659 | </keybind> | 669 | </keybind> |
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 @@ | |||
| 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 | # - Cowork with https://github.com/openai/chatgpt-retrieval-plugin | 6 | # - Cowork with https://github.com/openai/chatgpt-retrieval-plugin |
| 7 | # - History for prompt | 7 | # - History for prompt |
| 8 | # - Mac/BSD compatible | ||
| 8 | 9 | ||
| 9 | # Necessary commands | 10 | # Necessary commands |
| 10 | stacks=( curl jq sed ) | 11 | stacks=( curl jq sed ) |
| @@ -29,6 +30,7 @@ _print_helper_message() { | |||
| 29 | cat <<EOF | 30 | cat <<EOF |
| 30 | Usage: gpt [-h] [-m MODEL] [-m4] [-b BEHAVIOR] [-t temperature] | 31 | Usage: gpt [-h] [-m MODEL] [-m4] [-b BEHAVIOR] [-t temperature] |
| 31 | [-M MAX_TOKENS] [-s] [MESSAGE] | 32 | [-M MAX_TOKENS] [-s] [MESSAGE] |
| 33 | gpt <SUBCOMMAND> | ||
| 32 | 34 | ||
| 33 | Env: | 35 | Env: |
| 34 | OPENAI_API_KEY Generate API key from https://platform.openai.com/account/api-keys | 36 | OPENAI_API_KEY Generate API key from https://platform.openai.com/account/api-keys |
| @@ -206,7 +208,7 @@ _process_completion() { | |||
| 206 | 208 | ||
| 207 | # Check OPENAI API KEY in env | 209 | # Check OPENAI API KEY in env |
| 208 | # Exit with 6 (configuration issue) if it is not set | 210 | # Exit with 6 (configuration issue) if it is not set |
| 209 | [ -z "$OPENAI_API_KEY" ] && which token &>/dev/null && OPENAI_API_KEY=$(token openai) | 211 | [ -z "$OPENAI_API_KEY" ] && OPENAI_API_KEY=$(cat $XDG_CONFIG_HOME/openai/key) |
| 210 | [ -z "$OPENAI_API_KEY" ] && { echo API KEY not specified; exit 6; } | 212 | [ -z "$OPENAI_API_KEY" ] && { echo API KEY not specified; exit 6; } |
| 211 | 213 | ||
| 212 | # Parse arguments | 214 | # Parse arguments |
| @@ -285,7 +287,8 @@ stream=${stream:-false} | |||
| 285 | INDEX= | 287 | INDEX= |
| 286 | 288 | ||
| 287 | # Prepare for chat session | 289 | # Prepare for chat session |
| 288 | cache=$(mktemp -t gpt.XXXXXX) && touch "$cache" | 290 | CACHE_DIR=${CACHE_DIR:-/tmp} |
| 291 | cache=$(mktemp -t gpt.XXXXXX -p ${CACHE_DIR}) && touch "$cache" | ||
| 289 | #trap "rm $cache" EXIT | 292 | #trap "rm $cache" EXIT |
| 290 | session=() | 293 | session=() |
| 291 | 294 | ||