I am having a problem with getting responses from OpenAI's API...
I have this function:
`function generate_response($input) {
$openai_api_key = "MY TOKEN";
$prompt = "Answer the following question: " . $input;
$data = array(
'prompt' => $prompt,
'max_tokens' => 1000,
'temperature' => 0.5,
'model' => 'davinci',
'stop' => ['\n'],
);
$url = 'https://api.openai.com/v1/completions';
$headers = array(
'Content-Type: application/json',
'Authorization: Bearer ' . $openai_api_key
);
$data_string = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = json_decode(curl_exec($ch));
curl_close($ch);
if (isset($response->error)) {
return "Error: " . $response->error->message;
}
$text_parts = array();
foreach ($response->choices[0]->text as $part) {
$text_parts[] = $part;
}
$text = implode('', $text_parts);
return $text;
}
$user_question = "What is the capital of France?";
$response = generate_response($user_question);
echo "<h1>$response</h1>";`
It was saying something about model and engine then I used model however, it is still not working as I had expected any sugestions?
I tried changing model, engine, URL link. I was hoping i would get sensable answer for my question