diff --git a/client/src/components/Chat/Menus/Endpoints/ModelSelectorContext.tsx b/client/src/components/Chat/Menus/Endpoints/ModelSelectorContext.tsx index 26d476e85d84..26462fc1b5b4 100644 --- a/client/src/components/Chat/Menus/Endpoints/ModelSelectorContext.tsx +++ b/client/src/components/Chat/Menus/Endpoints/ModelSelectorContext.tsx @@ -27,6 +27,7 @@ type ModelSelectorContextType = { agentsMap: t.TAgentsMap | undefined; assistantsMap: t.TAssistantsMap | undefined; endpointsConfig: t.TEndpointsConfig; + hideBaseModels: boolean; // Functions endpointRequiresUserKey: (endpoint: string) => boolean; @@ -209,6 +210,8 @@ export function ModelSelectorProvider({ children, startupConfig }: ModelSelector }); }; + const hideBaseModels = startupConfig?.modelSpecs?.hideBaseModels ?? false; + const value = { // State searchValue, @@ -221,6 +224,7 @@ export function ModelSelectorProvider({ children, startupConfig }: ModelSelector assistantsMap, mappedEndpoints, endpointsConfig, + hideBaseModels, // Functions handleSelectSpec, diff --git a/client/src/components/Chat/Menus/Endpoints/components/EndpointItem.tsx b/client/src/components/Chat/Menus/Endpoints/components/EndpointItem.tsx index 8b7c4f84860f..5c3cc6240fb7 100644 --- a/client/src/components/Chat/Menus/Endpoints/components/EndpointItem.tsx +++ b/client/src/components/Chat/Menus/Endpoints/components/EndpointItem.tsx @@ -86,6 +86,7 @@ export function EndpointItem({ endpoint, endpointIndex }: EndpointItemProps) { assistantsMap, modelSpecs, selectedValues, + hideBaseModels, handleOpenKeyDialog, handleSelectEndpoint, endpointSearchValues, @@ -173,23 +174,24 @@ export function EndpointItem({ endpoint, endpointIndex }: EndpointItemProps) { {endpointSpecs.map((spec: TModelSpec) => ( ))} - {/* Render endpoint models */} - {filteredModels - ? renderEndpointModels( - endpoint, - endpoint.models || [], - selectedModel, - filteredModels, - endpointIndex, - ) - : endpoint.models && - renderEndpointModels( - endpoint, - endpoint.models, - selectedModel, - undefined, - endpointIndex, - )} + {/* Render endpoint models (hidden when hideBaseModels is enabled and there are specs for this endpoint) */} + {!(hideBaseModels && endpointSpecs.length > 0) && + (filteredModels + ? renderEndpointModels( + endpoint, + endpoint.models || [], + selectedModel, + filteredModels, + endpointIndex, + ) + : endpoint.models && + renderEndpointModels( + endpoint, + endpoint.models, + selectedModel, + undefined, + endpointIndex, + ))} )} diff --git a/librechat.example.yaml b/librechat.example.yaml index a7ab9ee05432..5454edd74eb9 100644 --- a/librechat.example.yaml +++ b/librechat.example.yaml @@ -453,6 +453,9 @@ endpoints: # - Only needs to be set on one spec per group (first one is used) # - Can be a URL or a built-in endpoint key (e.g., "openAI", "anthropic", "groq") # modelSpecs: +# enforce: false # If true, only model specs can be used, not base models +# prioritize: true # If true, model specs are shown before base models +# hideBaseModels: false # If true, hides base models when specs exist for an endpoint # list: # # Example 1: Nested under an endpoint (grouped with openAI endpoint) # - name: "gpt-4o" diff --git a/packages/data-provider/specs/models.spec.ts b/packages/data-provider/specs/models.spec.ts new file mode 100644 index 000000000000..c4473de5ac8c --- /dev/null +++ b/packages/data-provider/specs/models.spec.ts @@ -0,0 +1,62 @@ +import { specsConfigSchema } from '../src/models'; +import { EModelEndpoint } from '../src/schemas'; + +describe('specsConfigSchema', () => { + const validModelSpec = { + name: 'test-model', + label: 'Test Model', + preset: { + endpoint: EModelEndpoint.openAI, + }, + }; + + describe('hideBaseModels option', () => { + it('should default hideBaseModels to false when not provided', () => { + const config = { + list: [validModelSpec], + }; + + const result = specsConfigSchema.safeParse(config); + expect(result.success).toBe(true); + if (result.success) { + expect(result.data.hideBaseModels).toBe(false); + } + }); + + it('should accept hideBaseModels: true', () => { + const config = { + hideBaseModels: true, + list: [validModelSpec], + }; + + const result = specsConfigSchema.safeParse(config); + expect(result.success).toBe(true); + if (result.success) { + expect(result.data.hideBaseModels).toBe(true); + } + }); + + it('should accept hideBaseModels: false', () => { + const config = { + hideBaseModels: false, + list: [validModelSpec], + }; + + const result = specsConfigSchema.safeParse(config); + expect(result.success).toBe(true); + if (result.success) { + expect(result.data.hideBaseModels).toBe(false); + } + }); + + it('should reject hideBaseModels with non-boolean value', () => { + const config = { + hideBaseModels: 'yes', + list: [validModelSpec], + }; + + const result = specsConfigSchema.safeParse(config); + expect(result.success).toBe(false); + }); + }); +}); diff --git a/packages/data-provider/src/models.ts b/packages/data-provider/src/models.ts index 3c3c19766015..8b916fd2c87f 100644 --- a/packages/data-provider/src/models.ts +++ b/packages/data-provider/src/models.ts @@ -60,6 +60,7 @@ export const tModelSpecSchema = z.object({ export const specsConfigSchema = z.object({ enforce: z.boolean().default(false), prioritize: z.boolean().default(true), + hideBaseModels: z.boolean().default(false), list: z.array(tModelSpecSchema).min(1), addedEndpoints: z.array(z.union([z.string(), eModelEndpointSchema])).optional(), });