@xsai/stream-text 0.0.23 → 0.0.24
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 +1 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { chat
|
|
1
|
+
import { chat } from '@xsai/shared-chat';
|
|
2
2
|
|
|
3
3
|
const dataHeaderPrefix = "data: ";
|
|
4
4
|
const dataErrorPrefix = `{"error":`;
|
|
@@ -6,17 +6,6 @@ const streamText = async (options) => await chat({
|
|
|
6
6
|
...options,
|
|
7
7
|
stream: true
|
|
8
8
|
}).then(async (res) => {
|
|
9
|
-
if (!res.ok) {
|
|
10
|
-
const error = new ChatError(`Remote sent ${res.status} response`, res);
|
|
11
|
-
error.cause = new Error(await res.text());
|
|
12
|
-
}
|
|
13
|
-
if (!res.body) {
|
|
14
|
-
throw new ChatError("Response body is empty from remote server", res);
|
|
15
|
-
}
|
|
16
|
-
if (!(res.body instanceof ReadableStream)) {
|
|
17
|
-
const error = new ChatError(`Expected Response body to be a ReadableStream, but got ${String(res.body)}`, res);
|
|
18
|
-
error.cause = new Error(`Content-Type is ${res.headers.get("Content-Type")}`);
|
|
19
|
-
}
|
|
20
9
|
const decoder = new TextDecoder();
|
|
21
10
|
let finishReason;
|
|
22
11
|
let usage;
|