Skip to content

Commit

Permalink
Add test for no models error
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswilty committed Jul 5, 2024
1 parent adf24b3 commit 140510b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend/src/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async function getValidModelsFromOpenAI() {
console.debug('Valid OpenAI models:', validModels);
return validModels;
} catch (error) {
console.error('Error getting valid models: ', error);
console.error('Error getting valid models:', error);
throw error;
}
}
Expand Down
18 changes: 18 additions & 0 deletions backend/test/unit/openai.ts/getValidModelsFromOpenai.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,22 @@ describe('getValidModelsFromOpenAI', () => {

expect(validModels).toEqual(expectedValidModels);
});

test('GIVEN the user has no valid chat models available WHEN getValidModelsFromOpenAI is called THEN an error is thrown', async () => {
process.env.OPENAI_API_KEY = 'sk-12345';
const mockModelList = [
{ id: 'gpt-3' },
{ id: 'davinci-001' },
{ id: 'davinci-002' },
{ id: 'text-moderation-stable' },
{ id: 'whisper-1' },
];
mockListFn.mockResolvedValueOnce({
data: mockModelList,
} as OpenAI.ModelsPage);

await expect(getValidModelsFromOpenAI()).rejects.toThrow(
'No chat models found'
);
});
});

0 comments on commit 140510b

Please sign in to comment.