Merge pull request #241 from continuedev/chat-models

Include models with undefined roles in chat model filtering
This commit is contained in:
Nate Sesti 2025-08-19 15:45:21 -07:00 • committed by GitHub
commit e257621644
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 38 additions and 4 deletions

View file

@ -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);

View file

@ -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()', () => {

View file

@ -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);