At times, the GPT-3.5-turbo model provides inaccurate descriptions of the student comments, occasionally presenting views that contradict the sentiments expressed by the students.
This is the code
public function openai($dataa)
{
// dd($dataa);
$messages = [];
$combinedContent = ""; // Initialize an empty string
// dd($data);
// Assuming $dataArray is your array of strings
if (!is_array($dataa)) {
// dd($dataa);
$dataa = [$dataa];
}
foreach ($dataa as $item) {
$combinedContent .= $item . " next Comment is ";
}
$messages[] = ['role' => 'assistant', 'content' => "Please analyze the following list of student comments and provide a concise summary of the main themes, opinions, and feedback expressed by the students. The comments are as follows \n\"$combinedContent\" Please ensure that the summary captures the key points and sentiments expressed in these comments. Thank you!"];
// dd($combinedContent);
// Now, $messages contains the conversation data in the required format
// Replace with your API key
$apiKey = '';
$client = new Client([
'verify' => false, // Disable SSL verification
]);
$response = $client->post('https://api.openai.com/v1/chat/completions', [
'headers' => [
'Authorization' => 'Bearer ' . $apiKey,
],
'json' => [
'messages' => $messages,
'max_tokens' => 50, // Adjust the maximum length of the response as needed.
'model' => "gpt-3.5-turbo",
],
]);
$data = json_decode($response->getBody(), true);
// dd($data);
$description = $data['choices'][0]['message']['content'];
// dd($description);
return $description;
}