| @@ -305,9 +305,12 @@ | ||
| 305 | 305 | public function handle_health($request) { |
| 306 | 306 | $token_set = (string) get_option(self::TOKEN_OPTION, '') !== ''; |
| 307 | 307 | |
| 308 | 308 | $options = get_option('mxchat_options', array()); |
| 309 | - $embedding_model = isset($options['embedding_model']) ? (string) $options['embedding_model'] : ''; | |
| 309 | + // The effective model: custom:<model> when Custom Provider embeddings are on (plan 418afd). | |
| 310 | + $embedding_model = class_exists('MxChat_Utils') | |
| 311 | + ? (string) MxChat_Utils::get_selected_embedding_model(is_array($options) ? $options : array()) | |
| 312 | + : (isset($options['embedding_model']) ? (string) $options['embedding_model'] : ''); | |
| 310 | 313 | |
| 311 | 314 | return rest_ensure_response(array( |
| 312 | 315 | 'ok' => true, |
| 313 | 316 | 'plugin_version' => defined('MXCHAT_VERSION') ? MXCHAT_VERSION : null, |
| @@ -601,25 +604,16 @@ | ||
| 601 | 604 | // Pull the embedding API key from MxChat options (same logic as the |
| 602 | 605 | // admin form handler in MxChat_Knowledge_Manager::mxchat_handle_content_submission). |
| 603 | 606 | $bot_options = $this->get_bot_options($bot_id); |
| 604 | 607 | $options = !empty($bot_options) ? $bot_options : get_option('mxchat_options', array()); |
| 605 | - $selected_model = isset($options['embedding_model']) ? (string) $options['embedding_model'] : 'text-embedding-ada-002'; | |
| 606 | - | |
| 607 | - if (strpos($selected_model, 'voyage') === 0) { | |
| 608 | - $api_key = isset($options['voyage_api_key']) ? (string) $options['voyage_api_key'] : ''; | |
| 609 | - } elseif (strpos($selected_model, 'gemini-embedding') === 0) { | |
| 610 | - $api_key = isset($options['gemini_api_key']) ? (string) $options['gemini_api_key'] : ''; | |
| 611 | - } else { | |
| 612 | - $api_key = isset($options['api_key']) ? (string) $options['api_key'] : ''; | |
| 608 | + // The same decision every admin importer makes (plan 418afd): a site | |
| 609 | + // that embeds through a Custom Provider needs no OpenAI, Voyage or | |
| 610 | + // Gemini key, and the key check used to refuse it. | |
| 611 | + $preflight = MxChat_Utils::embedding_preflight(is_array($options) ? $options : array()); | |
| 612 | + if (!$preflight['ok']) { | |
| 613 | + return new WP_Error('mxchat_rest_no_api_key', $preflight['reason'], array('status' => 500)); | |
| 613 | 614 | } |
| 614 | - | |
| 615 | - if ($api_key === '') { | |
| 616 | - return new WP_Error( | |
| 617 | - 'mxchat_rest_no_api_key', | |
| 618 | - __('No embedding API key configured for the selected embedding model. Configure it in MxChat settings before pushing knowledge.', 'mxchat'), | |
| 619 | - array('status' => 500) | |
| 620 | - ); | |
| 621 | - } | |
| 615 | + $api_key = $preflight['api_key']; | |
| 622 | 616 | |
| 623 | 617 | // Embedding + chunking can take 10-60s for large documents. |
| 624 | 618 | if (function_exists('set_time_limit')) { |
| 625 | 619 | @set_time_limit(300); |