Skip to content

Commit f9a3014

Browse files
authored
Merge pull request #421 from openai/release-please--branches--master--changes--next--components--openai
2 parents 37b0a58 + 00d85f8 commit f9a3014

File tree

5 files changed

+51
-4
lines changed

5 files changed

+51
-4
lines changed

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "4.15.0"
2+
".": "4.15.1"
33
}

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 4.15.1 (2023-11-04)
4+
5+
Full Changelog: [v4.15.0...v4.15.1](https://github.com/openai/openai-node/compare/v4.15.0...v4.15.1)
6+
7+
### Documentation
8+
9+
* document customizing fetch ([#420](https://github.com/openai/openai-node/issues/420)) ([1ca982f](https://github.com/openai/openai-node/commit/1ca982f192daf49e33b7acb5505ed26c9d891255))
10+
311
## 4.15.0 (2023-11-03)
412

513
Full Changelog: [v4.14.2...v4.15.0](https://github.com/openai/openai-node/compare/v4.14.2...v4.15.0)

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ You can import in Deno via:
2121
<!-- x-release-please-start-version -->
2222

2323
```ts
24-
import OpenAI from 'https://raw.githubusercontent.com/openai/openai-node/v4.14.2-deno/mod.ts';
24+
import OpenAI from 'https://raw.githubusercontent.com/openai/openai-node/v4.15.0-deno/mod.ts';
2525
```
2626

2727
<!-- x-release-please-end -->
@@ -395,6 +395,45 @@ console.log(raw.headers.get('X-My-Header'));
395395
console.log(chatCompletion.choices);
396396
```
397397

398+
## Customizing the fetch client
399+
400+
By default, this library uses `node-fetch` in Node, and expects a global `fetch` function in other environments.
401+
402+
If you would prefer to use a global, web-standards-compliant `fetch` function even in a Node environment,
403+
(for example, if you are running Node with `--experimental-fetch` or using NextJS which polyfills with `undici`),
404+
add the following import before your first import `from "OpenAI"`:
405+
406+
<!-- prettier-ignore -->
407+
```ts
408+
// Tell TypeScript and the package to use the global web fetch instead of node-fetch.
409+
// Note, despite the name, this does not add any polyfills, but expects them to be provided if needed.
410+
import "openai/shims/web";
411+
import OpenAI from "openai";
412+
```
413+
414+
To do the inverse, add `import "openai/shims/node"` (which does import polyfills).
415+
This can also be useful if you are getting the wrong TypeScript types for `Response` - more details [here](https://github.com/openai/openai-node/src/_shims#readme).
416+
417+
You may also provide a custom `fetch` function when instantiating the client,
418+
which can be used to inspect or alter the `Request` or `Response` before/after each request:
419+
420+
```ts
421+
import { fetch } from 'undici'; // as one example
422+
import OpenAI from 'openai';
423+
424+
const client = new OpenAI({
425+
fetch: (url: RequestInfo, init?: RequestInfo): Response => {
426+
console.log('About to make request', url, init);
427+
const response = await fetch(url, init);
428+
console.log('Got response', response);
429+
return response;
430+
},
431+
});
432+
```
433+
434+
Note that if given a `DEBUG=true` environment variable, this library will log all requests and responses automatically.
435+
This is intended for debugging purposes only and may change in the future without notice.
436+
398437
## Configuring an HTTP(S) Agent (e.g., for proxies)
399438

400439
By default, this library uses a stable agent for all http/https requests to reuse TCP connections, eliminating many TCP & TLS handshakes and shaving around 100ms off most requests.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openai",
3-
"version": "4.15.0",
3+
"version": "4.15.1",
44
"description": "Client library for the OpenAI API",
55
"author": "OpenAI <[email protected]>",
66
"types": "dist/index.d.ts",

src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const VERSION = '4.15.0'; // x-release-please-version
1+
export const VERSION = '4.15.1'; // x-release-please-version

0 commit comments

Comments
 (0)