Changeset 3089461 for chatbot/trunk/includes/openai/qcld-bot-openai.php
- Timestamp:
- 05/20/2024 01:29:10 PM (11 months ago)
- File:
-
- 1 edited
-
chatbot/trunk/includes/openai/qcld-bot-openai.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
chatbot/trunk/includes/openai/qcld-bot-openai.php
r3077619 r3089461 62 62 add_action('wp_ajax_openai_settings_option', [$this, 'openai_settings_option_callback']); 63 63 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']); 67 67 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']); 69 69 70 70 if (is_admin() && !empty($_GET["page"]) && (($_GET["page"] == "openai-panel_dashboard") || ($_GET["page"] == "openai-panel_file") || ($_GET["page"] == "openai-panel_help"))) { … … 131 131 132 132 } 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 // } 153 153 154 154 public function buildFormBody( $fields, $boundary ) … … 173 173 } 174 174 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 // } 191 191 public function qcld_sanitize_text_or_array_field($array_or_string) { 192 192 if( is_string($array_or_string) ){ … … 206 206 } 207 207 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 parameteres227 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 // } 247 247 public function openai_finetune_create($file_id,$ft_suffix,$ft_engines){ 248 248 $apt_key = "Authorization: Bearer ". get_option('open_ai_api_key'); … … 326 326 return $result; 327 327 if (curl_errno($ch)) { 328 // phpcs:ignore 328 329 echo 'Error:' . curl_error($ch); 329 330 } … … 557 558 setcookie('qcld_threads_id',$threads_id , time() + (60000), "/"); 558 559 if (curl_errno($ch)) { 560 // phpcs:ignore 559 561 echo 'Error: ' . curl_error($ch); 560 562 }
Note: See TracChangeset
for help on using the changeset viewer.