I'm trying to use the Ada language processor of OpenAi to summarize a piece of text. When I try to use their playground, the function works and I get a summarization that makes sense and can be used by humans.
This is the cURL from the playground:
curl https://api.openai.com/v1/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "text-ada-001",
"prompt": "Please write a one paragraph professional synopsis:\n\nSome text",
"temperature": 0,
"max_tokens": 60,
"top_p": 1,
"frequency_penalty": 0,
"presence_penalty": 0
}'
When I take this cURL and transform it to PHP code, it stops working, or better said it works but it returns complete nonsense, nothing similar to the results from the playground.
PHP code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.openai.com/v1/completions');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$postFields = '{
"model": "text-ada-001",
"prompt": "Please write a one paragraph professional synopsis: ' . $text . '",
"temperature": 0,
"max_tokens": 500,
"top_p": 1,
"frequency_penalty": 0,
"presence_penalty": 0
}';
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: Bearer ' . $api_key;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $result;
Now, I tried to use both a json code like this, and to write a PHP array and convert it to json, same result. I have also tried to use a library but it also returned the same nonsense as before. I'm saying nonsense, because the text that it returns is not something that can be read and said, 'Hey, this is a proffesional synopsis'. I'm going to give an example of a sentence that I got in one of the iterations:
'It's not pretty and no I thought to myself, oh look IT'S NOT THAT REPUBLICAN kids would kno one of these things. OH IT'S A RESTRICTIOUS SCHOOL'.
I can assure you, there are no mentions of republicans or kids in the text that I'm processing.
My question is, am I doing something wrong? Does OpenAi work differently on their playground and in code?