File manager - Edit - /home/autoph/public_html/pms_v1/chatGPTv1/chatGPT.php
Back
<?php if(isset($_POST['myQue'])){ $openaiKey = "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"; $url = 'https://api.openai.com/v1/chat/completions'; //$myQuestions = 'what is the value of Pi'; $myQue = $_POST['myQue']; if($myQue===""){ echo 'Sorry, I cannot answer question if there is no question to be asked. please type something for me.'; } $data = [ 'model' => 'gpt-3.5-turbo', 'messages' => [ ['role' => 'system', 'content' => 'You are a helpful assistant.'], ['role' => 'user', 'content' => $myQue] ] ]; $payload = json_encode($data); $ch = curl_init($url); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Bearer ' . $openaiKey)); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); if ($response === false) { $error = curl_error($ch); // Handle error echo "Error: " . $error; } else { $result = json_decode($response, true); //$result = json_decode($response, true); $reply = $result['choices'][0]['message']['content']; echo '<pre style="white-space: pre-wrap;border:0px solid white;word-wrap:break-word;">'.$reply.'</pre>'; //var_dump($reply); } curl_close($ch); } ?>
| ver. 1.4 |
.
| PHP 7.3.33 | Generation time: 0.08 |
proxy
|
phpinfo
|
Settings