| @@ -55,11 +55,15 @@ | ||
| 55 | 55 | 'label' => __('Google Gemini', 'mxchat'), |
| 56 | 56 | 'key_option' => 'gemini_api_key', |
| 57 | 57 | 'requires_key_to_load_models' => false, |
| 58 | 58 | 'models' => array( |
| 59 | - 'gemini-3.5-flash' => array('label' => 'Gemini 3.5 Flash', 'description' => __('Stable — newest Flash generation, recommended default', 'mxchat')), | |
| 59 | + 'gemini-3.8-flash' => array('label' => 'Gemini 3.8 Flash', 'description' => __('Stable — newest Flash generation, recommended default', 'mxchat')), | |
| 60 | + 'gemini-3.7-flash' => array('label' => 'Gemini 3.7 Flash', 'description' => __('Stable — efficiency-first Flash', 'mxchat')), | |
| 61 | + 'gemini-3.6-flash' => array('label' => 'Gemini 3.6 Flash', 'description' => __('Stable — previous Flash generation', 'mxchat')), | |
| 62 | + 'gemini-3.5-flash' => array('label' => 'Gemini 3.5 Flash', 'description' => __('Stable — older Flash, priced above 3.8 Flash on every token', 'mxchat')), | |
| 60 | 63 | 'gemini-3.1-pro-preview' => array('label' => 'Gemini 3.1 Pro', 'description' => __('Preview — most intelligent, multimodal & agentic', 'mxchat')), |
| 61 | 64 | 'gemini-3-flash-preview' => array('label' => 'Gemini 3 Flash', 'description' => __('Preview — balanced speed and scale', 'mxchat')), |
| 65 | + 'gemini-3.5-flash-lite' => array('label' => 'Gemini 3.5 Flash-Lite', 'description' => __('Stable — cheapest Gemini, no thinking', 'mxchat')), | |
| 62 | 66 | 'gemini-3.1-flash-lite' => array('label' => 'Gemini 3.1 Flash-Lite', 'description' => __('Stable — cost-efficient, high throughput', 'mxchat')), |
| 63 | 67 | 'gemini-3.1-flash-lite-preview' => array('label' => 'Gemini 3.1 Flash-Lite (Preview)', 'description' => __('Preview — latest cost-efficient model', 'mxchat')), |
| 64 | 68 | 'gemini-2.5-pro' => array('label' => 'Gemini 2.5 Pro', 'description' => __('Stable — advanced thinking, code, math & long context', 'mxchat')), |
| 65 | 69 | 'gemini-2.5-flash' => array('label' => 'Gemini 2.5 Flash', 'description' => __('Stable — strong price-performance with thinking', 'mxchat')), |
| @@ -79,9 +83,18 @@ | ||
| 79 | 83 | // 'deprecated_on' (Y-m-d) + 'replacement' are optional per-model |
| 80 | 84 | // fields: pickers label a future date as "retires <date>" and hide |
| 81 | 85 | // the entry once the date passes (a saved value keeps rendering via |
| 82 | 86 | // settings_dropdown_groups($current_model)). |
| 83 | - 'gpt-5.6-sol' => array('label' => 'GPT-5.6 Sol', 'description' => __('Recommended — newest OpenAI flagship for reasoning, coding and chat', 'mxchat')), | |
| 87 | + // GPT-6 (announced 2026-09-22; plan 45c22d). Probed live on | |
| 88 | + // 2026-09-27: all three need max_completion_tokens, reject any | |
| 89 | + // temperature but 1 and reject reasoning_effort 'minimal'; | |
| 90 | + // Astra also rejects 'none'. Every "modern OpenAI" gate goes | |
| 91 | + // through is_modern_openai() so these ids are not sent legacy | |
| 92 | + // parameters (which 400 on the first message). | |
| 93 | + 'gpt-6-astra' => array('label' => 'GPT-6 Astra', 'description' => __('Recommended — newest OpenAI flagship; strongest reasoning, coding and agentic work', 'mxchat')), | |
| 94 | + 'gpt-6-sol' => array('label' => 'GPT-6 Sol', 'description' => __('Strong reasoning on demanding tasks at mid-tier cost', 'mxchat')), | |
| 95 | + 'gpt-6-luna' => array('label' => 'GPT-6 Luna', 'description' => __('Fastest and cheapest GPT-6 for high-volume, repeatable work', 'mxchat')), | |
| 96 | + 'gpt-5.6-sol' => array('label' => 'GPT-5.6 Sol', 'description' => __('Previous OpenAI flagship for reasoning, coding and chat', 'mxchat')), | |
| 84 | 97 | 'gpt-5.6-terra' => array('label' => 'GPT-5.6 Terra', 'description' => __('Balanced GPT-5.6 — strong capability at lower cost', 'mxchat')), |
| 85 | 98 | 'gpt-5.6-luna' => array('label' => 'GPT-5.6 Luna', 'description' => __('Fastest and cheapest GPT-5.6 for lightweight tasks', 'mxchat')), |
| 86 | 99 | 'gpt-5.5' => array('label' => 'GPT-5.5', 'description' => __('Previous flagship — powerful reasoning and coding model', 'mxchat')), |
| 87 | 100 | 'gpt-5.4' => array('label' => 'GPT-5.4', 'description' => __('Flagship reasoning and coding model', 'mxchat')), |
| @@ -671,9 +684,9 @@ | ||
| 671 | 684 | $map = array( |
| 672 | 685 | 'openai' => 'gpt-5.6-sol', |
| 673 | 686 | 'claude' => 'claude-haiku-4-5-20251001', |
| 674 | 687 | 'xai' => 'grok-4.6', |
| 675 | - 'gemini' => 'gemini-3.5-flash', | |
| 688 | + 'gemini' => 'gemini-3.8-flash', | |
| 676 | 689 | ); |
| 677 | 690 | $model = isset($map[$provider]) ? $map[$provider] : ''; |
| 678 | 691 | return (string) apply_filters('mxchat_default_vision_model', $model, $provider); |
| 679 | 692 | } |
| @@ -718,10 +731,29 @@ | ||
| 718 | 731 | */ |
| 719 | 732 | public static function reasoning_effort_for($model, $context = 'chat') { |
| 720 | 733 | $model = (string) $model; |
| 721 | 734 | |
| 722 | - // Only the gpt-5 family carries reasoning_effort. Everything else omits. | |
| 723 | - if (strpos($model, 'gpt-5') !== 0) { | |
| 735 | + // plan a9774b: every Gemini 3.x output price is "including thinking | |
| 736 | + // tokens" and the model thinks at its default level unless told | |
| 737 | + // otherwise — measured on this site's own support prompt, 71% of | |
| 738 | + // billed output on 3.8 Flash was hidden thinking, with indistinguishable | |
| 739 | + // replies at 'low' (0 hidden tokens). So the chat surface sends 'low': | |
| 740 | + // as reasoning_effort on the OpenAI-compatible endpoint, and as | |
| 741 | + // generationConfig.thinkingConfig.thinkingLevel on the native one (see | |
| 742 | + // gemini_thinking_config()). Flash-Lite does not think and returns 400 | |
| 743 | + // on any reasoning parameter — it must send nothing. | |
| 744 | + if (strpos($model, 'gemini-3') === 0) { | |
| 745 | + if (strpos($model, 'flash-lite') !== false) { | |
| 746 | + return null; | |
| 747 | + } | |
| 748 | + return ($context === 'chat') ? 'low' : null; | |
| 749 | + } | |
| 750 | + | |
| 751 | + // Only the modern OpenAI family (gpt-5*, gpt-6*) carries | |
| 752 | + // reasoning_effort. Everything else omits. plan 45c22d widened this | |
| 753 | + // from a literal gpt-5 prefix: a gpt-6 id used to fall through all | |
| 754 | + // three maps below and be sent legacy parameters. | |
| 755 | + if (!self::is_modern_openai($model)) { | |
| 724 | 756 | return null; |
| 725 | 757 | } |
| 726 | 758 | |
| 727 | 759 | switch ($context) { |
| @@ -728,8 +760,11 @@ | ||
| 728 | 760 | case 'websearch': |
| 729 | 761 | // integrator web-search (Responses API). Explicit allowlist, no |
| 730 | 762 | // "else" — anything not listed omits reasoning entirely. |
| 731 | 763 | $map = array( |
| 764 | + 'gpt-6-astra' => 'low', // plan 45c22d, probed 2026-09-27 on /v1/responses | |
| 765 | + 'gpt-6-sol' => 'low', | |
| 766 | + 'gpt-6-luna' => 'low', | |
| 732 | 767 | 'gpt-5.6-sol' => 'low', |
| 733 | 768 | 'gpt-5.6-terra' => 'low', |
| 734 | 769 | 'gpt-5.6-luna' => 'low', |
| 735 | 770 | 'gpt-5.5' => 'low', |
| @@ -748,8 +783,14 @@ | ||
| 748 | 783 | // 400'd on every call); the original gpt-5/-mini/-nano still |
| 749 | 784 | // REQUIRE 'minimal' and reject 'none'. Do not "harmonize" these |
| 750 | 785 | // — the two generations genuinely differ. |
| 751 | 786 | $map = array( |
| 787 | + // plan 45c22d (probed 2026-09-27): gpt-6-astra accepts only | |
| 788 | + // low|medium|high; gpt-6-sol/-luna accept none|low|medium|high. | |
| 789 | + // 'low' for all three, as for their 5.6 siblings. | |
| 790 | + 'gpt-6-astra' => 'low', | |
| 791 | + 'gpt-6-sol' => 'low', | |
| 792 | + 'gpt-6-luna' => 'low', | |
| 752 | 793 | 'gpt-5.6-sol' => 'low', |
| 753 | 794 | 'gpt-5.6-terra' => 'low', |
| 754 | 795 | 'gpt-5.6-luna' => 'low', |
| 755 | 796 | 'gpt-5.5' => 'low', |
| @@ -783,8 +824,14 @@ | ||
| 783 | 824 | } |
| 784 | 825 | if ($model === 'gpt-5.4') { |
| 785 | 826 | return 'none'; |
| 786 | 827 | } |
| 828 | + // plan 45c22d (probed 2026-09-27): gpt-6-astra accepts only | |
| 829 | + // low|medium|high; -sol/-luna accept none|low|medium|high. | |
| 830 | + // 'low' for all three, as for their 5.6 siblings. | |
| 831 | + if (in_array($model, array('gpt-6-astra', 'gpt-6-sol', 'gpt-6-luna'), true)) { | |
| 832 | + return 'low'; | |
| 833 | + } | |
| 787 | 834 | if (in_array($model, array('gpt-5.6-sol', 'gpt-5.6-terra', 'gpt-5.6-luna'), true)) { |
| 788 | 835 | return 'low'; |
| 789 | 836 | } |
| 790 | 837 | // plan-25b972: the original gpt-5 generation REQUIRES 'minimal' |
| @@ -815,13 +862,35 @@ | ||
| 815 | 862 | * |
| 816 | 863 | * @param string $model Chat model id. |
| 817 | 864 | * @return bool true if a custom temperature may be sent. |
| 818 | 865 | */ |
| 866 | + /** | |
| 867 | + * generationConfig.thinkingConfig for the native Gemini endpoint, or null | |
| 868 | + * to send none (plan a9774b). Derived from reasoning_effort_for() so the | |
| 869 | + * two Gemini paths — native generateContent and the OpenAI-compatible | |
| 870 | + * endpoint — always agree on the thinking level. Overridable via | |
| 871 | + * mxchat_gemini_thinking_level (return '' to send none). | |
| 872 | + * | |
| 873 | + * @param string $model Chat model id. | |
| 874 | + * @return array|null e.g. array('thinkingLevel' => 'low'). | |
| 875 | + */ | |
| 876 | + public static function gemini_thinking_config($model) { | |
| 877 | + $level = self::reasoning_effort_for($model, 'chat'); | |
| 878 | + if (strpos((string) $model, 'gemini-') !== 0) { | |
| 879 | + return null; | |
| 880 | + } | |
| 881 | + $level = apply_filters('mxchat_gemini_thinking_level', $level, $model); | |
| 882 | + if (!is_string($level) || $level === '' || !in_array($level, array('minimal', 'low', 'medium', 'high'), true)) { | |
| 883 | + return null; | |
| 884 | + } | |
| 885 | + return array('thinkingLevel' => $level); | |
| 886 | + } | |
| 887 | + | |
| 819 | 888 | public static function supports_temperature($model) { |
| 820 | 889 | $model = (string) $model; |
| 821 | 890 | |
| 822 | - // gpt-5 family accepts only the default temperature (1). | |
| 823 | - if (strpos($model, 'gpt-5') === 0) { | |
| 891 | + // gpt-5 / gpt-6 families accept only the default temperature (1). | |
| 892 | + if (self::is_modern_openai($model)) { | |
| 824 | 893 | return false; |
| 825 | 894 | } |
| 826 | 895 | |
| 827 | 896 | // Anthropic flagships that reject the temperature param outright. |
| @@ -850,7 +919,28 @@ | ||
| 850 | 919 | * @param string $model Chat model id. |
| 851 | 920 | * @return string 'max_completion_tokens' | 'max_tokens' |
| 852 | 921 | */ |
| 853 | 922 | public static function openai_token_param($model) { |
| 854 | - return strpos((string) $model, 'gpt-5') === 0 ? 'max_completion_tokens' : 'max_tokens'; | |
| 923 | + return self::is_modern_openai($model) ? 'max_completion_tokens' : 'max_tokens'; | |
| 924 | + } | |
| 925 | + | |
| 926 | + /** | |
| 927 | + * plan 45c22d: ONE predicate for "a modern OpenAI chat model" — the | |
| 928 | + * generations that take max_completion_tokens, only the default | |
| 929 | + * temperature, and reasoning_effort. Every gate that used to test the | |
| 930 | + * literal prefix gpt-5 routes through here, so the next generation is a | |
| 931 | + * one-line change instead of nine edits. Before this, gpt-6-* ids fell | |
| 932 | + * through all nine and were sent legacy parameters: a 400 on the first | |
| 933 | + * message while looking fine in the picker. | |
| 934 | + * | |
| 935 | + * The frozen partial-upgrade fallbacks in the integrator, the content | |
| 936 | + * generator and the editor assistant carry the same two-prefix test | |
| 937 | + * inline (they exist for the window where this class is not loaded). | |
| 938 | + * | |
| 939 | + * @param string $model Chat model id. | |
| 940 | + * @return bool | |
| 941 | + */ | |
| 942 | + public static function is_modern_openai($model) { | |
| 943 | + $model = (string) $model; | |
| 944 | + return strpos($model, 'gpt-5') === 0 || strpos($model, 'gpt-6') === 0; | |
| 855 | 945 | } |
| 856 | 946 | } |