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 {
113 loadProxyPresets,113 loadProxyPresets,
114 selected_proxy,114 selected_proxy,
115 initOpenAI,115 initOpenAI,
116 isHiddenReasoningModel,
117} from './scripts/openai.js';116} from './scripts/openai.js';
118117
119import {118import {
@@ -270,7 +269,7 @@ import { initSettingsSearch } from './scripts/setting-search.js';
270import { initBulkEdit } from './scripts/bulk-edit.js';269import { initBulkEdit } from './scripts/bulk-edit.js';
271import { deriveTemplatesFromChatTemplate } from './scripts/chat-templates.js';270import { deriveTemplatesFromChatTemplate } from './scripts/chat-templates.js';
272import { getContext } from './scripts/st-context.js';271import { getContext } from './scripts/st-context.js';
273import { extractReasoningFromData, initReasoning, PromptReasoning, updateReasoningTimeUI, updateReasoningUI } from './scripts/reasoning.js';272import { extractReasoningFromData, initReasoning, isHiddenReasoningModel, PromptReasoning, updateReasoningUI } from './scripts/reasoning.js';
274273
275// API OBJECT FOR EXTERNAL WIRING274// API OBJECT FOR EXTERNAL WIRING
276globalThis.SillyTavern = {275globalThis.SillyTavern = {
public/scripts/openai.js+0 -48
@@ -4995,54 +4995,6 @@ export function isImageInliningSupported() {
4995 }4995 }
4996}4996}
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 */
5004export 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
5046/**4998/**
5047 * Proxy stuff4999 * Proxy stuff
5048 */5000 */
public/scripts/reasoning.js+47 -1
@@ -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, isHiddenReasoningModel, oai_settings } from './openai.js';8import { chat_completion_sources, 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';
@@ -71,6 +71,52 @@ export function extractReasoningFromData(data) {
71}71}
7272
73/**73/**
74 * Check if the model supports reasoning, but does not send back the reasoning
75 * @returns {boolean} True if the model supports reasoning
76 */
77export 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/**
74 * Updates the Reasoning UI.120 * Updates the Reasoning UI.
75 * @param {number|JQuery<HTMLElement>|HTMLElement} messageIdOrElement The message ID or the message element.121 * @param {number|JQuery<HTMLElement>|HTMLElement} messageIdOrElement The message ID or the message element.
76 * @param {string|null} [reasoning=null] The reasoning content.122 * @param {string|null} [reasoning=null] The reasoning content.