Skip to content

Commit

Permalink
Merge pull request 0xacx#106 from 0xacx/escape-system-prompt-from-file
Browse files Browse the repository at this point in the history
Escape system prompt from file
  • Loading branch information
0xacx authored May 16, 2023
2 parents e6c213f + a5c3ddf commit fbe3d1b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions chatgpt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,16 @@ request_to_image() {
# $1 should be the message(s) formatted with role and content
request_to_chat() {
local message="$1"
escaped_system_prompt=$(escape "$SYSTEM_PROMPT")

curl https://api.openai.com/v1/chat/completions \
-sS \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $OPENAI_KEY" \
-d '{
"model": "'"$MODEL"'",
"messages": [
{"role": "system", "content": "'"$SYSTEM_PROMPT"'"},
{"role": "system", "content": "'"$escaped_system_prompt"'"},
'"$message"'
],
"max_tokens": '$MAX_TOKENS',
Expand Down Expand Up @@ -319,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
Expand Down

0 comments on commit fbe3d1b

Please sign in to comment.