| @@ -305,12 +305,9 @@ | ||
| 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 | - // 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'] : ''); | |
| 309 | + $embedding_model = isset($options['embedding_model']) ? (string) $options['embedding_model'] : ''; | |
| 313 | 310 | |
| 314 | 311 | return rest_ensure_response(array( |
| 315 | 312 | 'ok' => true, |
| 316 | 313 | 'plugin_version' => defined('MXCHAT_VERSION') ? MXCHAT_VERSION : null, |
| @@ -604,16 +601,25 @@ | ||
| 604 | 601 | // Pull the embedding API key from MxChat options (same logic as the |
| 605 | 602 | // admin form handler in MxChat_Knowledge_Manager::mxchat_handle_content_submission). |
| 606 | 603 | $bot_options = $this->get_bot_options($bot_id); |
| 607 | 604 | $options = !empty($bot_options) ? $bot_options : get_option('mxchat_options', array()); |
| 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)); | |
| 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'] : ''; | |
| 614 | 613 | } |
| 615 | - $api_key = $preflight['api_key']; | |
| 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 | + } | |
| 616 | 622 | |
| 617 | 623 | // Embedding + chunking can take 10-60s for large documents. |
| 618 | 624 | if (function_exists('set_time_limit')) { |
| 619 | 625 | @set_time_limit(300); |