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.1.6 1.6.86 0.1.7 1.6.87 0.1.8 1.6.88 0.1.9 1.6.89 0.2.0 1.6.90
ai-engine / classes / core.php
ai-engine / classes Last commit date
modules 3 years ago admin.php 3 years ago ai.php 3 years ago answer.php 3 years ago api.php 3 years ago core.php 3 years ago init.php 3 years ago openai.php 3 years ago query.php 3 years ago queryembed.php 3 years ago queryimage.php 3 years ago querytext.php 3 years ago querytranscribe.php 3 years ago rest.php 3 years ago ui.php 3 years ago
core.php
485 lines
1 <?php
2
3 require_once( MWAI_PATH . '/vendor/autoload.php' );
4 require_once( MWAI_PATH . '/constants/init.php' );
5
6 class Meow_MWAI_Core
7 {
8 public $admin = null;
9 public $is_rest = false;
10 public $is_cli = false;
11 public $site_url = null;
12 public $ai = null;
13 private $option_name = 'mwai_options';
14 public $defaultChatbotParams = MWAI_CHATBOT_PARAMS;
15
16 public function __construct() {
17 $this->site_url = get_site_url();
18 $this->is_rest = MeowCommon_Helpers::is_rest();
19 $this->is_cli = defined( 'WP_CLI' ) && WP_CLI;
20 $this->ai = new Meow_MWAI_AI( $this );
21 add_action( 'plugins_loaded', array( $this, 'init' ) );
22 }
23
24 function init() {
25 global $mwai;
26 $mwai = new Meow_MWAI_API();
27 if ( $this->is_rest ) {
28 new Meow_MWAI_Rest( $this );
29 }
30 if ( is_admin() ) {
31 new Meow_MWAI_Admin( $this );
32 new Meow_MWAI_Modules_Assistants( $this );
33 }
34 else {
35 //new Meow_MWAI_UI( $this );
36 if ( $this->get_option( 'shortcode_chat' ) ) {
37 new Meow_MWAI_Modules_Chatbot();
38 }
39 }
40
41 // Advanced core
42 if ( class_exists( 'MeowPro_MWAI_Core' ) ) {
43 new MeowPro_MWAI_Core( $this );
44 }
45 }
46
47 #region Roles & Capabilities
48
49 function can_access_settings() {
50 return apply_filters( 'mwai_allow_setup', current_user_can( 'manage_options' ) );
51 }
52
53 function can_access_features() {
54 $editor_or_admin = current_user_can( 'editor' ) || current_user_can( 'administrator' );
55 return apply_filters( 'mwai_allow_usage', $editor_or_admin );
56 }
57
58 #endregion
59
60 #region Text-Related Helpers
61
62 // Clean the text perfectly, resolve shortcodes, etc, etc.
63 function clean_text( $rawText = "" ) {
64 $text = strip_tags( $rawText );
65 $text = strip_shortcodes( $text );
66 $text = html_entity_decode( $text );
67 $text = str_replace( array( "\r", "\n" ), "", $text );
68 $sentences = preg_split( '/(?<=[.?!])(?=[a-zA-Z ])/', $text );
69 foreach ( $sentences as $key => $sentence ) {
70 $sentences[$key] = trim( $sentence );
71 }
72 $text = implode( " ", $sentences );
73 $text = preg_replace( '/^[\pZ\pC]+|[\pZ\pC]+$/u', '', $text );
74 return $text . " ";
75 }
76
77 // Make sure there are no duplicate sentences, and keep the length under a maximum length.
78 function clean_sentences( $text, $maxLength = 1024 ) {
79 $sentences = preg_split( '/(?<=[.?!])(?=[a-zA-Z ])/', $text );
80 $hashes = array();
81 $uniqueSentences = array();
82 $length = 0;
83 foreach ( $sentences as $sentence ) {
84 $sentence = preg_replace( '/^[\pZ\pC]+|[\pZ\pC]+$/u', '', $sentence );
85 $hash = md5( $sentence );
86 if ( !in_array( $hash, $hashes ) ) {
87 if ( $length + strlen( $sentence ) > $maxLength ) {
88 continue;
89 }
90 $hashes[] = $hash;
91 $uniqueSentences[] = $sentence;
92 $length += strlen( $sentence );
93 }
94 }
95 $text = implode( " ", $uniqueSentences );
96 $text = preg_replace( '/^[\pZ\pC]+|[\pZ\pC]+$/u', '', $text );
97 return $text;
98 }
99
100 function get_text_from_postId( $postId ) {
101 $post = get_post( $postId );
102 if ( !$post ) {
103 return false;
104 }
105 $post->post_content = apply_filters( 'the_content', $post->post_content );
106 $text = $this->clean_text( $post->post_content );
107 $text = $this->clean_sentences( $text );
108 return $text;
109 }
110
111 function markdown_to_html( $content ) {
112 $Parsedown = new Parsedown();
113 $content = $Parsedown->text( $content );
114 return $content;
115 }
116
117 function get_post_language( $postId ) {
118 $locale = get_locale();
119 $code = strtolower( substr( $locale, 0, 2 ) );
120 $lang_codes = array(
121 'aa' => 'Afar',
122 'ab' => 'Abkhazian',
123 'af' => 'Afrikaans',
124 'ak' => 'Akan',
125 'sq' => 'Albanian',
126 'am' => 'Amharic',
127 'ar' => 'Arabic',
128 'an' => 'Aragonese',
129 'hy' => 'Armenian',
130 'as' => 'Assamese',
131 'av' => 'Avaric',
132 'ae' => 'Avestan',
133 'ay' => 'Aymara',
134 'az' => 'Azerbaijani',
135 'ba' => 'Bashkir',
136 'bm' => 'Bambara',
137 'eu' => 'Basque',
138 'be' => 'Belarusian',
139 'bn' => 'Bengali',
140 'bh' => 'Bihari',
141 'bi' => 'Bislama',
142 'bs' => 'Bosnian',
143 'br' => 'Breton',
144 'bg' => 'Bulgarian',
145 'my' => 'Burmese',
146 'ca' => 'Catalan; Valencian',
147 'ch' => 'Chamorro',
148 'ce' => 'Chechen',
149 'zh' => 'Chinese',
150 'cu' => 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic',
151 'cv' => 'Chuvash',
152 'kw' => 'Cornish',
153 'co' => 'Corsican',
154 'cr' => 'Cree',
155 'cs' => 'Czech',
156 'da' => 'Danish',
157 'dv' => 'Divehi; Dhivehi; Maldivian',
158 'nl' => 'Dutch; Flemish',
159 'dz' => 'Dzongkha',
160 'en' => 'English',
161 'eo' => 'Esperanto',
162 'et' => 'Estonian',
163 'ee' => 'Ewe',
164 'fo' => 'Faroese',
165 'fj' => 'Fijjian',
166 'fi' => 'Finnish',
167 'fr' => 'French',
168 'fy' => 'Western Frisian',
169 'ff' => 'Fulah',
170 'ka' => 'Georgian',
171 'de' => 'German',
172 'gd' => 'Gaelic; Scottish Gaelic',
173 'ga' => 'Irish',
174 'gl' => 'Galician',
175 'gv' => 'Manx',
176 'el' => 'Greek, Modern',
177 'gn' => 'Guarani',
178 'gu' => 'Gujarati',
179 'ht' => 'Haitian; Haitian Creole',
180 'ha' => 'Hausa',
181 'he' => 'Hebrew',
182 'hz' => 'Herero',
183 'hi' => 'Hindi',
184 'ho' => 'Hiri Motu',
185 'hu' => 'Hungarian',
186 'ig' => 'Igbo',
187 'is' => 'Icelandic',
188 'io' => 'Ido',
189 'ii' => 'Sichuan Yi',
190 'iu' => 'Inuktitut',
191 'ie' => 'Interlingue',
192 'ia' => 'Interlingua (International Auxiliary Language Association)',
193 'id' => 'Indonesian',
194 'ik' => 'Inupiaq',
195 'it' => 'Italian',
196 'jv' => 'Javanese',
197 'ja' => 'Japanese',
198 'kl' => 'Kalaallisut; Greenlandic',
199 'kn' => 'Kannada',
200 'ks' => 'Kashmiri',
201 'kr' => 'Kanuri',
202 'kk' => 'Kazakh',
203 'km' => 'Central Khmer',
204 'ki' => 'Kikuyu; Gikuyu',
205 'rw' => 'Kinyarwanda',
206 'ky' => 'Kirghiz; Kyrgyz',
207 'kv' => 'Komi',
208 'kg' => 'Kongo',
209 'ko' => 'Korean',
210 'kj' => 'Kuanyama; Kwanyama',
211 'ku' => 'Kurdish',
212 'lo' => 'Lao',
213 'la' => 'Latin',
214 'lv' => 'Latvian',
215 'li' => 'Limburgan; Limburger; Limburgish',
216 'ln' => 'Lingala',
217 'lt' => 'Lithuanian',
218 'lb' => 'Luxembourgish; Letzeburgesch',
219 'lu' => 'Luba-Katanga',
220 'lg' => 'Ganda',
221 'mk' => 'Macedonian',
222 'mh' => 'Marshallese',
223 'ml' => 'Malayalam',
224 'mi' => 'Maori',
225 'mr' => 'Marathi',
226 'ms' => 'Malay',
227 'mg' => 'Malagasy',
228 'mt' => 'Maltese',
229 'mo' => 'Moldavian',
230 'mn' => 'Mongolian',
231 'na' => 'Nauru',
232 'nv' => 'Navajo; Navaho',
233 'nr' => 'Ndebele, South; South Ndebele',
234 'nd' => 'Ndebele, North; North Ndebele',
235 'ng' => 'Ndonga',
236 'ne' => 'Nepali',
237 'nn' => 'Norwegian Nynorsk; Nynorsk, Norwegian',
238 'nb' => 'Bokmål, Norwegian, Norwegian Bokmål',
239 'no' => 'Norwegian',
240 'ny' => 'Chichewa; Chewa; Nyanja',
241 'oc' => 'Occitan, Provençal',
242 'oj' => 'Ojibwa',
243 'or' => 'Oriya',
244 'om' => 'Oromo',
245 'os' => 'Ossetian; Ossetic',
246 'pa' => 'Panjabi; Punjabi',
247 'fa' => 'Persian',
248 'pi' => 'Pali',
249 'pl' => 'Polish',
250 'pt' => 'Portuguese',
251 'ps' => 'Pushto',
252 'qu' => 'Quechua',
253 'rm' => 'Romansh',
254 'ro' => 'Romanian',
255 'rn' => 'Rundi',
256 'ru' => 'Russian',
257 'sg' => 'Sango',
258 'sa' => 'Sanskrit',
259 'sr' => 'Serbian',
260 'hr' => 'Croatian',
261 'si' => 'Sinhala; Sinhalese',
262 'sk' => 'Slovak',
263 'sl' => 'Slovenian',
264 'se' => 'Northern Sami',
265 'sm' => 'Samoan',
266 'sn' => 'Shona',
267 'sd' => 'Sindhi',
268 'so' => 'Somali',
269 'st' => 'Sotho, Southern',
270 'es' => 'Spanish; Castilian',
271 'sc' => 'Sardinian',
272 'ss' => 'Swati',
273 'su' => 'Sundanese',
274 'sw' => 'Swahili',
275 'sv' => 'Swedish',
276 'ty' => 'Tahitian',
277 'ta' => 'Tamil',
278 'tt' => 'Tatar',
279 'te' => 'Telugu',
280 'tg' => 'Tajik',
281 'tl' => 'Tagalog',
282 'th' => 'Thai',
283 'bo' => 'Tibetan',
284 'ti' => 'Tigrinya',
285 'to' => 'Tonga (Tonga Islands)',
286 'tn' => 'Tswana',
287 'ts' => 'Tsonga',
288 'tk' => 'Turkmen',
289 'tr' => 'Turkish',
290 'tw' => 'Twi',
291 'ug' => 'Uighur; Uyghur',
292 'uk' => 'Ukrainian',
293 'ur' => 'Urdu',
294 'uz' => 'Uzbek',
295 've' => 'Venda',
296 'vi' => 'Vietnamese',
297 'vo' => 'Volapük',
298 'cy' => 'Welsh',
299 'wa' => 'Walloon',
300 'wo' => 'Wolof',
301 'xh' => 'Xhosa',
302 'yi' => 'Yiddish',
303 'yo' => 'Yoruba',
304 'za' => 'Zhuang; Chuang',
305 'zu' => 'Zulu',
306 );
307 $language = strtr( $code, $lang_codes );
308 $lang = apply_filters( 'wpml_post_language_details', null, $postId );
309 if ( !empty( $lang ) ) {
310 $language = $lang['display_name'];
311 }
312 return strtolower( $language );
313 }
314 #endregion
315
316 #region Users/Sessions Helpers
317
318 function get_session_id() {
319 if ( isset( $_COOKIE['mwai_session_id'] ) ) {
320 return $_COOKIE['mwai_session_id'];
321 }
322 return "N/A";
323 }
324
325 // Get the UserID from the data, or from the current user
326 function get_user_id( $data = null ) {
327 if ( isset( $data ) && isset( $data['userId'] ) ) {
328 return (int)$data['userId'];
329 }
330 if ( is_user_logged_in() ) {
331 $current_user = wp_get_current_user();
332 if ( $current_user->ID > 0 ) {
333 return $current_user->ID;
334 }
335 }
336 return null;
337 }
338
339 function get_ip_address( $data = null ) {
340 if ( isset( $data ) && isset( $data['ip'] ) ) {
341 $data['ip'] = (string)$data['ip'];
342 }
343 else {
344 if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
345 $data['ip'] = sanitize_text_field( $_SERVER['REMOTE_ADDR'] );
346 }
347 else if ( isset( $_SERVER['HTTP_CLIENT_IP'] ) ) {
348 $data['ip'] = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] );
349 }
350 else if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
351 $data['ip'] = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] );
352 }
353 }
354 return $data['ip'];
355 }
356
357 #endregion
358
359 #region Other Helpers
360
361 function isUrl( $url ) {
362 return strpos( $url, 'http' ) === 0 ? true : false;
363 }
364
365 #endregion
366
367 #region Usage & Costs
368
369 public function record_tokens_usage( $model, $prompt_tokens, $completion_tokens = 0 ) {
370 if ( !is_numeric( $prompt_tokens ) ) {
371 throw new Exception( 'Record usage: prompt_tokens is not a number.' );
372 }
373 if ( !is_numeric( $completion_tokens ) ) {
374 $completion_tokens = 0;
375 }
376 if ( !$model ) {
377 throw new Exception( 'Record usage: model is missing.' );
378 }
379 $usage = $this->get_option( 'openai_usage' );
380 $month = date( 'Y-m' );
381 if ( !isset( $usage[$month] ) ) {
382 $usage[$month] = array();
383 }
384 if ( !isset( $usage[$month][$model] ) ) {
385 $usage[$month][$model] = array(
386 'prompt_tokens' => 0,
387 'completion_tokens' => 0,
388 'total_tokens' => 0
389 );
390 }
391 $usage[$month][$model]['prompt_tokens'] += $prompt_tokens;
392 $usage[$month][$model]['completion_tokens'] += $completion_tokens;
393 $usage[$month][$model]['total_tokens'] += $prompt_tokens + $completion_tokens;
394 $this->update_option( 'openai_usage', $usage );
395 return [
396 'prompt_tokens' => $prompt_tokens,
397 'completion_tokens' => $completion_tokens,
398 'total_tokens' => $prompt_tokens + $completion_tokens
399 ];
400 }
401
402 public function record_images_usage( $model, $resolution, $images ) {
403 if ( !$model || !$resolution || !$images ) {
404 throw new Exception( 'Missing parameters for record_image_usage.' );
405 }
406 $usage = $this->get_option( 'openai_usage' );
407 $month = date( 'Y-m' );
408 if ( !isset( $usage[$month] ) ) {
409 $usage[$month] = array();
410 }
411 if ( !isset( $usage[$month][$model] ) ) {
412 $usage[$month][$model] = array(
413 'resolution' => array(),
414 'images' => 0
415 );
416 }
417 if ( !isset( $usage[$month][$model]['resolution'][$resolution] ) ) {
418 $usage[$month][$model]['resolution'][$resolution] = 0;
419 }
420 $usage[$month][$model]['resolution'][$resolution] += $images;
421 $usage[$month][$model]['images'] += $images;
422 $this->update_option( 'openai_usage', $usage );
423 return [
424 'resolution' => $resolution,
425 'images' => $images
426 ];
427 }
428
429 #endregion
430
431 #region Options
432 function get_all_options() {
433 $options = get_option( $this->option_name, null );
434 foreach ( MWAI_OPTIONS as $key => $value ) {
435 if ( !isset( $options[$key] ) ) {
436 $options[$key] = $value;
437 }
438 if ( $key === 'languages' ) {
439 // TODO: If we decide to make a set of options for languages, we can keep it in the settings
440 $options[$key] = MWAI_LANGUAGES;
441 $options[$key] = apply_filters( 'mwai_languages', $options[$key] );
442 }
443 }
444 $options['shortcode_chat_default_params'] = MWAI_CHATBOT_PARAMS;
445 $options['default_limits'] = MWAI_LIMITS;
446 $options['openai_models'] = MWAI_OPENAI_MODELS;
447 return $options;
448 }
449
450 // Validate and keep the options clean and logical.
451 function sanitize_options() {
452 $options = $this->get_all_options();
453 $needs_update = false;
454
455 // We can sanitize our future options here, let's always remember it.
456 // Now, it is empty...
457
458 if ( $needs_update ) {
459 update_option( $this->option_name, $options, false );
460 }
461 return $options;
462 }
463
464 function update_options( $options ) {
465 if ( !update_option( $this->option_name, $options, false ) ) {
466 return false;
467 }
468 $options = $this->sanitize_options();
469 return $options;
470 }
471
472 function update_option( $option, $value ) {
473 $options = $this->get_all_options();
474 $options[$option] = $value;
475 return $this->update_options( $options );
476 }
477
478 function get_option( $option, $default = null ) {
479 $options = $this->get_all_options();
480 return $options[$option] ?? $default;
481 }
482 #endregion
483 }
484
485 ?>