@xsai/stream-text 0.0.29 → 0.0.30
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.js +4 -4
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { chat } from '@xsai/shared-chat';
|
|
2
2
|
|
|
3
3
|
const chunkHeaderPrefix = "data:";
|
|
4
|
-
const streamText = async (options) =>
|
|
4
|
+
const streamText = async (options) => chat({
|
|
5
5
|
...options,
|
|
6
6
|
stream: true
|
|
7
7
|
}).then(async (res) => {
|
|
@@ -25,10 +25,10 @@ const streamText = async (options) => await chat({
|
|
|
25
25
|
controller.enqueue(chunk);
|
|
26
26
|
if (options.onChunk)
|
|
27
27
|
await options.onChunk(chunk);
|
|
28
|
-
if (chunk.choices[0].finish_reason) {
|
|
28
|
+
if (chunk.choices[0].finish_reason !== undefined) {
|
|
29
29
|
finishReason = chunk.choices[0].finish_reason;
|
|
30
30
|
}
|
|
31
|
-
if (chunk.usage) {
|
|
31
|
+
if (chunk.usage !== undefined) {
|
|
32
32
|
usage = chunk.usage;
|
|
33
33
|
}
|
|
34
34
|
};
|
|
@@ -38,7 +38,7 @@ const streamText = async (options) => await chat({
|
|
|
38
38
|
const text = decoder.decode(chunk, { stream: true });
|
|
39
39
|
buffer += text;
|
|
40
40
|
const lines = buffer.split("\n");
|
|
41
|
-
buffer = lines.pop()
|
|
41
|
+
buffer = lines.pop() ?? "";
|
|
42
42
|
for (const line of lines) {
|
|
43
43
|
if (await processLine(line, controller))
|
|
44
44
|
break;
|
package/package.json
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xsai/stream-text",
|
|
3
|
-
"version": "0.0.29",
|
|
4
3
|
"type": "module",
|
|
4
|
+
"version": "0.0.30",
|
|
5
|
+
"description": "extra-small AI SDK for Browser, Node.js, Deno, Bun or Edge Runtime.",
|
|
5
6
|
"author": "Moeru AI",
|
|
6
7
|
"license": "MIT",
|
|
7
8
|
"homepage": "https://xsai.js.org",
|
|
8
|
-
"description": "extra-small AI SDK for Browser, Node.js, Deno, Bun or Edge Runtime.",
|
|
9
|
-
"keywords": [
|
|
10
|
-
"xsai",
|
|
11
|
-
"openai",
|
|
12
|
-
"ai"
|
|
13
|
-
],
|
|
14
9
|
"repository": {
|
|
15
10
|
"type": "git",
|
|
16
11
|
"url": "git+https://github.com/moeru-ai/xsai.git",
|
|
17
12
|
"directory": "packages/stream-text"
|
|
18
13
|
},
|
|
19
14
|
"bugs": "https://github.com/moeru-ai/xsai/issues",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"xsai",
|
|
17
|
+
"openai",
|
|
18
|
+
"ai"
|
|
19
|
+
],
|
|
20
20
|
"sideEffects": false,
|
|
21
|
-
"main": "./dist/index.js",
|
|
22
|
-
"types": "./dist/index.d.ts",
|
|
23
21
|
"exports": {
|
|
24
22
|
".": {
|
|
25
23
|
"types": "./dist/index.d.ts",
|
|
26
24
|
"default": "./dist/index.js"
|
|
27
25
|
}
|
|
28
26
|
},
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
29
|
"files": [
|
|
30
30
|
"dist"
|
|
31
31
|
],
|