aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2023-03-25 16:33:45 +0800
committerHsieh Chin Fan <pham@topo.tw>2023-03-25 16:33:45 +0800
commite301cb5c40e551531a046a7b0d3b21b312109adf (patch)
treeeb9688acb7c55391826087c87ada57ff0992b282
parentd8c6bafbae6fe52a3d5b020c2017751c191e4178 (diff)
Update
-rwxr-xr-xbin/gpt/gpt21
1 files changed, 15 insertions, 6 deletions
diff --git a/bin/gpt/gpt b/bin/gpt/gpt
index f331050..c9917c7 100755
--- a/bin/gpt/gpt
+++ b/bin/gpt/gpt
@@ -70,8 +70,10 @@ Options:
70 If STDIN is given, it would be append to the end of message. 70 If STDIN is given, it would be append to the end of message.
71 71
72Special input: 72Special input:
73 . If input starts with '.', then a prompt of options shows up. 73 .c A special prompt of options shows up. User can dynamically modify
74 User can modify option value for API calls. 74 option values for API calls.
75
76 .h Ask gpt the usage of this script
75 77
76Reference: https://platform.openai.com/docs/api-reference/completions 78Reference: https://platform.openai.com/docs/api-reference/completions
77EOF 79EOF
@@ -123,28 +125,35 @@ _get_content() {
123 [ ! -t 0 ] && data="$(cat)" 125 [ ! -t 0 ] && data="$(cat)"
124 126
125 if [ ! "$SKIP_INPUT" = true ] ; then 127 if [ ! "$SKIP_INPUT" = true ] ; then
126 # Read content it from terminal 128 # Read content from terminal
127 while true; do 129 while true; do
128 read -e -r -p "Let's Chat: " content </dev/tty 130 read -e -r -p "Let's Chat: " content </dev/tty
129 if [[ "$content" =~ ^\. ]]; then 131 if [ "$content" = .c ]; then
130 echo -e '\n======\n' 132 echo -e '\n======\n'
131 _configure_options 133 _configure_options
132 echo -e '\n======\n' 134 echo -e '\n======\n'
133 continue 135 continue
136 elif [ "$content" = .h ]; then
137 content="What does the following script used for? how to use it?"
138 echo -n "$content"
139 content="$content\n\n$(cat $0)"
140 else
141 continue
134 fi 142 fi
135 [ -n "$content" ] && break 143 [ -n "$content" ] && break
136 done 144 done
145 # Exit 1 when "--skip" is specified, but no STDIN and CONTENT is given
137 elif [[ "$round" -eq 1 && -z "${content}${data}" ]]; then 146 elif [[ "$round" -eq 1 && -z "${content}${data}" ]]; then
138 echo -e "No data from STDIN\n" 147 echo -e "No data from STDIN\n"
139 exit 1; 148 exit 1;
140 fi 149 fi
141 150
142 # If it is the first round, append STDIN (If it exists) at the end 151 # If it is the first round, append STDIN (If it exists) at the end
143 if [[ ! "$SKIP_INPUT" = true && -n "$data" ]] ; then 152 if [[ ! "$SKIP_INPUT" = true || -n "$data" ]] ; then
144 content="$(printf "%s\\n\\n%s" "$content" "$data")" 153 content="$(printf "%s\\n\\n%s" "$content" "$data")"
145 echo -e "\n$data" 154 echo -e "\n$data"
146 # Or only use STDIN as content 155 # Or only use STDIN as content
147 elif [ -n "$data" ]; then 156 else
148 content="$data" 157 content="$data"
149 echo "$content" 158 echo "$content"
150 fi 159 fi