From a5c3ddf0e42d265573cdb6d68d8a675c0fe2cbb7 Mon Sep 17 00:00:00 2001 From: Achilleas Date: Tue, 16 May 2023 17:38:21 +0300 Subject: [PATCH] replace sed for escaping newlines with the escape function --- chatgpt.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chatgpt.sh b/chatgpt.sh index 0075d92..81df29a 100755 --- a/chatgpt.sh +++ b/chatgpt.sh @@ -125,8 +125,8 @@ request_to_image() { # $1 should be the message(s) formatted with role and content request_to_chat() { local message="$1" - # escape quotation marks and newlines in the prompt - escaped_system_prompt=$(echo "$SYSTEM_PROMPT" | sed 's/"/\\"/g' | sed ':a;N;$!ba;s/\n/\\n/g') + escaped_system_prompt=$(escape "$SYSTEM_PROMPT") + curl https://api.openai.com/v1/chat/completions \ -sS \ -H 'Content-Type: application/json' \ @@ -321,7 +321,7 @@ while $running; do if [ -z "$pipe_mode_prompt" ]; then if [ $MULTI_LINE_PROMPT = true ]; then echo -e "\nEnter a prompt: (Press Enter then Ctrl-D to send)" - cat > "${USER_INPUT_TEMP_FILE}" + cat >"${USER_INPUT_TEMP_FILE}" input_from_temp_file=$(cat "${USER_INPUT_TEMP_FILE}") prompt=$(escape "$input_from_temp_file") else