mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 16:30:15 +01:00
⚓ refactor(loadConfigModels): Fallback to Default Models if Fetch Fails (#2236)
This commit is contained in:
parent
a00756c469
commit
3a1d07136c
2 changed files with 64 additions and 0 deletions
|
|
@ -69,6 +69,8 @@ async function loadConfigModels(req) {
|
|||
apiKey: API_KEY,
|
||||
name,
|
||||
userIdQuery: models.userIdQuery,
|
||||
}).then((result) => {
|
||||
return !result?.length ? models.default ?? [] : result;
|
||||
});
|
||||
uniqueKeyToNameMap[uniqueKey] = uniqueKeyToNameMap[uniqueKey] || [];
|
||||
uniqueKeyToNameMap[uniqueKey].push(name);
|
||||
|
|
|
|||
|
|
@ -262,4 +262,66 @@ describe('loadConfigModels', () => {
|
|||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('falls back to default models if fetching returns an empty array', async () => {
|
||||
getCustomConfig.mockResolvedValue({
|
||||
endpoints: {
|
||||
custom: [
|
||||
{
|
||||
name: 'EmptyFetchModel',
|
||||
apiKey: 'API_KEY',
|
||||
baseURL: 'http://example.com',
|
||||
models: {
|
||||
fetch: true,
|
||||
default: ['defaultModel1', 'defaultModel2'],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
fetchModels.mockResolvedValue([]);
|
||||
|
||||
const result = await loadConfigModels(mockRequest);
|
||||
|
||||
expect(fetchModels).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
name: 'EmptyFetchModel',
|
||||
apiKey: 'API_KEY',
|
||||
}),
|
||||
);
|
||||
|
||||
expect(result.EmptyFetchModel).toEqual(['defaultModel1', 'defaultModel2']);
|
||||
});
|
||||
|
||||
it('falls back to default models if fetching returns a falsy value', async () => {
|
||||
getCustomConfig.mockResolvedValue({
|
||||
endpoints: {
|
||||
custom: [
|
||||
{
|
||||
name: 'FalsyFetchModel',
|
||||
apiKey: 'API_KEY',
|
||||
baseURL: 'http://example.com',
|
||||
models: {
|
||||
fetch: true,
|
||||
default: ['defaultModel1', 'defaultModel2'],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
fetchModels.mockResolvedValue(false);
|
||||
|
||||
const result = await loadConfigModels(mockRequest);
|
||||
|
||||
expect(fetchModels).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
name: 'FalsyFetchModel',
|
||||
apiKey: 'API_KEY',
|
||||
}),
|
||||
);
|
||||
|
||||
expect(result.FalsyFetchModel).toEqual(['defaultModel1', 'defaultModel2']);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue