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 +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.js +4 -5
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -31,11 +31,10 @@ export function mockOpenAIResponse(force = false, options = {}) {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
// Add delay if latency is specified
|
|
34
|
-
const
|
|
35
|
-
nock.defaults({ delayConnection: latency }) : null;
|
|
34
|
+
const mockWithDelay = latency > 0 ? nock(OPEN_AI_BASE_URL).delay(latency) : nock(OPEN_AI_BASE_URL);
|
|
36
35
|
|
|
37
36
|
// Mock chat completions endpoint
|
|
38
|
-
const chatScope =
|
|
37
|
+
const chatScope = mockWithDelay
|
|
39
38
|
.post(CHAT_COMPLETIONS_ENDPOINT)
|
|
40
39
|
.reply(function (uri, requestBody) {
|
|
41
40
|
if (logRequests) {
|
|
@@ -68,7 +67,7 @@ export function mockOpenAIResponse(force = false, options = {}) {
|
|
|
68
67
|
});
|
|
69
68
|
|
|
70
69
|
// Mock image generations endpoint
|
|
71
|
-
const imageScope =
|
|
70
|
+
const imageScope = mockWithDelay
|
|
72
71
|
.post(IMAGE_GENERATIONS_ENDPOINT)
|
|
73
72
|
.reply(function (uri, requestBody) {
|
|
74
73
|
if (logRequests) {
|
|
@@ -122,4 +121,4 @@ export function mockOpenAIResponse(force = false, options = {}) {
|
|
|
122
121
|
export function stopMocking() {
|
|
123
122
|
nock.cleanAll();
|
|
124
123
|
customScopes.forEach(scope => scope.persist(false)); // Disable persistence
|
|
125
|
-
}
|
|
124
|
+
}
|