You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -440,7 +446,7 @@ export abstract class APIClient {
440
446
if(value===null){
441
447
return`${encodeURIComponent(key)}=`;
442
448
}
443
-
thrownewError(
449
+
thrownewOpenAIError(
444
450
`Cannot stringify type ${typeofvalue}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`,
Copy file name to clipboardExpand all lines: src/index.ts
+4-2
Original file line number
Diff line number
Diff line change
@@ -103,7 +103,7 @@ export class OpenAI extends Core.APIClient {
103
103
...opts
104
104
}: ClientOptions={}){
105
105
if(apiKey===undefined){
106
-
thrownewError(
106
+
thrownewErrors.OpenAIError(
107
107
"The OPENAI_API_KEY environment variable is missing or empty; either provide it, or instantiate the OpenAI client with an apiKey option, like new OpenAI({ apiKey: 'my apiKey' }).",
108
108
);
109
109
}
@@ -116,7 +116,7 @@ export class OpenAI extends Core.APIClient {
"It looks like you're running in a browser-like environment.\n\nThis is disabled by default, as it risks exposing your secret API credentials to attackers.\nIf you understand the risks and have appropriate mitigations in place,\nyou can set the `dangerouslyAllowBrowser` option to `true`, e.g.,\n\nnew OpenAI({ apiKey, dangerouslyAllowBrowser: true });\n\nhttps://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety\n",
121
121
);
122
122
}
@@ -164,6 +164,7 @@ export class OpenAI extends Core.APIClient {
thrownewError(`Attempted to iterate over a response with no body`);
27
+
thrownewOpenAIError(`Attempted to iterate over a response with no body`);
27
28
}
28
29
constlineDecoder=newLineDecoder();
29
30
@@ -198,7 +199,7 @@ class LineDecoder {
198
199
returnBuffer.from(bytes).toString();
199
200
}
200
201
201
-
thrownewError(
202
+
thrownewOpenAIError(
202
203
`Unexpected: received non-Uint8Array (${bytes.constructor.name}) stream chunk in an environment with a global "Buffer" defined, which this library assumes to be Node. Please report this error.`,
203
204
);
204
205
}
@@ -210,14 +211,14 @@ class LineDecoder {
210
211
returnthis.textDecoder.decode(bytes);
211
212
}
212
213
213
-
thrownewError(
214
+
thrownewOpenAIError(
214
215
`Unexpected: received non-Uint8Array/ArrayBuffer (${
215
216
(bytesasany).constructor.name
216
217
}) in a web platform. Please report this error.`,
217
218
);
218
219
}
219
220
220
-
thrownewError(
221
+
thrownewOpenAIError(
221
222
`Unexpected: neither Buffer nor TextDecoder are available as globals. Please report this error.`,
0 commit comments