| Server IP : 162.214.74.102 / Your IP : 216.73.216.192 Web Server : Apache System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64 User : lrsys ( 1015) PHP Version : 5.6.40 Disable Function : exec,passthru,shell_exec,system MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/lrsys/www/lrsys_apps/leo/application/plugins/module_imobles/helpers/AI/ |
Upload File : |
<?php
class openaiHelper {
protected $openai_key = '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';
public function transcriptions($file, $model = 'whisper-1') {
try {
// $fileaux = new CurlFile('@"/home/leonardo/Downloads/testeaudio.mpga"', 'audio/mpeg', 'testeaudio.mpga');
$curl = curl_init();
$url = "https://api.openai.com/v1/audio/transcriptions";
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HEADER => false,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_SAFE_UPLOAD => true,
CURLOPT_HTTPHEADER => array(
"Content-Type: multipart/form-data",
"authorization: Bearer ".$this->openai_key),
CURLOPT_POSTFIELDS => array(
"model" => "whisper-1",
"file" => new CurlFile($file))
));
$response = curl_exec($curl);
curl_close($curl);
$response = json_decode($response);
if(isset($response->error))
{
$return = array('error' => true, 'data' => $response);
} else {
$return = array('error' => false, 'data' => $response);
}
}
catch (Exception $e) {
$return = array('error' => true, 'data' => $e);
}
return $return;
}
public function completions($prompt, $model = 'text-davinci-003') {
try {
$curl = curl_init();
$post_data = '{
"model": "'.$model.'",
"prompt": "'.$prompt.'",
"temperature": 0,
"max_tokens": 600,
"top_p": 0,
"frequency_penalty": 0,
"presence_penalty": 0
}';
$url = "https://api.openai.com/v1/completions";
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $post_data,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'authorization: Bearer '.$this->openai_key
),
));
$response = curl_exec($curl);
curl_close($curl);
$response = json_decode($response);
if(isset($response->error))
{
$return = array('error' => true, 'data' => $response);
} else {
$return = array('error' => false, 'data' => $response);
}
}
catch (Exception $e) {
$return = array('error' => true, 'data' => $e);
}
return $return;
}
public function chatCompletions($messages, $model = 'gpt-3.5-turbo') {
try {
$curl = curl_init();
$post_data = '{
"model": "'.$model.'",
"messages": '.$messages.'}';
$url = "https://api.openai.com/v1/chat/completions";
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $post_data,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'authorization: Bearer '.$this->openai_key
),
));
$response = curl_exec($curl);
curl_close($curl);
$response = json_decode($response);
if(isset($response->error))
{
$return = array('error' => true, 'data' => $response);
} else {
$return = array('error' => false, 'data' => $response);
}
}
catch (Exception $e) {
$return = array('error' => true, 'data' => $e);
}
return $return;
}
}