PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services / 8.8.0
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services v8.8.0
8.8.0 8.7.9 8.7.8 8.7.7 8.7.6 8.7.5 8.7.4 8.7.3 8.7.2 8.7.1 8.7.0 8.6.9 8.6.8 8.6.7 8.6.6 8.6.5 8.6.4 8.6.2 8.6.1 8.6.0 8.5.9 8.5.8 8.5.7 8.5.6 8.5.5 All 536 releases
← All changes | includes/integration/openai/qcld_wp_OpenAI.php +99 -99 8.7.3 → 8.8.0 View file →
@@ -1,99 +1,99 @@
1 -<?php
2 -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly.
3 -include_once(ABSPATH . 'wp-includes/pluggable.php');
4 -if(!class_exists('qcld_wp_OpenAI')){
5 - class qcld_wp_OpenAI{
6 - public $baseURL = "https://api.openai.com/v1/";
7 - private $defaultEngine = "davinci";
8 - public function setDefaultEngine($defaultEngine){
9 - $this->defaultEngine = $defaultEngine;
10 - }
11 -
12 - public function get_response($postFields){
13 - $url = "https://api.openai.com/v1/completions";
14 - $api_key = get_option('open_ai_api_key');
15 -
16 - $response = wp_remote_post(
17 - $url,
18 - array(
19 - 'headers' => array(
20 - 'Content-Type' => 'application/json',
21 - 'Authorization' => 'Bearer ' . $api_key,
22 - ),
23 - 'body' => $postFields,
24 - 'timeout' => 60,
25 - )
26 - );
27 -
28 - if ( is_wp_error( $response ) ) {
29 - return null;
30 - }
31 -
32 - return json_decode( wp_remote_retrieve_body( $response ) );
33 - }
34 - public function complete($prompt) {
35 - $max_tokens = (int)get_option( 'openai_max_tokens');
36 - $temp = (float)get_option( 'openai_temperature');
37 - $frequency_penalty = (float)get_option( 'frequency_penalty');
38 - $presence_penalty = (float)get_option( 'presence_penalty');
39 - $request_body = [
40 - "prompt" => $prompt,
41 - "model" => get_option( 'openai_engines'),
42 - "max_tokens" => $max_tokens,
43 - "top_p" => 1,
44 - "presence_penalty" => $presence_penalty,
45 - "frequency_penalty"=> $frequency_penalty,
46 - "best_of"=> 1,
47 - "stream" => false,
48 - ];
49 - $postFields = wp_json_encode($request_body);
50 - $result = self::get_response($postFields);
51 - return wp_json_encode($result);
52 - }
53 - public function gptcomplete($keyword){
54 - $url = 'https://api.openai.com/v1/responses';
55 - $api_key = get_option('open_ai_api_key');
56 -
57 - $response = wp_remote_post(
58 - $url,
59 - array(
60 - 'headers' => array(
61 - 'Content-Type' => 'application/json',
62 - 'Authorization' => 'Bearer ' . $api_key,
63 - ),
64 - 'body' => wp_json_encode( array(
65 - 'model' => get_option( 'openai_engines'),
66 - 'input' => $keyword,
67 - ) ),
68 - 'timeout' => 60,
69 - )
70 - );
71 -
72 - if ( is_wp_error( $response ) ) {
73 - return '';
74 - }
75 -
76 - return wp_remote_retrieve_body( $response );
77 - }
78 - public function models_list(){
79 - $api_key = get_option('open_ai_api_key');
80 - $url = 'https://api.openai.com/v1/models';
81 -
82 - $response = wp_remote_get(
83 - $url,
84 - array(
85 - 'headers' => array(
86 - 'Authorization' => 'Bearer ' . $api_key,
87 - ),
88 - 'timeout' => 30,
89 - )
90 - );
91 -
92 - if ( is_wp_error( $response ) ) {
93 - return false;
94 - }
95 -
96 - return wp_remote_retrieve_body( $response );
97 - }
98 - }
99 -}
1 +<?php
2 +if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly.
3 +include_once(ABSPATH . 'wp-includes/pluggable.php');
4 +if(!class_exists('qcld_wp_OpenAI')){
5 + class qcld_wp_OpenAI{
6 + public $baseURL = "https://api.openai.com/v1/";
7 + private $defaultEngine = "davinci";
8 + public function setDefaultEngine($defaultEngine){
9 + $this->defaultEngine = $defaultEngine;
10 + }
11 +
12 + public function get_response($postFields){
13 + $url = "https://api.openai.com/v1/completions";
14 + $api_key = get_option('open_ai_api_key');
15 +
16 + $response = wp_remote_post(
17 + $url,
18 + array(
19 + 'headers' => array(
20 + 'Content-Type' => 'application/json',
21 + 'Authorization' => 'Bearer ' . $api_key,
22 + ),
23 + 'body' => $postFields,
24 + 'timeout' => 60,
25 + )
26 + );
27 +
28 + if ( is_wp_error( $response ) ) {
29 + return null;
30 + }
31 +
32 + return json_decode( wp_remote_retrieve_body( $response ) );
33 + }
34 + public function complete($prompt) {
35 + $max_tokens = (int)get_option( 'openai_max_tokens');
36 + $temp = (float)get_option( 'openai_temperature');
37 + $frequency_penalty = (float)get_option( 'frequency_penalty');
38 + $presence_penalty = (float)get_option( 'presence_penalty');
39 + $request_body = [
40 + "prompt" => $prompt,
41 + "model" => get_option( 'openai_engines'),
42 + "max_tokens" => $max_tokens,
43 + "top_p" => 1,
44 + "presence_penalty" => $presence_penalty,
45 + "frequency_penalty"=> $frequency_penalty,
46 + "best_of"=> 1,
47 + "stream" => false,
48 + ];
49 + $postFields = wp_json_encode($request_body);
50 + $result = self::get_response($postFields);
51 + return wp_json_encode($result);
52 + }
53 + public function gptcomplete($keyword){
54 + $url = 'https://api.openai.com/v1/responses';
55 + $api_key = get_option('open_ai_api_key');
56 +
57 + $response = wp_remote_post(
58 + $url,
59 + array(
60 + 'headers' => array(
61 + 'Content-Type' => 'application/json',
62 + 'Authorization' => 'Bearer ' . $api_key,
63 + ),
64 + 'body' => wp_json_encode( array(
65 + 'model' => get_option( 'openai_engines'),
66 + 'input' => $keyword,
67 + ) ),
68 + 'timeout' => 60,
69 + )
70 + );
71 +
72 + if ( is_wp_error( $response ) ) {
73 + return '';
74 + }
75 +
76 + return wp_remote_retrieve_body( $response );
77 + }
78 + public function models_list(){
79 + $api_key = get_option('open_ai_api_key');
80 + $url = 'https://api.openai.com/v1/models';
81 +
82 + $response = wp_remote_get(
83 + $url,
84 + array(
85 + 'headers' => array(
86 + 'Authorization' => 'Bearer ' . $api_key,
87 + ),
88 + 'timeout' => 30,
89 + )
90 + );
91 +
92 + if ( is_wp_error( $response ) ) {
93 + return false;
94 + }
95 +
96 + return wp_remote_retrieve_body( $response );
97 + }
98 + }
99 +}