chatbot-chatgpt.css
3 years ago
chatbot-chatgpt.scss
3 years ago
chatbot.php
3 years ago
contentaware.php
3 years ago
imagesbot.php
3 years ago
contentaware.php
27 lines
| 1 | <?php |
| 2 | |
| 3 | class Meow_MWAI_Modules_ContentAware { |
| 4 | |
| 5 | function __construct() { |
| 6 | add_filter( 'mwai_chatbot_params_before', array( $this, 'chatbot_params' ) ); |
| 7 | } |
| 8 | |
| 9 | function chatbot_params( $params ) { |
| 10 | if ( !isset( $params['content_aware'] ) ) { |
| 11 | return $params; |
| 12 | } |
| 13 | $post = get_post(); |
| 14 | if ( !empty( $post ) ) { |
| 15 | // Before adding the content in the context, we should absolutely remove the HTML tags, |
| 16 | // the shortcodes, and the empty lines. Then lines should be replaced by a textual "\n". |
| 17 | $content = strip_tags( $post->post_content ); |
| 18 | $content = preg_replace( '/\[[^\]]+\]/', '', $content ); |
| 19 | $content = preg_replace( '/^\h*\v+/m', '', $content ); |
| 20 | $content = preg_replace( '/\v+/', "\\n", $content ); |
| 21 | $params['context'] = "Article:\\n\\n{***}\\n{$content}\\n{***}.\\n\\nDebate:\\n\\n"; |
| 22 | $params['start_sentence'] = "Is there anything you would like to discuss about this article?"; |
| 23 | } |
| 24 | return $params; |
| 25 | } |
| 26 | } |
| 27 |