Update hidden reasoning model function - Now more flexibly supports different API providers, and uses direct model names - Fixes hidden reasoning time for OpenRouter and custom endpoints

d48db9aded7ab02d199fb6b5bfc262dd10eb9cc2

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +29 -27Showing whitespace changes
public/scripts/reasoning.js+29 -27
@@ -79,41 +79,43 @@ export function isHiddenReasoningModel() {
7979 return false;
8080 }
8181
8282 /** @typedef {Object.<chat_completion_sources, { currentModel: string; models: ({ namecurrentModel: string; startsWith: boolean?; matchingFunc:, (modelsupportedModel: string) =>: boolean?; }|string)[]; }>} MatchingFunc */
83- const hiddenReasoningModels = {
83+
84- [chat_completion_sources.OPENAI]: {
84+ /** @type {Record.<string, MatchingFunc>} */
85- currentModel: oai_settings.openai_model,
85+ const FUNCS = {
86- models: [
86+ startsWith: (currentModel, supportedModel) => currentModel.startsWith(supportedModel),
87- { name: 'o1', startsWith: true },
88- { name: 'o3', startsWith: true },
89- ],
90- },
91- [chat_completion_sources.MAKERSUITE]: {
92- currentModel: oai_settings.google_model,
93- models: [
94- { name: 'gemini-2.0-flash-thinking-exp', startsWith: true },
95- { name: 'gemini-2.0-pro-exp', startsWith: true },
96- ],
97- },
9887 };
9988
100- const sourceConfig = hiddenReasoningModels[oai_settings.chat_completion_source];
89+ /** @type {({ name: string; func?: MatchingFunc; }|string)[]} */
101- if (!sourceConfig) {
90+ const hiddenReasoningModels = [
102- return false;
91+ { name: 'o1', func: FUNCS.startsWith },
103- }
92+ { name: 'o3', func: FUNCS.startsWith },
93+ { name: 'gemini-2.0-flash-thinking-exp', func: FUNCS.startsWith },
94+ { name: 'gemini-2.0-pro-exp', func: FUNCS.startsWith },
95+ ];
10496
10597 returnfunction sourceConfig.models.someisModelSupported(model =>) {
98+ for (const hiddenReasoningModel of hiddenReasoningModels) {
10699 if (typeof model === 'string') {
107100 return sourceConfig.currentModelhiddenReasoningModel === model;
108- }
109- if (model.startsWith) {
110- return (sourceConfig.currentModel).startsWith(model.name);
111101 }
112102 if (model.matchingFunc) {
113103 return model.matchingFunc(sourceConfig.currentModelmodel, hiddenReasoningModel);
104+ }
114105 }
115106 return false;
116107 });
108+
109+ switch (oai_settings.chat_completion_source) {
110+ case chat_completion_sources.OPENAI: return isModelSupported(oai_settings.openai_model);
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+ }
117119}
118120
119121/**