Changeset 3665073
- Timestamp:
- 08/25/2026 10:16:57 AM (2 months ago)
- Location:
- rankwell-ai/trunk
- Files:
-
- 3 edited
-
includes/ai/Transport.php (modified) (12 diffs)
-
rankwell-ai.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
rankwell-ai/trunk/includes/ai/Transport.php
r3663777 r3665073 5 5 * @package RankwellAI 6 6 * @since 1.0.0 7 * @version 1.0.1 7 8 */ 8 9 … … 19 20 class Transport { 20 21 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. 22 23 private const GOOGLE_AI_URL = 'https://generativelanguage.googleapis.com/v1beta/models/'; 23 24 … … 99 100 } 100 101 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 101 115 private static function call_google_ai(string $system_prompt, string $user_message, string $action, string $model = '') { 102 116 if ('' === $model) { … … 119 133 'generationConfig' => [ 120 134 '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 } 124 143 125 144 $response = wp_remote_post($url, [ … … 182 201 $body = [ 183 202 'model' => $model, 184 'response_format' => ['type' => 'json_object'],185 203 'messages' => [ 186 204 ['role' => 'system', 'content' => $system_prompt], … … 190 208 'max_tokens' => 32768, 191 209 ]; 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 } 192 215 193 216 $response = wp_remote_post(self::DEEPSEEK_URL, [ … … 213 236 $body = [ 214 237 'model' => $model, 215 'response_format' => ['type' => 'json_object'],216 238 'messages' => [ 217 239 ['role' => 'system', 'content' => $system_prompt], … … 221 243 'max_tokens' => 32768, 222 244 ]; 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 } 223 250 224 251 $response = wp_remote_post(self::CHATGPT_URL, [ … … 255 282 ]; 256 283 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)) { 258 286 $body['response_format'] = ['type' => 'json_object']; 259 287 } … … 292 320 ]; 293 321 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)) { 295 324 $body['response_format'] = ['type' => 'json_object']; 296 325 } … … 329 358 ]; 330 359 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)) { 332 362 $body['response_format'] = ['type' => 'json_object']; 333 363 } … … 393 423 } 394 424 395 /**425 /** 396 426 * Log API errors when WP_DEBUG_LOG is enabled. 397 427 * -
rankwell-ai/trunk/rankwell-ai.php
r3663777 r3665073 16 16 * Plugin URI: https://wordpress.org/plugins/rankwell-ai/ 17 17 * 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. 018 * Version: 1.0.1 19 19 * Author: Omajemite Don 20 20 * Author URI: https://ejesgist.com/developer … … 38 38 * @since 1.0.0 39 39 */ 40 define('RANKWELL_AI_VERSION', '1. 1.0');40 define('RANKWELL_AI_VERSION', '1.0.1'); 41 41 define('RANKWELL_AI_PATH', plugin_dir_path(__FILE__)); 42 42 define('RANKWELL_AI_URL', plugin_dir_url(__FILE__)); -
rankwell-ai/trunk/readme.txt
r3663777 r3665073 5 5 Tested up to: 7.1 6 6 Requires PHP: 8.0 7 Stable tag: 1.0. 07 Stable tag: 1.0.1 8 8 License: GPL-2.0+ 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.txt … … 211 211 212 212 == 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 213 218 214 219 = 1.0.0 =
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)