generated from windingwind/zotero-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 64
/
openai+4.68.1.patch
119 lines (119 loc) · 5.37 KB
/
openai+4.68.1.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
diff --git a/node_modules/openai/_shims/node-runtime.mjs b/node_modules/openai/_shims/node-runtime.mjs
index 3605162..7ff9cd5 100644
--- a/node_modules/openai/_shims/node-runtime.mjs
+++ b/node_modules/openai/_shims/node-runtime.mjs
@@ -1,12 +1,13 @@
import * as nf from 'node-fetch';
import * as fd from 'formdata-node';
-import KeepAliveAgent from 'agentkeepalive';
-import { AbortController as AbortControllerPolyfill } from 'abort-controller';
-import { ReadStream as FsReadStream } from 'node:fs';
+// import KeepAliveAgent from 'agentkeepalive';
+// import { AbortController as AbortControllerPolyfill } from 'abort-controller';
+// import { ReadStream as FsReadStream } from 'node:fs';
import { FormDataEncoder } from 'form-data-encoder';
-import { Readable } from 'node:stream';
+// import { Readable } from 'node:stream';
import { MultipartBody } from "./MultipartBody.mjs";
-import { ReadableStream } from 'node:stream/web';
+// import { ReadableStream } from 'node:stream/web';
+import { ReadableStream } from 'web-streams-polyfill/ponyfill/es6';
let fileFromPathWarned = false;
async function fileFromPath(path, ...args) {
// this import fails in environments that don't handle export maps correctly, like old versions of Jest
@@ -18,12 +19,28 @@ async function fileFromPath(path, ...args) {
// @ts-ignore
return await _fileFromPath(path, ...args);
}
-const defaultHttpAgent = new KeepAliveAgent({ keepAlive: true, timeout: 5 * 60 * 1000 });
-const defaultHttpsAgent = new KeepAliveAgent.HttpsAgent({ keepAlive: true, timeout: 5 * 60 * 1000 });
+// const defaultHttpAgent = new KeepAliveAgent({ keepAlive: true, timeout: 5 * 60 * 1000 });
+// const defaultHttpsAgent = new KeepAliveAgent.HttpsAgent({ keepAlive: true, timeout: 5 * 60 * 1000 });
+const defaultHttpAgent = {}
+const defaultHttpsAgent = {}
+function toReadableStream(encoder) {
+ const iterator = encoder.encode()
+
+ return new ReadableStream({
+ async pull(controller) {
+ const { value, done } = await iterator.next()
+ if (done) {
+ return controller.close()
+ }
+ controller.enqueue(value)
+ }
+ })
+}
async function getMultipartRequestOptions(form, opts) {
const encoder = new FormDataEncoder(form);
- const readable = Readable.from(encoder);
- const body = new MultipartBody(readable);
+ // const readable = Readable.from(encoder);
+ // const body = new MultipartBody(readable);
+ const body = toReadableStream(encoder)
const headers = {
...opts.headers,
...encoder.headers,
@@ -33,10 +50,10 @@ async function getMultipartRequestOptions(form, opts) {
}
export function getRuntime() {
// Polyfill global object if needed.
- if (typeof AbortController === 'undefined') {
- // @ts-expect-error (the types are subtly different, but compatible in practice)
- globalThis.AbortController = AbortControllerPolyfill;
- }
+ // if (typeof AbortController === 'undefined') {
+ // // @ts-expect-error (the types are subtly different, but compatible in practice)
+ // globalThis.AbortController = AbortControllerPolyfill;
+ // }
return {
kind: 'node',
fetch: nf.default,
@@ -50,7 +67,8 @@ export function getRuntime() {
getMultipartRequestOptions,
getDefaultAgent: (url) => (url.startsWith('https') ? defaultHttpsAgent : defaultHttpAgent),
fileFromPath,
- isFsReadStream: (value) => value instanceof FsReadStream,
+ // isFsReadStream: (value) => value instanceof FsReadStream,
+ isFsReadStream: (value) => false,
};
}
//# sourceMappingURL=node-runtime.mjs.map
\ No newline at end of file
diff --git a/node_modules/openai/core.mjs b/node_modules/openai/core.mjs
index 8bc7a0e..69889dc 100644
--- a/node_modules/openai/core.mjs
+++ b/node_modules/openai/core.mjs
@@ -216,7 +216,8 @@ export class APIClient {
if ('timeout' in options)
validatePositiveInteger('timeout', options.timeout);
const timeout = options.timeout ?? this.timeout;
- const httpAgent = options.httpAgent ?? this.httpAgent ?? getDefaultAgent(url);
+ // const httpAgent = options.httpAgent ?? this.httpAgent ?? getDefaultAgent(url);
+ const httpAgent = options.httpAgent ?? this.httpAgent ?? undefined;
const minAgentTimeout = timeout + 1000;
if (typeof httpAgent?.options?.timeout === 'number' &&
minAgentTimeout > (httpAgent.options.timeout ?? 0)) {
@@ -236,10 +237,10 @@ export class APIClient {
method,
...(body && { body: body }),
headers: reqHeaders,
- ...(httpAgent && { agent: httpAgent }),
+ // ...(httpAgent && { agent: httpAgent }),
// @ts-ignore node-fetch uses a custom AbortSignal type that is
// not compatible with standard web types
- signal: options.signal ?? null,
+ // signal: options.signal ?? null,
};
return { req, url, timeout };
}
@@ -301,7 +302,8 @@ export class APIClient {
if (options.signal?.aborted) {
throw new APIUserAbortError();
}
- const controller = new AbortController();
+ // const controller = new AbortController();
+ const controller = {}
const response = await this.fetchWithTimeout(url, req, timeout, controller).catch(castToError);
if (response instanceof Error) {
if (options.signal?.aborted) {