Plugin Directory

Changeset 3665073


Ignore:
Timestamp:
08/25/2026 10:16:57 AM (2 months ago)
Author:
ejesgist
Message:

fix inconsistent formatting output with chat with AI

Location:
rankwell-ai/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • rankwell-ai/trunk/includes/ai/Transport.php

    r3663777 r3665073  
    55 * @package RankwellAI
    66 * @since 1.0.0
     7 * @version 1.0.1
    78 */
    89
    … …  
    1920class Transport {
    2021
    21         // phpcs:ignore PluginCheck.CodeAnalysis.AIProvider.DirectIntegration -- Direct Gemini integration is an intentional plugin feature.
     22    // phpcs:ignore PluginCheck.CodeAnalysis.AIProvider.DirectIntegration -- Direct Gemini integration is an intentional plugin feature.
    2223    private const GOOGLE_AI_URL = 'https://generativelanguage.googleapis.com/v1beta/models/';
    2324
    … …  
    99100    }
    100101
     102    /**
     103     * Check if the system prompt requests JSON output (SEO extras).
     104     *
     105     * @since 1.0.0
     106     * @param string $system_prompt The system prompt.
     107     * @return bool True if JSON output is requested.
     108     */
     109    private static function should_force_json(string $system_prompt): bool {
     110        return strpos($system_prompt, '"titles"') !== false ||
     111               strpos($system_prompt, '"slugs"') !== false ||
     112               strpos($system_prompt, '"keywords"') !== false;
     113    }
     114
    101115    private static function call_google_ai(string $system_prompt, string $user_message, string $action, string $model = '') {
    102116        if ('' === $model) {
    … …  
    119133            'generationConfig' => [
    120134                'temperature' => 0.3,
    121                 'responseMimeType' => 'application/json',
    122             ],
    123         ];
     135            ],
     136        ];
     137
     138        // Only force JSON for non-chat actions that request SEO extras.
     139        // Chat must be able to return plain text with markdown tables.
     140        if ($action !== 'chat' && self::should_force_json($system_prompt)) {
     141            $body['generationConfig']['responseMimeType'] = 'application/json';
     142        }
    124143
    125144        $response = wp_remote_post($url, [
    … …  
    182201        $body = [
    183202            'model' => $model,
    184             'response_format' => ['type' => 'json_object'],
    185203            'messages' => [
    186204                ['role' => 'system', 'content' => $system_prompt],
    … …  
    190208            'max_tokens' => 32768,
    191209        ];
     210
     211        // Only force JSON for non-chat actions that request SEO extras.
     212        if ($action !== 'chat' && self::should_force_json($system_prompt)) {
     213            $body['response_format'] = ['type' => 'json_object'];
     214        }
    192215
    193216        $response = wp_remote_post(self::DEEPSEEK_URL, [
    … …  
    213236        $body = [
    214237            'model' => $model,
    215             'response_format' => ['type' => 'json_object'],
    216238            'messages' => [
    217239                ['role' => 'system', 'content' => $system_prompt],
    … …  
    221243            'max_tokens' => 32768,
    222244        ];
     245
     246        // Only force JSON for non-chat actions that request SEO extras.
     247        if ($action !== 'chat' && self::should_force_json($system_prompt)) {
     248            $body['response_format'] = ['type' => 'json_object'];
     249        }
    223250
    224251        $response = wp_remote_post(self::CHATGPT_URL, [
    … …  
    255282        ];
    256283
    257         if (strpos($system_prompt, '"titles"') !== false || strpos($system_prompt, '"slugs"') !== false || strpos($system_prompt, '"keywords"') !== false) {
     284        // Only force JSON for non-chat actions that request SEO extras.
     285        if ($action !== 'chat' && self::should_force_json($system_prompt)) {
    258286            $body['response_format'] = ['type' => 'json_object'];
    259287        }
    … …  
    292320        ];
    293321
    294         if (strpos($system_prompt, '"titles"') !== false || strpos($system_prompt, '"slugs"') !== false || strpos($system_prompt, '"keywords"') !== false) {
     322        // Only force JSON for non-chat actions that request SEO extras.
     323        if ($action !== 'chat' && self::should_force_json($system_prompt)) {
    295324            $body['response_format'] = ['type' => 'json_object'];
    296325        }
    … …  
    329358        ];
    330359
    331         if (strpos($system_prompt, '"titles"') !== false || strpos($system_prompt, '"slugs"') !== false || strpos($system_prompt, '"keywords"') !== false) {
     360        // Only force JSON for non-chat actions that request SEO extras.
     361        if ($action !== 'chat' && self::should_force_json($system_prompt)) {
    332362            $body['response_format'] = ['type' => 'json_object'];
    333363        }
    … …  
    393423    }
    394424
    395         /**
     425    /**
    396426     * Log API errors when WP_DEBUG_LOG is enabled.
    397427     *
  • rankwell-ai/trunk/rankwell-ai.php

    r3663777 r3665073  
    1616 * Plugin URI: https://wordpress.org/plugins/rankwell-ai/
    1717 * Description:       AI writing assistant built for journalists and newsrooms. Rewrite, fix grammar, improve readability, chat with AI, SEO optimize, and analyze headlines — all with AP Style, attribution rules, and factual guardrails.
    18  * Version:           1.0.0
     18 * Version:           1.0.1
    1919 * Author:            Omajemite Don
    2020 * Author URI:        https://ejesgist.com/developer
    … …  
    3838 * @since 1.0.0
    3939 */
    40 define('RANKWELL_AI_VERSION', '1.1.0');
     40define('RANKWELL_AI_VERSION', '1.0.1');
    4141define('RANKWELL_AI_PATH', plugin_dir_path(__FILE__));
    4242define('RANKWELL_AI_URL', plugin_dir_url(__FILE__));
  • rankwell-ai/trunk/readme.txt

    r3663777 r3665073  
    55Tested up to: 7.1
    66Requires PHP: 8.0
    7 Stable tag: 1.0.0
     7Stable tag: 1.0.1
    88License: GPL-2.0+
    99License URI: http://www.gnu.org/licenses/gpl-2.0.txt
    … …  
    211211
    212212== Changelog ==
     213
     214= 1.0.1 =
     215* Fixed: Chat with AI returns plain text consistently instead of JSON wrappers
     216* Fixed: JSON response format only forced for non-chat actions requesting SEO extras
     217* Improved: Added "message" key support in response parser for broader AI compatibility
    213218
    214219= 1.0.0 =
Note: See TracChangeset for help on using the changeset viewer.