mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-21 10:50:14 +01:00
🎪 refactor: Allow Last Model Spec Selection without Prioritizing (#10258)
* refactor: Default Model Spec Retrieval Logic, allowing last selected spec on new chat if last selection was a spec * chore: Replace hardcoded 'new' conversation ID with Constants.NEW_CONVO for consistency * chore: remove redundant condition for model spec preset selection in useNewConvo hook
This commit is contained in:
parent
cbbbde3681
commit
90e610ceda
3 changed files with 22 additions and 12 deletions
|
|
@ -252,18 +252,20 @@ const useNewConvo = (index = 0) => {
|
|||
};
|
||||
|
||||
let preset = _preset;
|
||||
const defaultModelSpec = getDefaultModelSpec(startupConfig);
|
||||
const result = getDefaultModelSpec(startupConfig);
|
||||
const defaultModelSpec = result?.default ?? result?.last;
|
||||
if (
|
||||
!preset &&
|
||||
startupConfig &&
|
||||
(startupConfig.modelSpecs?.prioritize === true ||
|
||||
(startupConfig.interface?.modelSelect ?? true) !== true) &&
|
||||
(startupConfig.interface?.modelSelect ?? true) !== true ||
|
||||
(result?.last != null && Object.keys(_template).length === 0)) &&
|
||||
defaultModelSpec
|
||||
) {
|
||||
preset = getModelSpecPreset(defaultModelSpec);
|
||||
}
|
||||
|
||||
if (conversation.conversationId === 'new' && !modelsData) {
|
||||
if (conversation.conversationId === Constants.NEW_CONVO && !modelsData) {
|
||||
const filesToDelete = Array.from(files.values())
|
||||
.filter(
|
||||
(file) =>
|
||||
|
|
|
|||
|
|
@ -66,7 +66,8 @@ export default function ChatRoute() {
|
|||
}
|
||||
|
||||
if (conversationId === Constants.NEW_CONVO && endpointsQuery.data && modelsQuery.data) {
|
||||
const spec = getDefaultModelSpec(startupConfig);
|
||||
const result = getDefaultModelSpec(startupConfig);
|
||||
const spec = result?.default ?? result?.last;
|
||||
logger.log('conversation', 'ChatRoute, new convo effect', conversation);
|
||||
newConversation({
|
||||
modelsData: modelsQuery.data,
|
||||
|
|
@ -90,7 +91,8 @@ export default function ChatRoute() {
|
|||
assistantListMap[EModelEndpoint.assistants] &&
|
||||
assistantListMap[EModelEndpoint.azureAssistants]
|
||||
) {
|
||||
const spec = getDefaultModelSpec(startupConfig);
|
||||
const result = getDefaultModelSpec(startupConfig);
|
||||
const spec = result?.default ?? result?.last;
|
||||
logger.log('conversation', 'ChatRoute new convo, assistants effect', conversation);
|
||||
newConversation({
|
||||
modelsData: modelsQuery.data,
|
||||
|
|
|
|||
|
|
@ -176,11 +176,17 @@ export function getConvoSwitchLogic(params: ConversationInitParams): InitiatedTe
|
|||
};
|
||||
}
|
||||
|
||||
/** Gets the default spec by order.
|
||||
*
|
||||
* First, the admin defined default, then last selected spec, followed by first spec
|
||||
/**
|
||||
* Gets default model spec from config and user preferences.
|
||||
* Priority: admin default → last selected → first spec (when prioritize=true or modelSelect disabled).
|
||||
* Otherwise: admin default or last conversation spec.
|
||||
*/
|
||||
export function getDefaultModelSpec(startupConfig?: t.TStartupConfig) {
|
||||
export function getDefaultModelSpec(startupConfig?: t.TStartupConfig):
|
||||
| {
|
||||
default?: t.TModelSpec;
|
||||
last?: t.TModelSpec;
|
||||
}
|
||||
| undefined {
|
||||
const { modelSpecs, interface: interfaceConfig } = startupConfig ?? {};
|
||||
const { list, prioritize } = modelSpecs ?? {};
|
||||
if (!list) {
|
||||
|
|
@ -190,9 +196,9 @@ export function getDefaultModelSpec(startupConfig?: t.TStartupConfig) {
|
|||
if (prioritize === true || !interfaceConfig?.modelSelect) {
|
||||
const lastSelectedSpecName = localStorage.getItem(LocalStorageKeys.LAST_SPEC);
|
||||
const lastSelectedSpec = list?.find((spec) => spec.name === lastSelectedSpecName);
|
||||
return defaultSpec || lastSelectedSpec || list?.[0];
|
||||
return { default: defaultSpec || lastSelectedSpec || list?.[0] };
|
||||
} else if (defaultSpec) {
|
||||
return defaultSpec;
|
||||
return { default: defaultSpec };
|
||||
}
|
||||
const lastConversationSetup = JSON.parse(
|
||||
localStorage.getItem(LocalStorageKeys.LAST_CONVO_SETUP + '_0') ?? '{}',
|
||||
|
|
@ -200,7 +206,7 @@ export function getDefaultModelSpec(startupConfig?: t.TStartupConfig) {
|
|||
if (!lastConversationSetup.spec) {
|
||||
return;
|
||||
}
|
||||
return list?.find((spec) => spec.name === lastConversationSetup.spec);
|
||||
return { last: list?.find((spec) => spec.name === lastConversationSetup.spec) };
|
||||
}
|
||||
|
||||
export function getModelSpecPreset(modelSpec?: t.TModelSpec) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue