Skip to content

Commit 05ff44f

Browse files
committedAug 12, 2023
v4.0.0-beta.10
1 parent 28276d6 commit 05ff44f

File tree

4 files changed

+3
-36
lines changed

4 files changed

+3
-36
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ async function main() {
5656
stream: true,
5757
});
5858
for await (const part of stream) {
59-
process.stdout.write(part.choices[0]?.text || '');
59+
process.stdout.write(part.choices[0]?.delta?.content || '');
6060
}
6161
}
6262

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openai",
3-
"version": "4.0.0-beta.9",
3+
"version": "4.0.0-beta.10",
44
"description": "Client library for the OpenAI API",
55
"author": "OpenAI <support@openai.com>",
66
"types": "dist/index.d.ts",

‎src/streaming.ts

-33
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Response } from 'openai/_shims/fetch';
2-
import { ReadableStream } from 'openai/_shims/ReadableStream';
32

43
type Bytes = string | ArrayBuffer | Uint8Array | Buffer | null | undefined;
54

@@ -68,38 +67,6 @@ export class Stream<Item> implements AsyncIterable<Item> {
6867
if (!done) this.controller.abort();
6968
}
7069
}
71-
72-
toReadableStream(): ReadableStream {
73-
const self = this;
74-
let iter: AsyncIterator<Item>;
75-
const encoder = new TextEncoder();
76-
77-
return new ReadableStream({
78-
async start() {
79-
iter = self[Symbol.asyncIterator]();
80-
},
81-
async pull(ctrl) {
82-
try {
83-
const { value, done } = await iter.next();
84-
if (done) return ctrl.close();
85-
86-
const str =
87-
typeof value === 'string' ? value : (
88-
// Add a newline after JSON to make it easier to parse newline-separated JSON on the frontend.
89-
JSON.stringify(value) + '\n'
90-
);
91-
const bytes = encoder.encode(str);
92-
93-
ctrl.enqueue(bytes);
94-
} catch (err) {
95-
ctrl.error(err);
96-
}
97-
},
98-
async cancel() {
99-
await iter.return?.();
100-
},
101-
});
102-
}
10370
}
10471

10572
class SSEDecoder {

‎src/version.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const VERSION = '4.0.0-beta.9';
1+
export const VERSION = '4.0.0-beta.10';

0 commit comments

Comments
 (0)
Please sign in to comment.