Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🐞 fix: Handle Empty Model Error in Assistants Form (#2265)

Danny Avilad07396d308c9
diff --git a/client/src/common/types.ts b/client/src/common/types.ts
index c83aaedc79..2db1828af2 100644
--- a/client/src/common/types.ts
+++ b/client/src/common/types.ts
@@ -18,6 +18,8 @@ import type { LucideIcon } from 'lucide-react';
export type GenericSetter<T> = (value: T | ((currentValue: T) => T)) => void;
+export type LastSelectedModels = Record<EModelEndpoint, string>;
+
export type NavLink = {
title: string;
label?: string;
diff --git a/client/src/components/SidePanel/Builder/AssistantPanel.tsx b/client/src/components/SidePanel/Builder/AssistantPanel.tsx
index f84f62928a..6399c5d347 100644
--- a/client/src/components/SidePanel/Builder/AssistantPanel.tsx
+++ b/client/src/components/SidePanel/Builder/AssistantPanel.tsx
@@ -317,19 +317,28 @@ export default function AssistantPanel({
<Controller
name="model"
control={control}
- render={({ field }) => (
- <SelectDropDown
- emptyTitle={true}
- value={field.value}
- setValue={field.onChange}
- availableValues={modelsQuery.data?.[EModelEndpoint.assistants] ?? []}
- showAbove={false}
- showLabel={false}
- className={cn(
- cardStyle,
- 'flex h-[40px] w-full flex-none items-center justify-center px-4 hover:cursor-pointer',
+ rules={{ required: true, minLength: 1 }}
+ render={({ field, fieldState: { error } }) => (
+ <>
+ <SelectDropDown
+ emptyTitle={true}
+ value={field.value}
+ setValue={field.onChange}
+ availableValues={modelsQuery.data?.[EModelEndpoint.assistants] ?? []}
+ showAbove={false}
+ showLabel={false}
+ className={cn(
+ cardStyle,
+ 'flex h-[40px] w-full flex-none items-center justify-center px-4 hover:cursor-pointer',
+ )}
+ containerClassName={cn('rounded-md', error ? 'border-red-500 border-2' : '')}
+ />
+ {error && (
+ <span className="text-sm text-red-500 transition duration-300 ease-in-out">
+ {localize('com_ui_field_required')}
+ </span>
)}
- />
+ </>
)}
/>
</div>
diff --git a/client/src/components/SidePanel/Builder/AssistantSelect.tsx b/client/src/components/SidePanel/Builder/AssistantSelect.tsx
index 07b88cb060..3e020985ac 100644
--- a/client/src/components/SidePanel/Builder/AssistantSelect.tsx
+++ b/client/src/components/SidePanel/Builder/AssistantSelect.tsx
@@ -4,17 +4,24 @@ import {
defaultAssistantFormValues,
defaultOrderQuery,
isImageVisionTool,
+ EModelEndpoint,
Capabilities,
FileSources,
} from 'librechat-data-provider';
import type { UseFormReset } from 'react-hook-form';
import type { UseMutationResult } from '@tanstack/react-query';
import type { Assistant, AssistantCreateParams } from 'librechat-data-provider';
-import type { AssistantForm, Actions, TAssistantOption, ExtendedFile } from '~/common';
+import type {
+ AssistantForm,
+ Actions,
+ TAssistantOption,
+ ExtendedFile,
+ LastSelectedModels,
+} from '~/common';
import SelectDropDown from '~/components/ui/SelectDropDown';
import { useListAssistantsQuery } from '~/data-provider';
+import { useLocalize, useLocalStorage } from '~/hooks';
import { useFileMapContext } from '~/Providers';
-import { useLocalize } from '~/hooks';
import { cn } from '~/utils';
const keys = new Set(['name', 'id', 'description', 'instructions', 'model']);
@@ -35,6 +42,10 @@ export default function AssistantSelect({
const localize = useLocalize();
const fileMap = useFileMapContext();
const lastSelectedAssistant = useRef<string | null>(null);
+ const [lastSelectedModels] = useLocalStorage<LastSelectedModels>(
+ 'lastSelectedModel',
+ {} as LastSelectedModels,
+ );
const assistants = useListAssistantsQuery(defaultOrderQuery, {
select: (res) =>
@@ -79,7 +90,10 @@ export default function AssistantSelect({
createMutation.reset();
if (!assistant) {
setCurrentAssistantId(undefined);
- return reset(defaultAssistantFormValues);
+ return reset({
+ ...defaultAssistantFormValues,
+ model: lastSelectedModels?.[EModelEndpoint.assistants] ?? '',
+ });
}
const update = {
@@ -127,7 +141,7 @@ export default function AssistantSelect({
reset(formValues);
setCurrentAssistantId(assistant?.id);
},
- [assistants.data, reset, setCurrentAssistantId, createMutation],
+ [assistants.data, reset, setCurrentAssistantId, createMutation, lastSelectedModels],
);
useEffect(() => {
diff --git a/client/src/localization/languages/Eng.tsx b/client/src/localization/languages/Eng.tsx
index 3d086ca837..618e06f0f7 100644
--- a/client/src/localization/languages/Eng.tsx
+++ b/client/src/localization/languages/Eng.tsx
@@ -46,6 +46,7 @@ export default {
com_assistants_update_error: 'There was an error updating your assistant.',
com_assistants_create_success: 'Successfully created',
com_assistants_create_error: 'There was an error creating your assistant.',
+ com_ui_field_required: 'This field is required',
com_ui_download_error: 'Error downloading file. The file may have been deleted.',
com_ui_attach_error_type: 'Unsupported file type for endpoint:',
com_ui_attach_error_size: 'File size limit exceeded for endpoint:',