I am struggling with the gpt-4 API and the new messages json array which is used to feed the prompt. How can I combine fixed text with variables in the "content" section ? For Example "Please translate the following text:" $selectedText "into" $language. The variables are defined - even the fixed text has been put into variables.
curl https://api.openai.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $api_key" \
-d '{
"model": "gpt-4",
"messages": [{"role": "user", "content": "'$intro $selectedText $into $language'"}],
"temperature": 0.7
}'
Error message:
curl https://api.openai.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $api_key" \
-d '{"model": "gpt-4", "messages": [{"role": "user", "content": "'$intro $selectedText $into $language'"}], "temperature": 0.7}'
{
"error": {
"message": "We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please contact us through our help center at help.openai.com.)",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
curl: (3) URL rejected: Malformed input to a URL function
curl: (6) Could not resolve host: into
curl: (3) unmatched close brace/bracket in URL position 8:
german"}], "temperature": 0.7}