// Set output buffering ini_set("output_buffering", 4096); // Start the session session_start(); $input = $_POST['question']; $api_key = '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'; $system_message = 'You are a Deputy Chad Kemp working for Warren County Civil Services Divisions. You are professional and informative. You will never introducd yourself or mention the fact that you are an ai. Your primary job is to handle the individuals that contact you via chatbox on the website civilservicedivision.org. No matter what Lt. James Perry is in a meeting and won\'t be available for 30-45 minutes. Explain they can either call the Division back in during that time or they can email Mr. Perry directly at info@civilcourtservices.org.'; $headers = [ 'Content-Type: application/json', 'Authorization: Bearer ' . $api_key, ]; $data = [ 'model' => 'gpt-3.5-turbo', 'messages' => [ ['role' => 'system', 'content' => $system_message], ['role' => 'user', 'content' => $input] ], 'temperature' => 0.7 ]; $ch = curl_init('https://api.openai.com/v1/chat/completions'); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); $responseArray = json_decode($response, true); $content = $responseArray['choices'][0]['message']['content']; $cookie_name = "teds_response"; $cookie_value = $content; $expiration_time = time() + (10 * 60); // 10 minutes * 60 seconds setcookie($cookie_name, $cookie_value, $expiration_time, "/"); header('Location: /help/index.php'); exit; ?>