-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
Description
Confirm this is a feature request for the Node library and not the underlying OpenAI API.
- This is a feature request for the Node library
Describe the feature or improvement you're requesting
Is there a recommended approach to mocking API calls created by this openai
node package?
Previously with openai@4
, it has been possible to mock the calls to openai, like so...
import nock from 'nock';
const OPEN_AI_BASE_URL = 'https://api.openai.com';
const CHAT_COMPLETIONS_ENDPOINT = '/v1/chat/completions';
export function mockOpenAIResponse(...responses) {
nock.cleanAll();
// Intercept the HTTP call and return the mock response
responses.forEach(response => {
nock(OPEN_AI_BASE_URL)
.post(CHAT_COMPLETIONS_ENDPOINT)
.reply(200, (/* uri, requestBody*/) => {
return getChatResponse(response);
});
});
}
However when installing the latest version openai@latest
, these mock calls no longer work. Whilst the paths to the service are still the same these have somehow alluded nock
.
Thanks
Additional context
No response