Merge pull request #241 from continuedev/chat-models
Include models with undefined roles in chat model filtering
This commit is contained in:
commit
e257621644
3 changed files with 38 additions and 4 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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()', () => {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue