mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-01 08:08:49 +01:00
refactor: Simplify preset creation in useNewConvo and ChatRoute by utilizing getModelSpecPreset
This commit is contained in:
parent
00cff20b08
commit
0e68f67cac
3 changed files with 16 additions and 25 deletions
|
|
@ -22,8 +22,8 @@ import {
|
|||
getEndpointField,
|
||||
buildDefaultConvo,
|
||||
getDefaultEndpoint,
|
||||
getModelSpecPreset,
|
||||
getDefaultModelSpec,
|
||||
getModelSpecIconURL,
|
||||
updateLastSelectedModel,
|
||||
createChatSearchParams,
|
||||
} from '~/utils';
|
||||
|
|
@ -238,11 +238,7 @@ const useNewConvo = (index = 0) => {
|
|||
(startupConfig.interface?.modelSelect ?? true) !== true) &&
|
||||
defaultModelSpec
|
||||
) {
|
||||
preset = {
|
||||
...defaultModelSpec.preset,
|
||||
iconURL: getModelSpecIconURL(defaultModelSpec),
|
||||
spec: defaultModelSpec.name,
|
||||
} as TConversation;
|
||||
preset = getModelSpecPreset(defaultModelSpec);
|
||||
}
|
||||
|
||||
if (conversation.conversationId === 'new' && !modelsData) {
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import {
|
|||
useGetStartupConfig,
|
||||
useGetEndpointsQuery,
|
||||
} from '~/data-provider';
|
||||
import { getDefaultModelSpec, getModelSpecPreset, logger } from '~/utils';
|
||||
import { useNewConvo, useAppStartup, useAssistantListMap } from '~/hooks';
|
||||
import { getDefaultModelSpec, getModelSpecIconURL, logger } from '~/utils';
|
||||
import { ToolCallsMapProvider } from '~/Providers';
|
||||
import ChatView from '~/components/Chat/ChatView';
|
||||
import useAuthRedirect from './useAuthRedirect';
|
||||
|
|
@ -65,15 +65,7 @@ export default function ChatRoute() {
|
|||
newConversation({
|
||||
modelsData: modelsQuery.data,
|
||||
template: conversation ? conversation : undefined,
|
||||
...(spec
|
||||
? {
|
||||
preset: {
|
||||
...spec.preset,
|
||||
iconURL: getModelSpecIconURL(spec),
|
||||
spec: spec.name,
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
...(spec ? { preset: getModelSpecPreset(spec) } : {}),
|
||||
});
|
||||
|
||||
hasSetConversation.current = true;
|
||||
|
|
@ -97,15 +89,7 @@ export default function ChatRoute() {
|
|||
newConversation({
|
||||
modelsData: modelsQuery.data,
|
||||
template: conversation ? conversation : undefined,
|
||||
...(spec
|
||||
? {
|
||||
preset: {
|
||||
...spec.preset,
|
||||
iconURL: getModelSpecIconURL(spec),
|
||||
spec: spec.name,
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
...(spec ? { preset: getModelSpecPreset(spec) } : {}),
|
||||
});
|
||||
hasSetConversation.current = true;
|
||||
} else if (
|
||||
|
|
|
|||
|
|
@ -203,6 +203,17 @@ export function getDefaultModelSpec(startupConfig?: t.TStartupConfig) {
|
|||
return list?.find((spec) => spec.name === lastConversationSetup.spec);
|
||||
}
|
||||
|
||||
export function getModelSpecPreset(modelSpec?: t.TModelSpec) {
|
||||
if (!modelSpec) {
|
||||
return;
|
||||
}
|
||||
return {
|
||||
...modelSpec.preset,
|
||||
spec: modelSpec.name,
|
||||
iconURL: getModelSpecIconURL(modelSpec),
|
||||
};
|
||||
}
|
||||
|
||||
/** Gets the default spec iconURL by order or definition.
|
||||
*
|
||||
* First, the admin defined default, then last selected spec, followed by first spec
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue