diff --git a/client/src/hooks/useNewConvo.ts b/client/src/hooks/useNewConvo.ts index 8e1e4f8e5f..24c291213e 100644 --- a/client/src/hooks/useNewConvo.ts +++ b/client/src/hooks/useNewConvo.ts @@ -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) { diff --git a/client/src/routes/ChatRoute.tsx b/client/src/routes/ChatRoute.tsx index 4ce9cdef9e..48382fc548 100644 --- a/client/src/routes/ChatRoute.tsx +++ b/client/src/routes/ChatRoute.tsx @@ -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 ( diff --git a/client/src/utils/endpoints.ts b/client/src/utils/endpoints.ts index f86f81682e..497c76aca6 100644 --- a/client/src/utils/endpoints.ts +++ b/client/src/utils/endpoints.ts @@ -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