openai-api-mock 0.1.27 → 0.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -2199,8 +2199,8 @@ function mockOpenAIResponse(force = false, options = {}) {
2199
2199
  if (env !== "development" && !force) {
2200
2200
  return { isActive: false, stopMocking };
2201
2201
  }
2202
- latency > 0 ? nock.defaults({ delayConnection: latency }) : null;
2203
- nock(OPEN_AI_BASE_URL).post(CHAT_COMPLETIONS_ENDPOINT).reply(function(uri, requestBody) {
2202
+ const mockWithDelay = latency > 0 ? nock(OPEN_AI_BASE_URL).delay(latency) : nock(OPEN_AI_BASE_URL);
2203
+ mockWithDelay.post(CHAT_COMPLETIONS_ENDPOINT).reply(function(uri, requestBody) {
2204
2204
  if (logRequests) {
2205
2205
  console.log(`[openai-api-mock] Chat request:`, JSON.stringify(requestBody, null, 2));
2206
2206
  }
@@ -2222,7 +2222,7 @@ function mockOpenAIResponse(force = false, options = {}) {
2222
2222
  return [500, { error: { message: "Internal server error in mock" } }];
2223
2223
  }
2224
2224
  });
2225
- nock(OPEN_AI_BASE_URL).post(IMAGE_GENERATIONS_ENDPOINT).reply(function(uri, requestBody) {
2225
+ mockWithDelay.post(IMAGE_GENERATIONS_ENDPOINT).reply(function(uri, requestBody) {
2226
2226
  if (logRequests) {
2227
2227
  console.log(`[openai-api-mock] Image request:`, JSON.stringify(requestBody, null, 2));
2228
2228
  }