diff --git a/src/services/ModelService.refactored.ts b/src/services/ModelService.refactored.ts index 694d32d34..debcde1c8 100644 --- a/src/services/ModelService.refactored.ts +++ b/src/services/ModelService.refactored.ts @@ -49,7 +49,8 @@ export class ModelService this.assistant = assistant; this.authConfig = authConfig; this.availableModels = (assistant.models?.filter( - (model) => model && model.roles?.includes("chat"), + (model) => + model && (model.roles?.includes("chat") || model.roles === undefined), ) || []) as ModelConfig[]; // Check if we have a persisted model name and use it if valid @@ -91,7 +92,8 @@ export class ModelService this.assistant = assistant; this.authConfig = authConfig; this.availableModels = (assistant.models?.filter( - (model) => model && model.roles?.includes("chat"), + (model) => + model && (model.roles?.includes("chat") || model.roles === undefined), ) || []) as ModelConfig[]; const [llmApi, model] = getLlmApi(assistant, authConfig); diff --git a/src/services/ModelService.test.ts b/src/services/ModelService.test.ts index 6a2bd43c1..8437fc6c7 100644 --- a/src/services/ModelService.test.ts +++ b/src/services/ModelService.test.ts @@ -205,6 +205,36 @@ describe('ModelService', () => { index: 1, }); }); + + test('should include models with undefined roles', async () => { + // Add a model with undefined roles to the assistant + const assistantWithUndefinedRoles = { + ...mockAssistant, + models: [ + ...mockAssistant.models!, + { + provider: 'local', + model: 'llama-2', + name: 'Llama 2', + apiKey: 'test-key', + // roles is undefined + } as ModelConfig, + ], + }; + + vi.mocked(config.getLlmApi).mockReturnValue([mockLlmApi as any, assistantWithUndefinedRoles.models![0] as ModelConfig]); + await service.initialize(assistantWithUndefinedRoles, mockAuthConfig); + + const models = service.getAvailableChatModels(); + + // Should include the two chat models and the model with undefined roles + expect(models).toHaveLength(3); + expect(models[2]).toEqual({ + provider: 'local', + name: 'Llama 2', + index: 2, + }); + }); }); describe('getCurrentModelIndex()', () => { diff --git a/src/services/ModelService.ts b/src/services/ModelService.ts index 0ba08d6d4..5bbd1b70b 100644 --- a/src/services/ModelService.ts +++ b/src/services/ModelService.ts @@ -49,7 +49,8 @@ export class ModelService this.assistant = assistant; this.authConfig = authConfig; this.availableModels = (assistant.models?.filter( - (model) => model && model.roles?.includes("chat"), + (model) => + model && (model.roles?.includes("chat") || model.roles === undefined), ) || []) as ModelConfig[]; // Check if we have a persisted model name and use it if valid @@ -91,7 +92,8 @@ export class ModelService this.assistant = assistant; this.authConfig = authConfig; this.availableModels = (assistant.models?.filter( - (model) => model && model.roles?.includes("chat"), + (model) => + model && (model.roles?.includes("chat") || model.roles === undefined), ) || []) as ModelConfig[]; const [llmApi, model] = getLlmApi(assistant, authConfig);