Plugin Directory

Changeset 3237554


Ignore:
Timestamp:
02/10/2025 03:42:07 AM (12 months ago)
Author:
wpgrids
Message:

Release v1.2.9

Location:
ai-content-generation
Files:
61 added
6 edited

Legend:

Unmodified
Added
Removed
  • ai-content-generation/trunk/assets/js/wpwand-gutenberg.js

    r3211354 r3237554  
    249249
    250250    $(document).ready(function ($) {
     251        let isEventBound = false;
     252
    251253        wp.data.subscribe(function () {
    252254            if ('top' == wpwand_glb.toggler_positions && $('body').hasClass('block-editor-page')) {
    253 
    254255                if (!$('.edit-post-header-toolbar').find('.wpwand-trigger').length) {
    255 
    256256                    $('.edit-post-header-toolbar').append('<a class="wpwand-trigger" href="#"><img src="' + wpwand_glb.logo + '">AI Assistant</a>')
    257 
    258257                }
    259258            }
    260259            if (0 == wpwand_glb.hide_ai_bar) {
    261 
    262260                if (!$('.editor-styles-wrapper').find('.wpwand-prompt-form').length) {
    263261                    let prompt_form = '<div class="wpwand-prompt-form" id="wpwand-prompt-form"><div class="wpwand-dr-prompt-input"><img src="' + wpwand_glb.logo + '">  <a class="wpwand-ai-bar-hiw" href="https://wpwand.com/how-ai-assistant-work" target="_blank">See how it works</a>      <input type="text" placeholder="Ask AI to write anything..."></div></div>';
    264262                    $('.editor-styles-wrapper').append(prompt_form);
    265263
    266 
    267                     $('#wpwand-prompt-form input').keypress(function (event) {
    268 
    269                         var keycode = (event.keyCode ? event.keyCode : event.which);
    270                         if (keycode == '13') {
    271                             const $this = $(this);
    272 
    273 
    274                             wpwand_prompt_ajax($this);
    275                         }
    276 
    277                     });
    278                 }
    279             }
    280 
    281 
     264                    // Only bind event if not already bound
     265                    if (!isEventBound) {
     266                        $(document).on('keydown', '#wpwand-prompt-form input', function(event) {
     267                            if (event.keyCode === 13 || event.which === 13) {
     268                                event.preventDefault();
     269                                event.stopPropagation();
     270                                const $this = $(this);
     271                                if ($this.val().trim()) {
     272                                    wpwand_prompt_ajax($this);
     273                                }
     274                                return false;
     275                            }
     276                        });
     277                        isEventBound = true;
     278                    }
     279                }
     280            }
    282281        });
    283     })
     282    });
    284283
    285284
  • ai-content-generation/trunk/inc/admin.php

    r3220881 r3237554  
    9494                                </td>
    9595                            </tr>
     96                            <tr valign="top">
     97                                <th scope="row">
     98                                    <label for="wpwand_deepseek_api_key">
     99                                        <?php esc_html_e('DeepSeek API Key', 'wp-wand'); ?>
     100                                        <span class="wpwand-field-desc">Add your DeepSeek API key to activate
     101                                            <?php echo esc_html(wpwand_brand_name()) ?>
     102                                        </span>
     103                                    </label>
     104                                </th>
     105                                <td class="wpwand-field">
     106                                    <input type="text" id="wpwand_deepseek_api_key" name="wpwand_deepseek_api_key" class="regular-text"
     107                                        value="<?php echo esc_attr(wpwand_get_option('wpwand_deepseek_api_key')); ?>" />
     108                                    <div class="wpwand_api_key_status">
     109
     110                                        <svg width="16" height="16" viewBox="0 0 16 16" fill="none"
     111                                            xmlns="http://www.w3.org/2000/svg">
     112                                            <path fill-rule="evenodd" clip-rule="evenodd"
     113                                                d="M8 16C12.4183 16 16 12.4183 16 8C16 3.58172 12.4183 0 8 0C3.58172 0 0 3.58172 0 8C0 12.4183 3.58172 16 8 16ZM11.7071 6.70711C12.0976 6.31658 12.0976 5.68342 11.7071 5.29289C11.3166 4.90237 10.6834 4.90237 10.2929 5.29289L7 8.58579L5.70711 7.29289C5.31658 6.90237 4.68342 6.90237 4.29289 7.29289C3.90237 7.68342 3.90237 8.31658 4.29289 8.70711L6.29289 10.7071C6.68342 11.0976 7.31658 11.0976 7.70711 10.7071L11.7071 6.70711Z"
     114                                                fill="<?php echo esc_attr(WPWAND_DEEPSEEK_KEY) ? '#3BCB38' : '#D1D6DB' ?>" />
     115                                        </svg>
     116
     117                                        <span>
     118                                            <?php printf($activate_text) // phpcs:ignore
     119                                            ?>
     120                                        </span>
     121                                    </div>
     122                                </td>
     123                            </tr>
     124
    96125
    97126                            <?php if ((WPWAND_OPENAI_KEY) || (WPWAND_CLAUDE_KEY)): ?>
     
    134163
    135164                                            <?php endif; ?>
     165                                            <?php if (WPWAND_DEEPSEEK_KEY): ?>
     166                                                <optgroup label="DeepSeek Models">
     167                                                    <option value="deepseek-reasoner" <?php selected(wpwand_get_option('wpwand_model', 'deepseek-reasoner'), 'deepseek-reasoner'); ?>>
     168                                                        <?php esc_html_e('DeepSeek Reasoner (R1)', 'wp-wand'); ?></option>
     169                                                    <option value="deepseek-chat" <?php selected(wpwand_get_option('wpwand_model', 'deepseek-chat'), 'deepseek-chat'); ?>>
     170                                                        <?php esc_html_e('DeepSeek Chat', 'wp-wand'); ?></option>
     171                                                </optgroup>
     172
     173                                            <?php endif; ?>
    136174                                        </select>
    137175                                    </td>
     
    321359        )
    322360    );
     361    register_setting(
     362        'wpwand_settings_group',
     363        'wpwand_deepseek_api_key',
     364        array(
     365            'type' => 'string',
     366            'description' => esc_html__('DeepSeek API Key', 'wp-wand'),
     367            'sanitize_callback' => 'sanitize_text_field',
     368            'validate_callback' => 'wpwand_validate_deepseek_api_key',
     369        )
     370    );
    323371
    324372
     
    442490    if (!preg_match('/^sk-/', $input)) {
    443491        add_settings_error('wpwand_api_key', 'wpwand_api_key_invalid', esc_html__('Invalid OpenAI API key format.', 'wp-wand'));
    444         return get_option('wpwand_api_key');
     492        return wpwand_get_option('wpwand_api_key');
    445493    }
    446494
     
    455503    if (!preg_match('/^[a-zA-Z0-9_\-]+$/i', $input)) {
    456504        add_settings_error('wpwand_claude_api_key', 'wpwand_claude_api_key_invalid', esc_html__('Invalid Claude API key format.', 'wp-wand'));
    457         return get_option('wpwand_claude_api_key');
     505        return wpwand_get_option('wpwand_claude_api_key');
    458506    }
    459507
    460508    return $input;
    461509}
     510
     511/**
     512 * Validate DeepSeek API Key
     513 */
     514function wpwand_validate_deepseek_api_key($input)
     515{
     516    if (!preg_match('/^sk-/', $input)) {
     517        add_settings_error('wpwand_deepseek_api_key', 'wpwand_deepseek_api_key_invalid', esc_html__('Invalid DeepSeek API key format.', 'wp-wand'));
     518        return wpwand_get_option('wpwand_deepseek_api_key');
     519    }
     520
     521    return $input;
     522}
     523
    462524
    463525
  • ai-content-generation/trunk/inc/api.php

    r3220881 r3237554  
    6161        foreach ($content->choices as $choice) {
    6262            $reply = isset($choice->message) ? $choice->message->content : $choice->text;
     63            $reasoning_content = isset($choice->message->reasoning_content) ? $choice->message->reasoning_content : '';
     64
     65            // <div class="wpwand-ai-reasoning">
     66            // ' . $reasoning_content . '
     67            // </div>
    6368
    6469            $text .= '<div class="wpwand-content">
     70       
    6571            <button class="wpwand-copy-button" >
    6672            <svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
     
    6975            Copy to Clipboard
    7076            </button>
     77       
    7178            ' . $is_elementor . $is_gutenberg . '<div class="wpwand-ai-response">' . wpautop($reply) . '
    7279            </div></div>';
     
    332339        return 'claude';
    333340    }
     341    if ($model && strpos($model, 'deepseek') !== false) {
     342        return 'deepseek';
     343    }
    334344    return 'openai';
    335345}
     
    337347function wpwand_ai_error($error)
    338348{
    339     $source = isset($error->type) && strpos($error->type, 'claude') !== false ? 'claude' : 'openai';
     349    $source = isset($error->type) && strpos($error->type, 'claude') !== false ? 'claude' : (isset($error->type) && strpos($error->type, 'deepseek') !== false ? 'deepseek' : 'openai');
    340350    $provider = ucfirst($source);
     351    // if curl error then add server error / server is not responding
     352    if (isset($error->message) && strpos($error->message, 'curl') !== false) {
     353        return "{$provider} Error: Server is not responding";
     354    }
    341355    return "{$provider} Error: " . $error->message;
    342356}
    343357
    344 
    345 
    346 function wpwand_claude($prompt, $number_of_result = 1, $args = [])
     358/*
     359// deprecated
     360function wpwand_claude($prompt, $number_of_result = 1, $args = []) 
    347361{
    348362    try {
     
    395409}
    396410
    397 
     411 */
    398412
    399413function wpwand_openAi($prompt, $number_of_result = 1, $args = [])
     
    445459                array(
    446460                    'role' => 'user',
    447                     'content' => "{$variation_prefix}{$prompt} You must write in {$args['language']}. {$args['biz_details']} {$args['targated_customer']} and don't add any other text"
     461                    'content' => "{$variation_prefix}{$prompt} You must write in {$args['language']}. {$args['biz_details']} {$args['targated_customer']}"
    448462                )
    449463            ),
     
    484498}
    485499
     500function wpwand_generate_deepseek_content($prompt, $number_of_result, $args, $request_config)
     501{
     502    $endpoint = 'https://api.deepseek.com/v1/chat/completions';
     503
     504
     505    return wpwand_generate_common_ai_content($endpoint, $prompt, $number_of_result, $args, $request_config);
     506}
     507
    486508function wpwand_generate_openai_content($prompt, $number_of_result, $args, $request_config)
    487509{
    488510    $endpoint = 'https://api.openai.com/v1/chat/completions';
    489     $request_config['headers']['Authorization'] = 'Bearer ' . WPWAND_OPENAI_KEY;
    490 
    491     $model = isset($args['model']) && !empty($args['model']) ? $args['model'] :  'gpt-3.5-turbo';
     511
     512
     513
     514    /*     $model = isset($args['model']) && !empty($args['model']) ? $args['model'] :  'gpt-3.5-turbo';
    492515    $body = array(
    493516        'model' => $model,
     
    518541    if (isset($response_body->error)) {
    519542        throw new Exception($response_body->error->message);
    520     }
    521 
    522     return $response_body;
     543    } */
     544
     545    return wpwand_generate_common_ai_content($endpoint, $prompt, $number_of_result, $args, $request_config);
     546}
     547
     548
     549
     550function wpwand_generate_common_ai_content($endpoint, $prompt, $number_of_result, $args, $request_config)
     551{
     552    $model = isset($args['model']) && !empty($args['model']) ? $args['model'] : 'gpt-3.5-turbo';
     553    $request_config['headers']['Authorization'] = wpwand_api_source($model) == 'deepseek' ? 'Bearer ' . WPWAND_DEEPSEEK_KEY : 'Bearer ' . WPWAND_OPENAI_KEY;
     554   
     555    // Base variations for multiple results
     556    $variations = array(
     557        "Provide a unique perspective on this: ",
     558        "Give a different take on this topic: ",
     559        "Approach this from another angle: ",
     560        "Offer an alternative view on this: ",
     561        "Present a fresh perspective on this: "
     562    );
     563
     564    $responses = array();
     565   
     566    // Make multiple requests for multiple results
     567    for ($i = 0; $i < $number_of_result; $i++) {
     568        // Add variation prefix for multiple results
     569        $variation_prefix = $number_of_result > 1 ? ($variations[$i % count($variations)] ?? '') : '';
     570       
     571        $body = [
     572            'model' => $model,
     573            'messages' => [
     574                [
     575                    'role' => 'system',
     576                    'content' => "You are a professional content writer. You must follow the system instructions strictly."
     577                ],
     578                [
     579                    'role' => 'system',
     580                    'content' => "You must write in {$args['language']}. {$args['biz_details']} {$args['targated_customer']}"
     581                ],
     582                [
     583                    'role' => 'user',
     584                    'content' => "{$variation_prefix}{$prompt} . You must follow this instructions strictly. Don't add any other text/explanation/multiple results. Just write the content."
     585                ]
     586            ],
     587            'temperature' => $args['temperature'] + ($i * 0.1), // Slightly vary temperature for diversity
     588            'max_tokens' => $args['max_tokens'],
     589            'frequency_penalty' => (float) wpwand_get_option('wpwand_frequency', 0),
     590            'presence_penalty' => (float) wpwand_get_option('wpwand_presence_penalty', 0)
     591        ];
     592
     593        $response = wp_safe_remote_post($endpoint, array_merge(
     594            $request_config,
     595            array('body' => json_encode($body))
     596        ));
     597
     598        if (is_wp_error($response)) {
     599            throw new Exception($response->get_error_message());
     600        }
     601
     602        $response_body = json_decode(wp_remote_retrieve_body($response));
     603
     604        if (isset($response_body->error)) {
     605            throw new Exception($response_body->error->message);
     606        }
     607
     608        $responses[] = $response_body;
     609    }
     610
     611    // Combine all responses into a single response object
     612    $combined_response = new stdClass();
     613    $combined_response->choices = array();
     614   
     615    foreach ($responses as $resp) {
     616        if (isset($resp->choices) && !empty($resp->choices)) {
     617            $combined_response->choices[] = $resp->choices[0];
     618        }
     619    }
     620
     621    return $combined_response;
    523622}
    524623
     
    558657
    559658        $is_claude = 'claude' === wpwand_api_source($args['model']);
     659        $is_deepseek = 'deepseek' === wpwand_api_source($args['model']);
    560660
    561661        // Generate content based on the model type
     
    566666                throw new Exception('Claude API key is missing');
    567667            }
     668        } else if ($is_deepseek) {
     669            if (WPWAND_DEEPSEEK_KEY && !empty(WPWAND_DEEPSEEK_KEY)) {
     670                $response = wpwand_generate_deepseek_content($prompt, $number_of_result, $args, $request_config);
     671            } else {
     672                throw new Exception('DeepSeek API key is missing');
     673            }
    568674        } else {
    569675            if (WPWAND_OPENAI_KEY && !empty(WPWAND_OPENAI_KEY)) {
     
    579685            'error' => (object) [
    580686                'message' => $e->getMessage(),
    581                 'type' => $is_claude ? 'claude_error' : 'openai_error',
     687                'type' => $is_claude ? 'claude_error' : ($is_deepseek ? 'deepseek_error' : 'openai_error'),
    582688                'code' => 500
    583689            ]
  • ai-content-generation/trunk/inc/frontend.php

    r3220881 r3237554  
    3131
    3232
    33             <?php if (!WPWAND_OPENAI_KEY && !WPWAND_CLAUDE_KEY): ?>
     33            <?php if (!WPWAND_OPENAI_KEY && !WPWAND_CLAUDE_KEY && !WPWAND_DEEPSEEK_KEY): ?>
    3434                <!-- wp wand api missing notice  -->
    3535
  • ai-content-generation/trunk/readme.txt

    r3220882 r3237554  
    55Requires at least: 5.0
    66Tested up to:  6.7.1
    7 Stable Tag: 1.2.8
     7Stable Tag: 1.2.9
    88License: GPL-2.0+
    99License URI: http://www.gnu.org/licenses/gpl-2.0.txt
     
    308308== Changelog ==
    309309
     310= 1.2.9 =
     311* New: Deepseek R1 Added.
     312* New: Deepseek Chat Added.
     313* Fixed: Minor issues.
     314
    310315= 1.2.8 =
    311316* New: Claude 3.5 Sonnet Added.
  • ai-content-generation/trunk/wp-wand.php

    r3220881 r3237554  
    55 * Plugin URI: https://wpwand.com/
    66 * Description: WP Wand is a AI content generation plugin for WordPress that helps your team create high quality content 10X faster and 50x cheaper. No monthly subscription required.
    7  * Version: 1.2.8
     7 * Version: 1.2.9
    88 * Author: WP Wand
    99 * Author URI: https://wpwand.com/
     
    3737if (!defined('WPWAND_CLAUDE_KEY')) {
    3838    define('WPWAND_CLAUDE_KEY', get_option('wpwand_claude_api_key', false));
     39}
     40if (!defined('WPWAND_DEEPSEEK_KEY')) {
     41    define('WPWAND_DEEPSEEK_KEY', get_option('wpwand_deepseek_api_key', false));
    3942}
    4043define('WPWAND_AI_CHARACTER', '');
Note: See TracChangeset for help on using the changeset viewer.