Fix and shorten isHiddenReasoningModel

703e876f4a827bd6751f52c4f20ced7d36e14cf1

Wolfsblvt <wolfsblvt@gmail.com>

2 files changed, +7 -26Showing whitespace changes
public/scripts/openai.js+1 -2
@@ -82,7 +82,6 @@ export {
8282 setOpenAIMessageExamples,
8383 setupChatCompletionPromptManager,
8484 sendOpenAIRequest,
85- getChatCompletionModel,
8685 TokenHandler,
8786 IdentifierNotFoundError,
8887 Message,
@@ -1497,7 +1496,7 @@ async function sendWindowAIRequest(messages, signal, stream) {
14971496 }
14981497}
14991498
15001499export function getChatCompletionModel() {
15011500 switch (oai_settings.chat_completion_source) {
15021501 case chat_completion_sources.CLAUDE:
15031502 return oai_settings.claude_model;
public/scripts/reasoning.js+6 -24
@@ -5,7 +5,7 @@ import { chat, closeMessageEditor, event_types, eventSource, main_api, messageFo
55import { getRegexedString, regex_placement } from './extensions/regex/engine.js';
66import { getCurrentLocale, t } from './i18n.js';
77import { MacrosParser } from './macros.js';
88import { chat_completion_sources, getChatCompletionModel, oai_settings } from './openai.js';
99import { Popup } from './popup.js';
1010import { power_user } from './power-user.js';
1111import { SlashCommand } from './slash-commands/SlashCommand.js';
@@ -80,13 +80,13 @@ export function isHiddenReasoningModel() {
8080 }
8181
8282 /** @typedef {{ (currentModel: string, supportedModel: string): boolean }} MatchingFunc */
83-
8483 /** @type {Record.<string, MatchingFunc>} */
8584 const FUNCS = {
85+ equals: (currentModel, supportedModel) => currentModel === supportedModel,
8686 startsWith: (currentModel, supportedModel) => currentModel.startsWith(supportedModel),
8787 };
8888
8989 /** @type {({ name: string; func?: MatchingFunc; }|string)[]} */
9090 const hiddenReasoningModels = [
9191 { name: 'o1', func: FUNCS.startsWith },
9292 { name: 'o3', func: FUNCS.startsWith },
@@ -94,28 +94,10 @@ export function isHiddenReasoningModel() {
9494 { name: 'gemini-2.0-pro-exp', func: FUNCS.startsWith },
9595 ];
9696
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- }
10898
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- }
119101}
120102
121103/**