Skip to content

Mocking, no longer working in v5 #1565

@MrSwitch

Description

@MrSwitch

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requestedsdk

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions