Fix and shorten isHiddenReasoningModel
| @@ -82,7 +82,6 @@ export { | ||
| 82 | 82 | setOpenAIMessageExamples, |
| 83 | 83 | setupChatCompletionPromptManager, |
| 84 | 84 | sendOpenAIRequest, |
| 85 | - getChatCompletionModel, | |
| 86 | 85 | TokenHandler, |
| 87 | 86 | IdentifierNotFoundError, |
| 88 | 87 | Message, |
| @@ -1497,7 +1496,7 @@ async function sendWindowAIRequest(messages, signal, stream) { | ||
| 1497 | 1496 | } |
| 1498 | 1497 | } |
| 1499 | 1498 | |
| 1500 | 1499 | export function getChatCompletionModel() { |
| 1501 | 1500 | switch (oai_settings.chat_completion_source) { |
| 1502 | 1501 | case chat_completion_sources.CLAUDE: |
| 1503 | 1502 | return oai_settings.claude_model; |
| @@ -5,7 +5,7 @@ import { chat, closeMessageEditor, event_types, eventSource, main_api, messageFo | ||
| 5 | 5 | import { getRegexedString, regex_placement } from './extensions/regex/engine.js'; |
| 6 | 6 | import { getCurrentLocale, t } from './i18n.js'; |
| 7 | 7 | import { MacrosParser } from './macros.js'; |
| 8 | 8 | import { chat_completion_sources, getChatCompletionModel, oai_settings } from './openai.js'; |
| 9 | 9 | import { Popup } from './popup.js'; |
| 10 | 10 | import { power_user } from './power-user.js'; |
| 11 | 11 | import { SlashCommand } from './slash-commands/SlashCommand.js'; |
| @@ -80,13 +80,13 @@ export function isHiddenReasoningModel() { | ||
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** @typedef {{ (currentModel: string, supportedModel: string): boolean }} MatchingFunc */ |
| 83 | - | |
| 84 | 83 | /** @type {Record.<string, MatchingFunc>} */ |
| 85 | 84 | const FUNCS = { |
| 85 | + equals: (currentModel, supportedModel) => currentModel === supportedModel, | |
| 86 | 86 | startsWith: (currentModel, supportedModel) => currentModel.startsWith(supportedModel), |
| 87 | 87 | }; |
| 88 | 88 | |
| 89 | 89 | /** @type {({ name: string; func?: MatchingFunc; }|string)[]} */ |
| 90 | 90 | const hiddenReasoningModels = [ |
| 91 | 91 | { name: 'o1', func: FUNCS.startsWith }, |
| 92 | 92 | { name: 'o3', func: FUNCS.startsWith }, |
| @@ -94,28 +94,10 @@ export function isHiddenReasoningModel() { | ||
| 94 | 94 | { name: 'gemini-2.0-pro-exp', func: FUNCS.startsWith }, |
| 95 | 95 | ]; |
| 96 | 96 | |
| 97 | - function isModelSupported(model) { | |
| 97 | + const model = getChatCompletionModel(); | |
| 98 | - for (const hiddenReasoningModel of hiddenReasoningModels) { | |
| 99 | - if (typeof hiddenReasoningModel === 'string') { | |
| 100 | - return hiddenReasoningModel === model; | |
| 101 | - } | |
| 102 | - if (hiddenReasoningModel.func) { | |
| 103 | - return hiddenReasoningModel.func(model, hiddenReasoningModel.name); | |
| 104 | - } | |
| 105 | - } | |
| 106 | - return false; | |
| 107 | - } | |
| 108 | 98 | |
| 109 | - switch (oai_settings.chat_completion_source) { | |
| 99 | + const isHidden = hiddenReasoningModels.some(({ name, func }) => func(model, name)); | |
| 110 | - case chat_completion_sources.OPENAI: return isModelSupported(oai_settings.openai_model); | |
| 100 | + return isHidden; | |
| 111 | - case chat_completion_sources.MAKERSUITE: return isModelSupported(oai_settings.google_model); | |
| 112 | - case chat_completion_sources.CLAUDE: return isModelSupported(oai_settings.claude_model); | |
| 113 | - case chat_completion_sources.OPENROUTER: return isModelSupported(oai_settings.openrouter_model); | |
| 114 | - case chat_completion_sources.ZEROONEAI: return isModelSupported(oai_settings.zerooneai_model); | |
| 115 | - case chat_completion_sources.MISTRALAI: return isModelSupported(oai_settings.mistralai_model); | |
| 116 | - case chat_completion_sources.CUSTOM: return isModelSupported(oai_settings.custom_model); | |
| 117 | - default: return false; | |
| 118 | - } | |
| 119 | 101 | } |
| 120 | 102 | |
| 121 | 103 | /** |