Skip to content

Commit 4395626

Browse files
authored
Merge pull request #87 from tomas223/fix/multiline-file-prompt
fix: multiline file prompt input
2 parents 2e25138 + 289e604 commit 4395626

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

chatgpt.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,16 @@ 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')
128130
curl https://api.openai.com/v1/chat/completions \
129131
-sS \
130132
-H 'Content-Type: application/json' \
131133
-H "Authorization: Bearer $OPENAI_KEY" \
132134
-d '{
133135
"model": "'"$MODEL"'",
134136
"messages": [
135-
{"role": "system", "content": "'"$SYSTEM_PROMPT"'"},
137+
{"role": "system", "content": "'"$escaped_system_prompt"'"},
136138
'"$message"'
137139
],
138140
"max_tokens": '$MAX_TOKENS',

0 commit comments

Comments
 (0)