Plugin Directory


Ignore:
Timestamp:
05/20/2024 01:29:10 PM (11 months ago)
Author:
quantumcloud
Message:

# Removed unnecessary functions
# Improved security

File:
1 edited

Legend:

Unmodified
Added
Removed
  • chatbot/trunk/includes/openai/qcld-bot-openai.php

    r3077619 r3089461  
    6262            add_action('wp_ajax_openai_settings_option', [$this, 'openai_settings_option_callback']);
    6363            add_action('wp_ajax_openai_response',[$this,'openai_response_callback']);
    64             add_action('wp_ajax_openai_file_list',[$this,'openai_file_list_callback']);
    65             add_action('wp_ajax_openai_file_upload',[$this,'openai_file_upload_callback']);
    66             add_action('wp_ajax_openai_file_delete',[$this,'openai_file_delete_callback']);
     64           // add_action('wp_ajax_openai_file_list',[$this,'openai_file_list_callback']);
     65           // add_action('wp_ajax_openai_file_upload',[$this,'openai_file_upload_callback']);
     66           // add_action('wp_ajax_openai_file_delete',[$this,'openai_file_delete_callback']);
    6767            add_action('wp_ajax_nopriv_openai_response', [$this, 'openai_response_callback']);
    68             add_action('wp_ajax_qcld_openai_file_dowload',[$this,'qcld_openai_file_dowload']);
     68           // add_action('wp_ajax_qcld_openai_file_dowload',[$this,'qcld_openai_file_dowload']);
    6969           
    7070            if (is_admin() && !empty($_GET["page"]) && (($_GET["page"] == "openai-panel_dashboard") || ($_GET["page"] == "openai-panel_file") || ($_GET["page"] == "openai-panel_help"))) {
     
    131131         
    132132        }
    133         public function openai_file_delete_callback(){
    134             $file_id = sanitize_text_field($_POST['file_id']);
    135             $url = 'https://api.openai.com/v1/files/'. $file_id;
    136             $apt_key = "Authorization: Bearer ". get_option('open_ai_api_key');
    137             $ch = curl_init();
    138             curl_setopt($ch, CURLOPT_URL, $url);
    139             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    140             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
    141             $headers = array(
    142                 $apt_key,
    143             );
    144             curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    145             $result = curl_exec($ch);
    146             if (curl_errno($ch)) {
    147                 echo 'Error:' . curl_error($ch);
    148             }
    149             curl_close($ch);
    150            wp_send_json( json_decode($result));
    151            wp_die();
    152         }
     133        // public function openai_file_delete_callback(){
     134        //     $file_id = sanitize_text_field($_POST['file_id']);
     135        //     $url = 'https://api.openai.com/v1/files/'. $file_id;
     136        //     $apt_key = "Authorization: Bearer ". get_option('open_ai_api_key');
     137        //     $ch = curl_init();
     138        //     curl_setopt($ch, CURLOPT_URL, $url);
     139        //     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     140        //     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
     141        //     $headers = array(
     142        //         $apt_key,
     143        //     );
     144        //     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     145        //     $result = curl_exec($ch);
     146        //     if (curl_errno($ch)) {
     147        //         echo 'Error:' . curl_error($ch);
     148        //     }
     149        //     curl_close($ch);
     150        //    wp_send_json( json_decode($result));
     151        //    wp_die();
     152        // }
    153153     
    154154        public function buildFormBody( $fields, $boundary )
     
    173173        }
    174174
    175         public function openai_file_list_callback(){
    176             $url = 'https://api.openai.com/v1/files';
    177             $apt_key = "Authorization: Bearer ". get_option('open_ai_api_key');
    178             $curl = curl_init();
    179             curl_setopt($curl, CURLOPT_URL, $url);
    180             $headers = array(
    181                 "Content-Type: application/json",
    182                 $apt_key,
    183             );
    184             curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    185             curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    186             $response = curl_exec($curl);
    187             curl_close($curl);
    188             wp_send_json( json_decode($response));
    189             wp_die();
    190         }
     175        // public function openai_file_list_callback(){
     176        //     $url = 'https://api.openai.com/v1/files';
     177        //     $apt_key = "Authorization: Bearer ". get_option('open_ai_api_key');
     178        //     $curl = curl_init();
     179        //     curl_setopt($curl, CURLOPT_URL, $url);
     180        //     $headers = array(
     181        //         "Content-Type: application/json",
     182        //         $apt_key,
     183        //     );
     184        //     curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
     185        //     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     186        //     $response = curl_exec($curl);
     187        //     curl_close($curl);
     188        //     wp_send_json( json_decode($response));
     189        //     wp_die();
     190        // }
    191191        public function qcld_sanitize_text_or_array_field($array_or_string) {
    192192            if( is_string($array_or_string) ){
     
    206206        }
    207207     
    208         public function openai_file_upload_callback(){
    209             $uploadedfile = $_FILES['file'];
    210             $url = 'https://api.openai.com/v1/files';
    211             $apt_key = "Authorization: Bearer ". get_option('open_ai_api_key');
    212             $curl = curl_init($url);
    213             curl_setopt($curl, CURLOPT_URL, $url);
    214             curl_setopt($curl, CURLOPT_POST, true);
    215             $headers = array(
    216                 "Content-Type: multipart/form-data",
    217                 $apt_key,
    218             );
    219             if (function_exists('curl_file_create')) {
    220                 $tmp_file = curl_file_create($uploadedfile['tmp_name'], 'jsonl', $uploadedfile['name']);
    221             } else {
    222                 $tmp_file = open($uploadedfile['tmp_name']);
    223             }
    224             $data = array('file'=> $tmp_file,'purpose'=> 'fine-tune');
    225             $init = curl_init();
    226             //function parameteres
    227             curl_setopt($init, CURLOPT_URL,$url);
    228             curl_setopt($init, CURLOPT_HTTPHEADER, $headers);
    229             curl_setopt($init, CURLOPT_POSTFIELDS, $data);
    230             curl_setopt($init, CURLOPT_RETURNTRANSFER, true);
    231             $res = json_decode(curl_exec ($init));
    232            
    233             curl_close ($init);
    234             if(!empty($res->error)){
    235                 $response['status'] = 'error';
    236                 $response['message'] = $res->error->message;
    237             }
    238            
    239             if(!empty($res->status)){
    240                 $response['status'] = 'success';
    241                 $response['message'] = 'Successfully Created file' . $res->id ;
    242                
    243             }
    244             echo wp_send_json([$response]);
    245             wp_die();
    246         }
     208        // public function openai_file_upload_callback(){
     209        //     $uploadedfile = $_FILES['file'];
     210        //     $url = 'https://api.openai.com/v1/files';
     211        //     $apt_key = "Authorization: Bearer ". get_option('open_ai_api_key');
     212        //     $curl = curl_init($url);
     213        //     curl_setopt($curl, CURLOPT_URL, $url);
     214        //     curl_setopt($curl, CURLOPT_POST, true);
     215        //     $headers = array(
     216        //         "Content-Type: multipart/form-data",
     217        //         $apt_key,
     218        //     );
     219        //     if (function_exists('curl_file_create')) {
     220        //         $tmp_file = curl_file_create($uploadedfile['tmp_name'], 'jsonl', $uploadedfile['name']);
     221        //     } else {
     222        //         $tmp_file = open($uploadedfile['tmp_name']);
     223        //     }
     224        //     $data = array('file'=> $tmp_file,'purpose'=> 'fine-tune');
     225        //     $init = curl_init();
     226        //     //function parameteres
     227        //     curl_setopt($init, CURLOPT_URL,$url);
     228        //     curl_setopt($init, CURLOPT_HTTPHEADER, $headers);
     229        //     curl_setopt($init, CURLOPT_POSTFIELDS, $data);
     230        //     curl_setopt($init, CURLOPT_RETURNTRANSFER, true);
     231        //     $res = json_decode(curl_exec ($init));
     232           
     233        //     curl_close ($init);
     234        //     if(!empty($res->error)){
     235        //         $response['status'] = 'error';
     236        //         $response['message'] = $res->error->message;
     237        //     }
     238           
     239        //     if(!empty($res->status)){
     240        //         $response['status'] = 'success';
     241        //         $response['message'] = 'Successfully Created file' . $res->id ;
     242               
     243        //     }
     244        //     echo wp_send_json([$response]);
     245        //     wp_die();
     246        // }
    247247        public function openai_finetune_create($file_id,$ft_suffix,$ft_engines){
    248248            $apt_key = "Authorization: Bearer ". get_option('open_ai_api_key');
     
    326326                return $result;
    327327                if (curl_errno($ch)) {
     328                    // phpcs:ignore
    328329                    echo 'Error:' . curl_error($ch);
    329330                }
     
    557558                            setcookie('qcld_threads_id',$threads_id  , time() + (60000), "/");
    558559                            if (curl_errno($ch)) {
     560                                // phpcs:ignore
    559561                                echo 'Error: ' . curl_error($ch);
    560562                            }
Note: See TracChangeset for help on using the changeset viewer.