I want to swap out ‘completions’ for ‘dialogues’ - is that possible? I made a chatbot, but he keeps completing the users inputs and sometimes responds to himself
here is my code
<?php
class Openai{
private function secret_key(){
return $secret_key = 'Bearer mykeyhere';
}
public function request($engine, $prompt, $conversation_history){
$request_body = [
"model" => "dialog-davinci-003",
"prompt" => $prompt,
"conversation_history" => $conversation_history,
"conversation_id" => "1",
"max_tokens" => 1000,
"temperature" => 1
];
$postfields = json_encode($request_body);
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.openai.com/v1/models/dialogues",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $postfields,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Authorization: ' . $this->secret_key()
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "Error #:" . $err;
} else {
$response_obj = json_decode($response);
$text = $response_obj->choices[0]->text;
$text = nl2br($text);
return $text;
}
}