Skip to content

Commit a5c3ddf

Browse files
committed
replace sed for escaping newlines with the escape function
1 parent a69c998 commit a5c3ddf

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

chatgpt.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ request_to_image() {
125125
# $1 should be the message(s) formatted with role and content
126126
request_to_chat() {
127127
local message="$1"
128-
# escape quotation marks and newlines in the prompt
129-
escaped_system_prompt=$(echo "$SYSTEM_PROMPT" | sed 's/"/\\"/g' | sed ':a;N;$!ba;s/\n/\\n/g')
128+
escaped_system_prompt=$(escape "$SYSTEM_PROMPT")
129+
130130
curl https://api.openai.com/v1/chat/completions \
131131
-sS \
132132
-H 'Content-Type: application/json' \
@@ -321,7 +321,7 @@ while $running; do
321321
if [ -z "$pipe_mode_prompt" ]; then
322322
if [ $MULTI_LINE_PROMPT = true ]; then
323323
echo -e "\nEnter a prompt: (Press Enter then Ctrl-D to send)"
324-
cat > "${USER_INPUT_TEMP_FILE}"
324+
cat >"${USER_INPUT_TEMP_FILE}"
325325
input_from_temp_file=$(cat "${USER_INPUT_TEMP_FILE}")
326326
prompt=$(escape "$input_from_temp_file")
327327
else

0 commit comments

Comments
 (0)