Move isHiddenReasoningModel

c886de5deba89ab4381142cf2c181e6d4935db2b

Cohee <18619528+Cohee1207@users.noreply.github.com>

3 files changed, +48 -51Ignore whitespace
public/script.js+1 -2
@@ -113,7 +113,6 @@ import {
113113 loadProxyPresets,
114114 selected_proxy,
115115 initOpenAI,
116- isHiddenReasoningModel,
117116} from './scripts/openai.js';
118117
119118import {
@@ -270,7 +269,7 @@ import { initSettingsSearch } from './scripts/setting-search.js';
270269import { initBulkEdit } from './scripts/bulk-edit.js';
271270import { deriveTemplatesFromChatTemplate } from './scripts/chat-templates.js';
272271import { getContext } from './scripts/st-context.js';
273272import { extractReasoningFromData, initReasoning, PromptReasoningisHiddenReasoningModel, updateReasoningTimeUIPromptReasoning, updateReasoningUI } from './scripts/reasoning.js';
274273
275274// API OBJECT FOR EXTERNAL WIRING
276275globalThis.SillyTavern = {
public/scripts/openai.js+0 -48
@@ -4995,54 +4995,6 @@ export function isImageInliningSupported() {
49954995 }
49964996}
49974997
4998-
4999-
5000-/**
5001- * Check if the model supports reasoning, but does not send back the reasoning
5002- * @returns {boolean} True if the model supports reasoning
5003- */
5004-export function isHiddenReasoningModel() {
5005- if (main_api !== 'openai') {
5006- return false;
5007- }
5008-
5009- /** @typedef {Object.<chat_completion_sources, { currentModel: string; models: ({ name: string; startsWith: boolean?; matchingFunc: (model: string) => boolean?; }|string)[]; }>} */
5010- const hiddenReasoningModels = {
5011- [chat_completion_sources.OPENAI]: {
5012- currentModel: oai_settings.openai_model,
5013- models: [
5014- { name: 'o1', startsWith: true },
5015- { name: 'o3', startsWith: true },
5016- ],
5017- },
5018- [chat_completion_sources.MAKERSUITE]: {
5019- currentModel: oai_settings.google_model,
5020- models: [
5021- { name: 'gemini-2.0-flash-thinking-exp', startsWith: true },
5022- { name: 'gemini-2.0-pro-exp', startsWith: true },
5023- ],
5024- },
5025- };
5026-
5027- const sourceConfig = hiddenReasoningModels[oai_settings.chat_completion_source];
5028- if (!sourceConfig) {
5029- return false;
5030- }
5031-
5032- return sourceConfig.models.some(model => {
5033- if (typeof model === 'string') {
5034- return sourceConfig.currentModel === model;
5035- }
5036- if (model.startsWith) {
5037- return (sourceConfig.currentModel).startsWith(model.name);
5038- }
5039- if (model.matchingFunc) {
5040- return model.matchingFunc(sourceConfig.currentModel);
5041- }
5042- return false;
5043- });
5044-}
5045-
50464998/**
50474999 * Proxy stuff
50485000 */
public/scripts/reasoning.js+47 -1
@@ -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, isHiddenReasoningModel, oai_settings } from './openai.js';
99import { Popup } from './popup.js';
1010import { power_user } from './power-user.js';
1111import { SlashCommand } from './slash-commands/SlashCommand.js';
@@ -71,6 +71,52 @@ export function extractReasoningFromData(data) {
7171}
7272
7373/**
74+ * Check if the model supports reasoning, but does not send back the reasoning
75+ * @returns {boolean} True if the model supports reasoning
76+ */
77+export function isHiddenReasoningModel() {
78+ if (main_api !== 'openai') {
79+ return false;
80+ }
81+
82+ /** @typedef {Object.<chat_completion_sources, { currentModel: string; models: ({ name: string; startsWith: boolean?; matchingFunc: (model: string) => boolean?; }|string)[]; }>} */
83+ const hiddenReasoningModels = {
84+ [chat_completion_sources.OPENAI]: {
85+ currentModel: oai_settings.openai_model,
86+ models: [
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+ };
99+
100+ const sourceConfig = hiddenReasoningModels[oai_settings.chat_completion_source];
101+ if (!sourceConfig) {
102+ return false;
103+ }
104+
105+ return sourceConfig.models.some(model => {
106+ if (typeof model === 'string') {
107+ return sourceConfig.currentModel === model;
108+ }
109+ if (model.startsWith) {
110+ return (sourceConfig.currentModel).startsWith(model.name);
111+ }
112+ if (model.matchingFunc) {
113+ return model.matchingFunc(sourceConfig.currentModel);
114+ }
115+ return false;
116+ });
117+}
118+
119+/**
74120 * Updates the Reasoning UI.
75121 * @param {number|JQuery<HTMLElement>|HTMLElement} messageIdOrElement The message ID or the message element.
76122 * @param {string|null} [reasoning=null] The reasoning content.