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 {
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}
14991498
1500function getChatCompletionModel() {1499export 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;
public/scripts/reasoning.js+6 -24
@@ -5,7 +5,7 @@ import { chat, closeMessageEditor, event_types, eventSource, main_api, messageFo
5import { getRegexedString, regex_placement } from './extensions/regex/engine.js';5import { getRegexedString, regex_placement } from './extensions/regex/engine.js';
6import { getCurrentLocale, t } from './i18n.js';6import { getCurrentLocale, t } from './i18n.js';
7import { MacrosParser } from './macros.js';7import { MacrosParser } from './macros.js';
8import { chat_completion_sources, oai_settings } from './openai.js';8import { chat_completion_sources, getChatCompletionModel, oai_settings } from './openai.js';
9import { Popup } from './popup.js';9import { Popup } from './popup.js';
10import { power_user } from './power-user.js';10import { power_user } from './power-user.js';
11import { SlashCommand } from './slash-commands/SlashCommand.js';11import { SlashCommand } from './slash-commands/SlashCommand.js';
@@ -80,13 +80,13 @@ export function isHiddenReasoningModel() {
80 }80 }
8181
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 };
8888
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 ];
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 }
119}101}
120102
121/**103/**