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, +32 -30Ignore whitespace
public/scripts/reasoning.js+32 -30
@@ -79,41 +79,43 @@ export function isHiddenReasoningModel() {
79 return false;79 return false;
80 }80 }
8181
82 /** @typedef {Object.<chat_completion_sources, { currentModel: string; models: ({ name: string; startsWith: boolean?; matchingFunc: (model: string) => boolean?; }|string)[]; }>} */82 /** @typedef {{ (currentModel: string, supportedModel: string): boolean }} 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 },
98 };87 };
9988
100 const sourceConfig = hiddenReasoningModels[oai_settings.chat_completion_source];89 /** @type {({ name: string; func?: MatchingFunc; }|string)[]} */
101 if (!sourceConfig) {90 const hiddenReasoningModels = [
91 { name: 'o1', func: FUNCS.startsWith },
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 ];
96
97 function isModelSupported(model) {
98 for (const hiddenReasoningModel of hiddenReasoningModels) {
99 if (typeof model === 'string') {
100 return hiddenReasoningModel === model;
101 }
102 if (model.matchingFunc) {
103 return model.matchingFunc(model, hiddenReasoningModel);
104 }
105 }
102 return false;106 return false;
103 }107 }
104108
105 return sourceConfig.models.some(model => {109 switch (oai_settings.chat_completion_source) {
106 if (typeof model === 'string') {110 case chat_completion_sources.OPENAI: return isModelSupported(oai_settings.openai_model);
107 return sourceConfig.currentModel === model;111 case chat_completion_sources.MAKERSUITE: return isModelSupported(oai_settings.google_model);
108 }112 case chat_completion_sources.CLAUDE: return isModelSupported(oai_settings.claude_model);
109 if (model.startsWith) {113 case chat_completion_sources.OPENROUTER: return isModelSupported(oai_settings.openrouter_model);
110 return (sourceConfig.currentModel).startsWith(model.name);114 case chat_completion_sources.ZEROONEAI: return isModelSupported(oai_settings.zerooneai_model);
111 }115 case chat_completion_sources.MISTRALAI: return isModelSupported(oai_settings.mistralai_model);
112 if (model.matchingFunc) {116 case chat_completion_sources.CUSTOM: return isModelSupported(oai_settings.custom_model);
113 return model.matchingFunc(sourceConfig.currentModel);117 default: return false;
114 }118 }
115 return false;
116 });
117}119}
118120
119/**121/**