openai-api-mock 0.1.28 → 0.1.29

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openai-api-mock",
3
- "version": "0.1.28",
3
+ "version": "0.1.29",
4
4
  "description": "A Node.js module for mocking OpenAI API responses in a development environment",
5
5
  "repository": {
6
6
  "type": "git",
package/src/index.js CHANGED
@@ -30,12 +30,10 @@ export function mockOpenAIResponse(force = false, options = {}) {
30
30
  return { isActive: false, stopMocking };
31
31
  }
32
32
 
33
- // Add delay if latency is specified
34
- const mockWithDelay = latency > 0 ? nock(OPEN_AI_BASE_URL).delay(latency) : nock(OPEN_AI_BASE_URL);
35
-
36
33
  // Mock chat completions endpoint
37
- const chatScope = mockWithDelay
34
+ const chatScope = nock(OPEN_AI_BASE_URL)
38
35
  .post(CHAT_COMPLETIONS_ENDPOINT)
36
+ .delay(latency) // Add delay to the interceptor
39
37
  .reply(function (uri, requestBody) {
40
38
  if (logRequests) {
41
39
  console.log(`[openai-api-mock] Chat request:`, JSON.stringify(requestBody, null, 2));
@@ -67,8 +65,9 @@ export function mockOpenAIResponse(force = false, options = {}) {
67
65
  });
68
66
 
69
67
  // Mock image generations endpoint
70
- const imageScope = mockWithDelay
68
+ const imageScope = nock(OPEN_AI_BASE_URL)
71
69
  .post(IMAGE_GENERATIONS_ENDPOINT)
70
+ .delay(latency) // Add delay to the interceptor
72
71
  .reply(function (uri, requestBody) {
73
72
  if (logRequests) {
74
73
  console.log(`[openai-api-mock] Image request:`, JSON.stringify(requestBody, null, 2));