Fix and shorten isHiddenReasoningModel
| @@ -82,7 +82,6 @@ export { | |||
| 82 | setOpenAIMessageExamples, | 82 | setOpenAIMessageExamples, |
| 83 | setupChatCompletionPromptManager, | 83 | setupChatCompletionPromptManager, |
| 84 | sendOpenAIRequest, | 84 | sendOpenAIRequest, |
| 85 | getChatCompletionModel, | ||
| 86 | TokenHandler, | 85 | TokenHandler, |
| 87 | IdentifierNotFoundError, | 86 | IdentifierNotFoundError, |
| 88 | Message, | 87 | Message, |
| @@ -1497,7 +1496,7 @@ async function sendWindowAIRequest(messages, signal, stream) { | |||
| 1497 | } | 1496 | } |
| 1498 | } | 1497 | } |
| 1499 | 1498 | ||
| 1500 | function getChatCompletionModel() { | 1499 | export function getChatCompletionModel() { |
| 1501 | switch (oai_settings.chat_completion_source) { | 1500 | switch (oai_settings.chat_completion_source) { |
| 1502 | case chat_completion_sources.CLAUDE: | 1501 | case chat_completion_sources.CLAUDE: |
| 1503 | return oai_settings.claude_model; | 1502 | return oai_settings.claude_model; |
| @@ -5,7 +5,7 @@ import { chat, closeMessageEditor, event_types, eventSource, main_api, messageFo | |||
| 5 | import { getRegexedString, regex_placement } from './extensions/regex/engine.js'; | 5 | import { getRegexedString, regex_placement } from './extensions/regex/engine.js'; |
| 6 | import { getCurrentLocale, t } from './i18n.js'; | 6 | import { getCurrentLocale, t } from './i18n.js'; |
| 7 | import { MacrosParser } from './macros.js'; | 7 | import { MacrosParser } from './macros.js'; |
| 8 | import { chat_completion_sources, oai_settings } from './openai.js'; | 8 | import { chat_completion_sources, getChatCompletionModel, oai_settings } from './openai.js'; |
| 9 | import { Popup } from './popup.js'; | 9 | import { Popup } from './popup.js'; |
| 10 | import { power_user } from './power-user.js'; | 10 | import { power_user } from './power-user.js'; |
| 11 | import { SlashCommand } from './slash-commands/SlashCommand.js'; | 11 | import { SlashCommand } from './slash-commands/SlashCommand.js'; |
| @@ -80,13 +80,13 @@ export function isHiddenReasoningModel() { | |||
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | /** @typedef {{ (currentModel: string, supportedModel: string): boolean }} MatchingFunc */ | 82 | /** @typedef {{ (currentModel: string, supportedModel: string): boolean }} MatchingFunc */ |
| 83 | |||
| 84 | /** @type {Record.<string, MatchingFunc>} */ | 83 | /** @type {Record.<string, MatchingFunc>} */ |
| 85 | const FUNCS = { | 84 | const FUNCS = { |
| 85 | equals: (currentModel, supportedModel) => currentModel === supportedModel, | ||
| 86 | startsWith: (currentModel, supportedModel) => currentModel.startsWith(supportedModel), | 86 | startsWith: (currentModel, supportedModel) => currentModel.startsWith(supportedModel), |
| 87 | }; | 87 | }; |
| 88 | 88 | ||
| 89 | /** @type {({ name: string; func?: MatchingFunc; }|string)[]} */ | 89 | /** @type {{ name: string; func: MatchingFunc; }[]} */ |
| 90 | const hiddenReasoningModels = [ | 90 | const hiddenReasoningModels = [ |
| 91 | { name: 'o1', func: FUNCS.startsWith }, | 91 | { name: 'o1', func: FUNCS.startsWith }, |
| 92 | { name: 'o3', func: FUNCS.startsWith }, | 92 | { name: 'o3', func: FUNCS.startsWith }, |
| @@ -94,28 +94,10 @@ export function isHiddenReasoningModel() { | |||
| 94 | { name: 'gemini-2.0-pro-exp', func: FUNCS.startsWith }, | 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 | /** |