diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2023-03-30 14:20:25 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2023-03-30 14:20:25 +0800 |
| commit | e4ad7fed9e02b743221a6859a2e78bb5592569fe (patch) | |
| tree | a1d0547a564f3b24969e75924fcb385135ef16f2 | |
| parent | 5e3aab3eaf7e6f40b32ae455e216c63dd7d2a56e (diff) | |
Add more options into gpt
| -rwxr-xr-x | bin/gpt/gpt | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/bin/gpt/gpt b/bin/gpt/gpt index e44d756..09bb323 100755 --- a/bin/gpt/gpt +++ b/bin/gpt/gpt | |||
| @@ -10,8 +10,8 @@ | |||
| 10 | stacks=( curl jq sed ) | 10 | stacks=( curl jq sed ) |
| 11 | 11 | ||
| 12 | # User can dynamically change these options for API call | 12 | # User can dynamically change these options for API call |
| 13 | configurable_options=( model behavior temperature max_tokens stream context ) | ||
| 14 | 13 | ||
| 14 | configurable_options=( model behavior temperature max_tokens stream context ) | ||
| 15 | # If script is interupt by SIGINT, simply print leave message | 15 | # If script is interupt by SIGINT, simply print leave message |
| 16 | trap _print_leave_message INT | 16 | trap _print_leave_message INT |
| 17 | 17 | ||
| @@ -48,6 +48,9 @@ Options: | |||
| 48 | "You are a helpful assistant." | 48 | "You are a helpful assistant." |
| 49 | (Defaults to "You are a helpful programming assistant") | 49 | (Defaults to "You are a helpful programming assistant") |
| 50 | 50 | ||
| 51 | -B|--sys-message Use prompt to set system message (How model behave). | ||
| 52 | User can still modify it by special prompt '.c' | ||
| 53 | |||
| 51 | -t|--temperature Value between 0 and 2. Higher values like 0.8 will make the | 54 | -t|--temperature Value between 0 and 2. Higher values like 0.8 will make the |
| 52 | output more random, while lower values like 0.2 will make it | 55 | output more random, while lower values like 0.2 will make it |
| 53 | more focused and deterministic. | 56 | more focused and deterministic. |
| @@ -75,6 +78,9 @@ Special Input: | |||
| 75 | .c A special prompt of options shows up. User can dynamically modify | 78 | .c A special prompt of options shows up. User can dynamically modify |
| 76 | option values for API calls. | 79 | option values for API calls. |
| 77 | 80 | ||
| 81 | .r Rewind previous chats. This is useful when terminal is occupied by | ||
| 82 | configuration or other jobs | ||
| 83 | |||
| 78 | .h Ask gpt the usage of this script | 84 | .h Ask gpt the usage of this script |
| 79 | 85 | ||
| 80 | Reference: https://platform.openai.com/docs/api-reference/completions | 86 | Reference: https://platform.openai.com/docs/api-reference/completions |
| @@ -120,6 +126,17 @@ _configure_options() { | |||
| 120 | done | 126 | done |
| 121 | } | 127 | } |
| 122 | 128 | ||
| 129 | _print_previous_chats() { | ||
| 130 | echo | ||
| 131 | jq -r ' | ||
| 132 | def colors: { | ||
| 133 | "white": "\u001b[37m", | ||
| 134 | "yellow": "\u001b[33m", | ||
| 135 | }; | ||
| 136 | if .id|not then .messages[-1].content + "\n" else colors.yellow + .choices[0].message.content + colors.white + "\n" end | ||
| 137 | ' "$cache" | ||
| 138 | } | ||
| 139 | |||
| 123 | # Get latest content for completion | 140 | # Get latest content for completion |
| 124 | _get_content() { | 141 | _get_content() { |
| 125 | 142 | ||
| @@ -135,6 +152,8 @@ _get_content() { | |||
| 135 | _configure_options | 152 | _configure_options |
| 136 | echo -e '\n======\n' | 153 | echo -e '\n======\n' |
| 137 | continue | 154 | continue |
| 155 | elif [ "$content" = .r ]; then | ||
| 156 | _print_previous_chats | ||
| 138 | elif [ "$content" = .h ]; then | 157 | elif [ "$content" = .h ]; then |
| 139 | content="What does the following script used for? Show me how to use it?" | 158 | content="What does the following script used for? Show me how to use it?" |
| 140 | echo -n "$content" | 159 | echo -n "$content" |
| @@ -200,6 +219,10 @@ while [ "$#" -gt 0 ]; do | |||
| 200 | behavior="$2" | 219 | behavior="$2" |
| 201 | shift 2 | 220 | shift 2 |
| 202 | ;; | 221 | ;; |
| 222 | -B|--sys-message) | ||
| 223 | SYSTEM_PROMPT=true | ||
| 224 | shift 1 | ||
| 225 | ;; | ||
| 203 | -t|--temperature) | 226 | -t|--temperature) |
| 204 | temperature="$2" | 227 | temperature="$2" |
| 205 | shift 2 | 228 | shift 2 |
| @@ -259,6 +282,11 @@ cache=$(mktemp) && touch "$cache" | |||
| 259 | session=() | 282 | session=() |
| 260 | round=1 | 283 | round=1 |
| 261 | 284 | ||
| 285 | # Allow user input system message | ||
| 286 | if [ "$SYSTEM_PROMPT" = true ]; then | ||
| 287 | read -e -r -p "System Message: " behavior | ||
| 288 | fi | ||
| 289 | |||
| 262 | # Use while to keep chat session | 290 | # Use while to keep chat session |
| 263 | while true; do | 291 | while true; do |
| 264 | _get_content | 292 | _get_content |