Plugin Directory

Changeset 3138208


Ignore:
Timestamp:
08/20/2024 01:25:12 PM (20 months ago)
Author:
codeapple
Message:
  • Added latest ChatGPT-4o support
  • Minor bug fixes
  • Updated to work better & faster
  • Minor UI updated
Location:
wordai
Files:
49 added
9 edited

Legend:

Unmodified
Added
Removed
  • wordai/trunk/admin/css/sc-wordai-misc-styles.css

    r3072955 r3138208  
    128128  font-size: 14px;
    129129  vertical-align: middle;
    130   font-weight: bold
     130  font-weight: bold;
     131  cursor: pointer; 
    131132}
    132133.scwordai-notice-wrapper h3 {
     
    249250    font-size: 16px;
    250251    font-weight: bold;
    251     width: 12%;
     252    width: 16%;
    252253    font-family: 'Merienda', Arial, Helvetica, sans-serif;
    253254}
  • wordai/trunk/admin/js/sc-wordai-content-generate-script.js

    r3072955 r3138208  
    6262                     scWordAIContentGenerationTotalItemsTracker++;               
    6363                     resolve( data );
    64                     // console.log(data);
     64                    console.log(data);
    6565                    },
    6666                  error: function( xhr, status, error ) {
     
    292292                            scCompleteResponse              = '';
    293293                            //console.log(e);
    294                             //console.log('Progress [Response Chunk]...');                                             
     294                            // console.log('Progress [Response Chunk]...');                                             
    295295                            scChunkResponse                 =   e.target.response;                         
    296                             //console.log(scChunkResponse);
     296                            // console.log(scChunkResponse);
    297297                            scCompleteResponse              = scWordAIProcessGroupOfChunkResponse(scChunkResponse);
    298                             //console.log( 'Chunk Complete Response:'+ scCompleteResponse );                           
     298                            // console.log( 'Chunk Complete Response:'+ scCompleteResponse );                           
    299299                            scWordAIResponseErrorMessage    = ( scCompleteResponse[0] !== undefined && scCompleteResponse[0].error !== undefined )? scCompleteResponse[0].errorData : '';
    300300                            //scCompleteResponse                = scCompleteResponse.replace(/^\"/g, '').replace(/\"$/g, '');
     
    355355                            scCompleteResponse              = '';
    356356                            //console.log(e);
    357                             //console.log('Progress [Response Chunk]...');                                             
     357                            // console.log('Progress [Response Chunk]...');                                             
    358358                            scChunkResponse                 =   e.target.response;                         
    359                             //console.log(scChunkResponse);
     359                            // console.log(scChunkResponse);
    360360                            scCompleteResponse              = scWordAIProcessGroupOfChunkResponse(scChunkResponse);                         
    361361                            //console.log( scCompleteResponse );                           
     
    476476                            scCompleteResponse              = '';
    477477                            //console.log(e);
    478                             //console.log('Progress [Response Chunk]...');                                             
     478                            console.log('Progress [Response Chunk]...');                                               
    479479                            scChunkResponse                 = e.target.response;                           
    480                             //console.log(scChunkResponse);
     480                            console.log(scChunkResponse);
    481481                            scCompleteResponse              = scWordAIProcessGroupOfChunkResponse(scChunkResponse);                         
    482                             //console.log( scCompleteResponse );                           
     482                            console.log( scCompleteResponse );                         
    483483                            scWordAIResponseErrorMessage    = ( scCompleteResponse[0] !== undefined && scCompleteResponse[0].error !== undefined )? scCompleteResponse[0].errorData : '';
    484484                            $('.sc-wordai-generated-tags').val(scCompleteResponse.replace(/\n/g, "").replace(/\\/, "") );                           
     
    528528        let scWordAIContentGenerateCancelButton     = $('.sc-wordai-generate-cancel-requests-content-btn');
    529529       
    530         console.log('scWordAIContentGenerationTotalItemsTracker: '+ scWordAIContentGenerationTotalItemsTracker );
     530        // console.log('scWordAIContentGenerationTotalItemsTracker: '+ scWordAIContentGenerationTotalItemsTracker );
    531531        if ( scWordAIContentGenerationTotalItems == scWordAIContentGenerationTotalItemsTracker ) {
    532532            scWordAIProcessAutoInsertItemsIntoEditor();
     
    599599                // Process valid response   
    600600                scListedChunkProgressResponse           = scChunkResponse.split('\n\n');
    601                 //console.log( scListedChunkProgressResponse );
     601                // console.log( scListedChunkProgressResponse );
     602                // console.log('FOR LOOP LENGTH: '+ scListedChunkProgressResponse.length );
    602603                try {
    603                     for( let i = 0; i < scListedChunkProgressResponse.length; i++ ) {
    604                         if ( $.trim(scListedChunkProgressResponse[i]).length != 0 ) {                   
     604                    // First chunk contain always empty response like {"role":"assistant","content":""}
     605                    for( let i = 1; i < scListedChunkProgressResponse.length; i++ ) {
     606                        // console.log('FOR LOOP: ');
     607                        // console.log( scListedChunkProgressResponse[i] );
     608                        // console.log( scListedChunkProgressResponse[i].length );
     609                        // if ( $.trim( scListedChunkProgressResponse[i] ).length != 0 ) {                 
     610                        if ( scListedChunkProgressResponse[i] ) {                   
    605611                            let jsonParsedData          =  JSON.parse( scListedChunkProgressResponse[i] );                             
     612                            // console.log('scWordAIProcessGroupOfChunkResponse Invoked - Inside Process Data FOR LOOP: ');                         
     613                            // console.log( jsonParsedData.choices[0].delta.content );
    606614                            scWordAIProcessedResponse   += ( jsonParsedData.choices[0].delta.content != undefined )? jsonParsedData.choices[0].delta.content : '';
     615                            // console.log( scWordAIProcessedResponse );
    607616                        }
    608                     }
     617                    } // for
    609618                }
    610619                catch(e) {
    611                     //console.log(scListedChunkProgressResponse[i]);
    612                     //console.log(e);
     620                    // console.log('Catch Error( scWordAIProcessGroupOfChunkResponse ): ');
     621                    console.log(scListedChunkProgressResponse[i]);
     622                    console.log(e);
    613623                }
    614624                finally {
  • wordai/trunk/admin/js/wordai-admin-view-script.js

    r3072955 r3138208  
    209209            case 'excerpt':                 
    210210                    try {
    211                         await wp.data.dispatch('core/block-editor').insertBlocks( wp.blocks.createBlock( 'core/post-excerpt', { content: content }) );
     211                        // await wp.data.dispatch('core/block-editor').insertBlocks( wp.blocks.createBlock( 'core/post-excerpt', { content: content }) );
     212                        await wp.data.dispatch('core/block-editor').insertBlocks( wp.blocks.createBlock( 'core/post-excerpt', {}) );
    212213                    }
    213214                    finally {                       
  • wordai/trunk/admin/views/submenus-apisettings.php

    r3072955 r3138208  
    8282                </td>
    8383                <td>                   
    84                     <p class="sc-wordai-settings-text-hints"><?php esc_html_e('GPT-4 is a large multimodal model that can solve difficult problems with greater accuracy than any of previous models. GPT-4 is available in the OpenAI API to paying customers. The difference between GPT-4 and GPT-3.5 models is not significant. However, in more complex reasoning situations, GPT-4 is much more capable than any of OpenAI previous models. GPT-3.5 Turbo is most capable and cost effective model in the GPT-3.5 family.', 'wordai');?></p>
     84                    <p class="sc-wordai-settings-text-hints"><?php esc_html_e('GPT-4o is the latest step in pushing the boundaries of deep learning, in the direction of practical usability. GPT-4o is 2x faster, half the price, and has 5x higher rate limits compared to GPT-4 Turbo. GPT-4 is a large multimodal model that can solve difficult problems with greater accuracy than any of previous models. GPT-4 is available in the OpenAI API to paying customers. The difference between GPT-4 and GPT-3.5 models is not significant. However, in more complex reasoning situations, GPT-4 is much more capable than any of OpenAI previous models. GPT-3.5 Turbo is most capable and cost effective model in the GPT-3.5 family.', 'wordai');?></p>
    8585                </td>                   
    8686            </tr>               
  • wordai/trunk/includes/class-sftcy-wordai-ajaxhandler.php

    r3072955 r3138208  
    283283        check_ajax_referer( 'scwordai_wpnonce', 'security' );       
    284284        self::$output = [];             
    285         $post_data = isset( $_POST['postData'] ) ? sanitize_url( $_POST['postData'] ) : '';
     285        $post_data = isset( $_POST['postData'] ) ? sanitize_text_field( $_POST['postData'] ) : '';     
    286286        parse_str( $post_data, $params );                       
    287287        array_walk( $params, function( &$value, $key ) { $value = sanitize_text_field( $value ); });
    288         $params['sc-wordai-streaming']  = ( isset( $params['sc-wordai-streaming'] ) && $params['sc-wordai-streaming'] == 'on' )? 1 : 0;                                                 
     288        $params['sc-wordai-streaming']  = ( isset( $params['sc-wordai-streaming'] ) && $params['sc-wordai-streaming'] == 'on' )? 1 : 0;                                                        
    289289        $is_option_data_added           = get_option('sftcy-wordai-apisettings-data');
    290         $updated_options_data           = $is_option_data_added ? array_merge( maybe_unserialize( $is_option_data_added ), $params ) : $params;
    291         $update_data                    = update_option('sftcy-wordai-apisettings-data', maybe_serialize( $updated_options_data ) );       
     290        $updated_options_data           = $is_option_data_added ? array_merge( maybe_unserialize( $is_option_data_added ), $params ) : $params;     
     291        $update_data                    = update_option('sftcy-wordai-apisettings-data', maybe_serialize( $updated_options_data ) );               
    292292                           
    293293        if ( $update_data ) {
     
    501501       
    502502        if ( isset( SFTCY_Wordai_OpenAI::$output['status'] ) && SFTCY_Wordai_OpenAI::$output['status'] == 'success' ) {
    503             //var_dump( SC_Wordai_OpenAI::$output['responseText'] );
     503            // var_dump( SFTCY_Wordai_OpenAI::$output['responseText'] );
    504504            // pick the text between double quotes         
    505505            preg_match_all('/"([^"]+)"/', SFTCY_Wordai_OpenAI::$output['responseText'], $matches );
    506             //var_dump($matches );
     506            // var_dump($matches );
    507507            SFTCY_Wordai_OpenAI::$output['listOfTitles'] =  '';
    508508            $i = 1;
     
    573573               
    574574        $response               = SFTCY_Wordai_OpenAI::create_content( $api_params);       
    575         //var_dump( SFTCY_Wordai_OpenAI::$output );     
     575        // var_dump( SFTCY_Wordai_OpenAI::$output );       
    576576
    577577        //SFTCY_Wordai_OpenAI::$output['status']            = 'success';
  • wordai/trunk/includes/class-sftcy-wordai-openai.php

    r3072991 r3138208  
    1111    public static $AI_LISTMODEL_EP  = 'https://api.openai.com/v1/models';           
    1212    //public static $AI_COMPLETION_EP   = 'https://api.openai.com/v1/completions';      // OLD Models EP
    13     public static $AI_COMPLETION_EP = 'https://api.openai.com/v1/chat/completions';     // GPT-4 | GPT-3.5 Turbo Models EP
     13    public static $AI_COMPLETION_EP = 'https://api.openai.com/v1/chat/completions';     // GPT-4o | GPT-4 | GPT-3.5 Turbo Models EP
    1414    public static $AI_IMAGE_EP      = 'https://api.openai.com/v1/images/generations';
    1515       
     
    9393                    //$generated_prompt     = 'Write article about ' . sanitize_text_field( $prompt_hints ) . ' in language code ' . $content_settings['language_code'] . '. Style:' . $content_settings['sc-wordai-writing-style'] . '. Tone:' . $content_settings['sc-wordai-writing-tone'] .'.Article length will have '. sanitize_text_field( $content_length_readable ) .'.Each paragraph with heading title within 300 words.';       
    9494                    // Last Active
    95                     $generated_prompt       = 'Write article about ' . sanitize_text_field( $prompt_hints ) . ' in ' . $language_name . ' language. Style:' . $content_settings['sc-wordai-writing-style'] . '. Tone:' . $content_settings['sc-wordai-writing-tone'] .'. Article length will have '. $content_length_readable .'. Each paragraph with relevant heading within maximum 200 words.';                         
     95                    // $generated_prompt        = 'Write article about ' . sanitize_text_field( $prompt_hints ) . ' in ' . $language_name . ' language. Style:' . $content_settings['sc-wordai-writing-style'] . '. Tone:' . $content_settings['sc-wordai-writing-tone'] .'. Article length will have '. $content_length_readable .'. Each paragraph with relevant heading within maximum 200 words.';                         
     96                    $generated_prompt       = 'Write article about ' . sanitize_text_field( $prompt_hints ) . ' in ' . $language_name . ' language. Style:' . $content_settings['sc-wordai-writing-style'] . '. Tone:' . $content_settings['sc-wordai-writing-tone'] .'. Article length will have '. $content_length_readable .'. Each paragraph with relevant heading title.';
    9697                   
    9798                    // Inactive
     
    124125   
    125126    /**
     127     * Params ref: https://platform.openai.com/docs/api-reference/chat/create
    126128     * Get OpenAI API settings params
    127129     * return - array
     
    132134        // $openai_params['model'] = $data['sc-wordai-openai-model-slug'];
    133135        $openai_params['model'] = ! isset( $data['sc-wordai-openai-model-slug'] ) || empty( $data['sc-wordai-openai-model-slug'] )? self::$MODEL : trim( $data['sc-wordai-openai-model-slug'] );
    134         $openai_params['max_tokens'] = empty( $data['sc-wordai-max-tokens'] ) ? null : intval( $data['sc-wordai-max-tokens'] );
     136        $openai_params['max_tokens'] = empty( $data['sc-wordai-max-tokens'] ) ? null : intval( $data['sc-wordai-max-tokens'] ); // Ref: https://platform.openai.com/docs/api-reference/chat/create#chat-create-max_tokens
    135137        $openai_params['temperature'] = floatval( $data['sc-wordai-temperature'] );
    136138        $openai_params['top_p'] =  floatval( $data['sc-wordai-top-p'] );
    137139        $openai_params['presence_penalty'] = floatval( $data['sc-wordai-presence-penalty-input'] );
    138140        $openai_params['frequency_penalty'] = floatval( $data['sc-wordai-frequency-penalty-input'] );
    139         $openai_params['stop'] = $data['sc-wordai-stop-input'];     
     141        // $openai_params['stop'] = $data['sc-wordai-stop-input'];     
     142        $openai_params['stop'] = empty( $data['sc-wordai-stop-input'] )? null : trim( $data['sc-wordai-stop-input'] );  // Ref: https://platform.openai.com/docs/api-reference/chat/create#chat-create-stop
    140143       
    141144        if ( isset( $data['sc-wordai-streaming'] ) && $data['sc-wordai-streaming'] == 1 ) {
     
    209212     * Check Generated content
    210213     * If streaming true then 'responseBody' have null value
     214     * max_token - NULL - may truncate the response text / content
     215     * If max_token value larger than model's maximum support number then response will not be generated
    211216     * @since 1.0.0
    212217     */
     
    221226        }
    222227        else {
     228            // Last using $args
     229            // $args = array(
     230            //  'headers' => array(
     231            //      'Authorization' => 'Bearer ' . self::$API_KEY,
     232            //      'Content-Type'  => 'application/json',
     233            //  ),
     234            //  'timeout'           => 90,
     235            //  'httpversion'       => '1.0',
     236            //  'sslverify'         => false,
     237            //  'body'              => wp_json_encode( $api_params )           
     238            // );
     239
     240            // Modified - $args
    223241            $args = array(
    224242                'headers' => array(
    225243                    'Authorization' => 'Bearer ' . self::$API_KEY,
    226                     'Content-Type'  => 'application/json',
     244                    'Content-Type'  => 'application/json; charset=UTF-8',
    227245                ),
    228246                'timeout'           => 90,
    229247                'httpversion'       => '1.0',
    230                 'sslverify'         => false,
    231                 'body'              => wp_json_encode( $api_params )   
     248                'sslverify'         => false,                               
     249                'data_format'       => 'body', 
     250                'body'              => wp_json_encode( $api_params ),
    232251            );
    233252
     
    235254            // exit();
    236255
    237             $response = wp_remote_post( self::$AI_COMPLETION_EP, $args );               
     256            $response = wp_remote_post( self::$AI_COMPLETION_EP, $args );   // Last using           
     257           
     258           
     259            // var_dump( wp_remote_retrieve_body( $response ) );
     260            // exit;
    238261
    239262            if ( ! is_wp_error( $response ) ) {
    240263                $body = json_decode( wp_remote_retrieve_body( $response ), true );                             
     264                // var_dump( $body );
     265                // exit;
    241266                self::$output['responseBody'] = $body;
    242267                // response['choices'][0]['message']['content'] - GPT 3.5 Turbo / GPT-4 response format
    243268                // $body["choices"][0]["text"]                  - Old GPT models response format
    244                 if ( isset( $body['choices'][0]['message']['content'] ) ) {
     269                if ( isset( $body['choices'][0]['message']['content'] ) ) {                 
    245270                    self::$output['responseText'] = $body['choices'][0]['message']['content'];
    246271                    self::$output['status'] = 'success';
     
    324349     * @return  - string - Json string chunk data to browser
    325350     * Sample Chunks
    326        data: {"id":"chatcmpl-8OyJgfbdoPuV0h5jyS5LYGXKHQIU1","object":"chat.completion.chunk","created":1700962420,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"content":"The"},"finish_reason":null}]}
    327        data: {"id":"chatcmpl-8OyJgfbdoPuV0h5jyS5LYGXKHQIU1","object":"chat.completion.chunk","created":1700962420,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
    328        data: [DONE]                                         
     351     *  data: {"id":"chatcmpl-8OyJgfbdoPuV0h5jyS5LYGXKHQIU1","object":"chat.completion.chunk","created":1700962420,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"content":"The"},"finish_reason":null}]}
     352     *  data: {"id":"chatcmpl-8OyJgfbdoPuV0h5jyS5LYGXKHQIU1","object":"chat.completion.chunk","created":1700962420,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
     353     *  data: [DONE]                                           
    329354     *
    330355     * @since 1.0.0 
     
    356381            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1 );
    357382            curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($curl_info, $data) {
    358                 // echo wp_kses( self::wordai_raw_contents( $data ), self::wordai_allowed_html_tags() );
     383                // echo wp_kses( self::wordai_raw_contents( $data ), self::wordai_allowed_html_tags() );                               
    359384                echo self::wordai_raw_contents( $data );                                   
    360385                @ob_end_flush();
     
    371396     */
    372397    public static function wordai_raw_contents( $data = '' ) {
    373         return str_replace( 'data: ', '', $data );
     398        return str_replace( 'data: ', '', $data );     
    374399    }
    375400
     
    730755            'gpt-3.5-turbo'   => 'GPT-3.5 Turbo',
    731756            'gpt-4'           => 'GPT-4',
     757            'gpt-4o'          => 'GPT-4o'
    732758        ];
    733759       
  • wordai/trunk/includes/class-sftcy-wordai.php

    r3073033 r3138208  
    186186        $default_params['sc-wordai-frequency-penalty-input']    = 0;
    187187        $default_params['sc-wordai-best-of-input']              = 1;
    188         $default_params['sc-wordai-stop-input']                 = '\n';
     188        $default_params['sc-wordai-stop-input']                 = null; // Keep it null - if any chars mistyped then response may cut off
    189189       
    190190        return $default_params;
  • wordai/trunk/readme.txt

    r3073190 r3138208  
    22Contributors: codeapple, softcoy
    33Donate link: https://www.buymeacoffee.com/softcoy
    4 Tags: Openai chatgpt-4, AI based content generator, AI product description writer, Dall-e-3 HD image generator, AI Copilot
     4Tags: Openai chatgpt-4, AI based content generator, AI product description writer, Dall-e-3 HD image generator, AI Copilot, chatgpt-4o
    55Requires at least: 6.0
    66Tested up to: 6.5
    77Requires PHP: 7.2
    8 Stable tag: 1.0.2
     8Stable tag: 1.0.3
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3737* WooCommerce product Title / Description / Short Description Generation
    3838* WooCommerce product images Generation
    39 * Latest model GPT-4 supported
     39* Latest model GPT-4o supported
    4040
    4141
     
    7777
    7878= Can I use the latest model to generate content / images? =
    79 Yes, WordAI supports the latest GPT-4 model.
     79Yes, WordAI supports the latest GPT-4o model.
    8080
    8181= Can I limit the content paragraphs? =
     
    8585Yes, WordAI supports to set image sizes with image number limit, in 'Image Settings' menu page you can set those options.
    8686
     87= Why my result text / content are cut off / truncated ? =
     88If this happens then you have changed / set API parameters wrongly - just go to WordAI menu -> API Settings, click on 'Reset Settings' button to set all API parameters as default & check to see your results now. You may change ChatGPT model or other parameters as needed.
     89
     90= Why I do not see any output generated text / content ? =
     91You may have issue with streaming feature with your hosted server restriction / settings, You just uncheck the 'Streaming' option through WordAI menu -> API Settings, and then click 'Save API Settings' button to save the changes and check the result.
     92
    8793
    8894
    8995== Changelog ==
     96
     97= 1.0.3 =
     98* Added ChatGpt-4o
     99* Minor bugs fixed
     100* Updated to work better & faster
     101* Minor UI updated
     102
     103= 1.0.2 =
     104* Minor bugs fixed
     105
    90106= 1.0.0 =
    91107* Initialize released the plugin
     
    103119
    104120== Upgrade Notice ==
    105 = 1.0.0 =
    106 This is initial released version, new features will be added gradually so do upgrade when you see new update version available in your Plugins admin panel.
     121= 1.0.3 =
     122Upgrade to the latest version to avail all latest features
  • wordai/trunk/wordai.php

    r3073033 r3138208  
    44 * Plugin URI:  https://softcoy.com
    55 * Description: AI driven humanlike SEO friendly content writing with HD images generation based on OpenAI. Automatize your Post / Page / Product content writing tasks.
    6  * Version:     1.0.2
     6 * Version:     1.0.3
    77 * Author:      softcoy
    88 * Author URI:  https://softcoy.com/
     
    3636 
    3737if ( ! defined( 'SFTCY_WORDAI_VERSION') ) {
    38   define( 'SFTCY_WORDAI_VERSION', '1.0.2' );
     38  define( 'SFTCY_WORDAI_VERSION', '1.0.3' );
    3939}
    4040if ( ! defined( 'SFTCY_WORDAI_MINIMUM_PHP_VERSION') ) {
Note: See TracChangeset for help on using the changeset viewer.