diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2023-03-24 10:07:17 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2023-03-24 10:07:17 +0800 |
commit | 6dbca2cd9caa5dd19a71cf03cf13bddb31e6da75 (patch) | |
tree | 1b14314cd83947cd57a042a4ef94044b3ed9608c | |
parent | a54eb3b754638c81a27f89b9cf2789f6279d2ce8 (diff) |
Update
-rwxr-xr-x | bin/gpt/gpt | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/bin/gpt/gpt b/bin/gpt/gpt index 34f7635..d33e382 100755 --- a/bin/gpt/gpt +++ b/bin/gpt/gpt | |||
@@ -4,6 +4,7 @@ | |||
4 | # - Use suggested block to wrap data: | 4 | # - Use suggested block to wrap data: |
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 | 8 | ||
8 | # Necessary commands | 9 | # Necessary commands |
9 | stacks=( curl jq ) | 10 | stacks=( curl jq ) |
@@ -229,20 +230,18 @@ EOF | |||
229 | # API call | 230 | # API call |
230 | # Save original response into cache file | 231 | # Save original response into cache file |
231 | # And only print content of message | 232 | # And only print content of message |
232 | response="$( | 233 | curl https://api.openai.com/$ROUTE \ |
233 | curl https://api.openai.com/$ROUTE \ | 234 | --silent \ |
234 | --silent \ | 235 | -H "Content-Type: application/json" \ |
235 | -H "Content-Type: application/json" \ | 236 | -H "Authorization: Bearer $OPENAI_API_KEY" \ |
236 | -H "Authorization: Bearer $OPENAI_API_KEY" \ | 237 | -d "$body" | \ |
237 | -d "$body" | \ | 238 | jq . | tee -a "$cache" | \ |
238 | jq . | tee -a "$cache" | \ | 239 | jq -r .choices[0].message.content |
239 | jq -r .choices[0].message.content | ||
240 | )" | ||
241 | echo -e "${response}\n\n======\n" | 240 | echo -e "${response}\n\n======\n" |
242 | 241 | ||
243 | # Append newest message into session | 242 | # Append newest message into session |
244 | assistant_message="$(cat <<EOF | 243 | assistant_message="$(cat <<EOF |
245 | {"role": "assistant", "content": $(<<<"$response" jq -sR .)} | 244 | {"role": "assistant", "content": $(jq -sr '.[-1].choices[0].message.content' "$cache" | jq -sR .)} |
246 | EOF | 245 | EOF |
247 | )" | 246 | )" |
248 | session+=("$assistant_message") | 247 | session+=("$assistant_message") |