From 7064ce81c7a2922818bbd8cb70c24c8b5aa17d40 Mon Sep 17 00:00:00 2001 From: bmen25124 Date: Tue, 25 Feb 2025 15:45:35 +0300 Subject: [PATCH] Exported getChatCompletionModel with optional parameter --- public/scripts/openai.js | 12 +++++++++--- public/scripts/st-context.js | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/public/scripts/openai.js b/public/scripts/openai.js index a814159d1..eb2c43ea9 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -1497,8 +1497,14 @@ async function sendWindowAIRequest(messages, signal, stream) { } } -export function getChatCompletionModel() { - switch (oai_settings.chat_completion_source) { +/** + * Gets the API model for the selected chat completion source. + * @param {string} source If it's set, ignores active source + * @returns {string} API model + */ +export function getChatCompletionModel(source = null) { + const activeSource = source ?? oai_settings.chat_completion_source; + switch (activeSource) { case chat_completion_sources.CLAUDE: return oai_settings.claude_model; case chat_completion_sources.OPENAI: @@ -1532,7 +1538,7 @@ export function getChatCompletionModel() { case chat_completion_sources.DEEPSEEK: return oai_settings.deepseek_model; default: - throw new Error(`Unknown chat completion source: ${oai_settings.chat_completion_source}`); + throw new Error(`Unknown chat completion source: ${activeSource}`); } } diff --git a/public/scripts/st-context.js b/public/scripts/st-context.js index 729418552..2393a4800 100644 --- a/public/scripts/st-context.js +++ b/public/scripts/st-context.js @@ -57,7 +57,7 @@ import { groups, openGroupChat, selected_group } from './group-chats.js'; import { t, translate } from './i18n.js'; import { hideLoader, showLoader } from './loader.js'; import { MacrosParser } from './macros.js'; -import { oai_settings } from './openai.js'; +import { getChatCompletionModel, oai_settings } from './openai.js'; import { callGenericPopup, Popup, POPUP_RESULT, POPUP_TYPE } from './popup.js'; import { power_user, registerDebugFunction } from './power-user.js'; import { getPresetManager } from './preset-manager.js'; @@ -200,6 +200,7 @@ export function getContext() { getTextGenServer, extractMessageFromData, getPresetManager, + getChatCompletionModel, }; }