Skip to content

Commit 6fc4698

Browse files
authored
Merge pull request #53 from 0xacx/Enable-response-formatting-in-history
Add formatted response data to history
2 parents 10cb481 + c3681f6 commit 6fc4698

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

chatgpt.sh

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ maintain_chat_context() {
105105
done
106106
}
107107

108-
# build user chat message function for /chat/completions (gpt turbo model)
108+
# build user chat message function for /chat/completions (gpt models)
109109
# builds chat message before request,
110110
# $1 should be the chat message
111111
# $2 should be the escaped prompt
@@ -122,18 +122,18 @@ build_user_chat_message() {
122122
}
123123

124124
# adds the assistant response to the message in (chatml) format
125-
# for /chat/completions (gpt turbo model)
125+
# for /chat/completions (gpt models)
126126
# keeps messages length under max token limit
127127
# $1 should be the chat message
128128
# $2 should be the response data (only the text)
129129
add_assistant_response_to_chat_message() {
130130
chat_message="$1"
131-
response_data="$2"
131+
local local_response_data="$2"
132132

133133
# replace new line characters from response with space
134-
response_data=$(echo "$response_data" | tr '\n' ' ')
134+
local_response_data=$(echo "$local_response_data" | tr '\n' ' ')
135135
# add response to chat context as answer
136-
chat_message="$chat_message, {\"role\": \"assistant\", \"content\": \"$response_data\"}"
136+
chat_message="$chat_message, {\"role\": \"assistant\", \"content\": \"$local_response_data\"}"
137137

138138
# transform to json array to parse with jq
139139
chat_message_json="[ $chat_message ]"
@@ -306,8 +306,8 @@ while $running; do
306306
eval $response_data
307307
fi
308308
fi
309-
response_data=$(echo "$response_data" | sed 's/"/\\"/g')
310-
add_assistant_response_to_chat_message "$chat_message" "$response_data"
309+
escaped_response_data=$(echo "$response_data" | sed 's/"/\\"/g')
310+
add_assistant_response_to_chat_message "$chat_message" "$escaped_response_data"
311311

312312
timestamp=$(date +"%d/%m/%Y %H:%M")
313313
echo -e "$timestamp $prompt \n$response_data \n" >>~/.chatgpt_history
@@ -325,8 +325,8 @@ while $running; do
325325

326326
echo -e "${CHATGPT_CYAN_LABEL}${response_data}"
327327

328-
response_data=$(echo "$response_data" | sed 's/"/\\"/g')
329-
add_assistant_response_to_chat_message "$chat_message" "$response_data"
328+
escaped_response_data=$(echo "$response_data" | sed 's/"/\\"/g')
329+
add_assistant_response_to_chat_message "$chat_message" "$escaped_response_data"
330330

331331
timestamp=$(date +"%d/%m/%Y %H:%M")
332332
echo -e "$timestamp $prompt \n$response_data \n" >>~/.chatgpt_history
@@ -349,8 +349,9 @@ while $running; do
349349
escaped_response_data=$(echo "$response_data" | sed 's/"/\\"/g')
350350
maintain_chat_context "$chat_context" "$escaped_response_data"
351351
fi
352-
352+
echo "this"
353+
echo $response_data
353354
timestamp=$(date +"%d/%m/%Y %H:%M")
354-
echo -e "$timestamp $prompt \n$escaped_response_data \n" >>~/.chatgpt_history
355+
echo -e "$timestamp $prompt \n$response_data \n" >>~/.chatgpt_history
355356
fi
356-
done
357+
done

0 commit comments

Comments
 (0)