openai-api-mock 0.1.27 → 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/__tests__/mock_delay.test.js +28 -0
- package/dist/index.cjs +2 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.js +3 -5
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -30,13 +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 delayResponse = latency > 0 ?
|
|
35
|
-
nock.defaults({ delayConnection: latency }) : null;
|
|
36
|
-
|
|
37
33
|
// Mock chat completions endpoint
|
|
38
34
|
const chatScope = nock(OPEN_AI_BASE_URL)
|
|
39
35
|
.post(CHAT_COMPLETIONS_ENDPOINT)
|
|
36
|
+
.delay(latency) // Add delay to the interceptor
|
|
40
37
|
.reply(function (uri, requestBody) {
|
|
41
38
|
if (logRequests) {
|
|
42
39
|
console.log(`[openai-api-mock] Chat request:`, JSON.stringify(requestBody, null, 2));
|
|
@@ -70,6 +67,7 @@ export function mockOpenAIResponse(force = false, options = {}) {
|
|
|
70
67
|
// Mock image generations endpoint
|
|
71
68
|
const imageScope = nock(OPEN_AI_BASE_URL)
|
|
72
69
|
.post(IMAGE_GENERATIONS_ENDPOINT)
|
|
70
|
+
.delay(latency) // Add delay to the interceptor
|
|
73
71
|
.reply(function (uri, requestBody) {
|
|
74
72
|
if (logRequests) {
|
|
75
73
|
console.log(`[openai-api-mock] Image request:`, JSON.stringify(requestBody, null, 2));
|
|
@@ -122,4 +120,4 @@ export function mockOpenAIResponse(force = false, options = {}) {
|
|
|
122
120
|
export function stopMocking() {
|
|
123
121
|
nock.cleanAll();
|
|
124
122
|
customScopes.forEach(scope => scope.persist(false)); // Disable persistence
|
|
125
|
-
}
|
|
123
|
+
}
|