@blueking/ai-blueking 0.1.4 → 0.1.5-beta.1
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/README.md +3 -2
- package/dist/chat-helper.js +38 -31
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -79,6 +79,8 @@ npm i @blueking/ai-blueking
|
|
|
79
79
|
|
|
80
80
|
// 发送消息
|
|
81
81
|
const handleSend = (message: string) => {
|
|
82
|
+
// 记录当前消息记录
|
|
83
|
+
const chatHistory = [...messages.value];
|
|
82
84
|
// 添加一条消息
|
|
83
85
|
messages.value.push({
|
|
84
86
|
role: 'user',
|
|
@@ -88,8 +90,7 @@ npm i @blueking/ai-blueking
|
|
|
88
90
|
chatHelper.stream(
|
|
89
91
|
{
|
|
90
92
|
inputs: {
|
|
91
|
-
|
|
92
|
-
chat_history: messages.value,
|
|
93
|
+
chat_history: chatHistory,
|
|
93
94
|
},
|
|
94
95
|
},
|
|
95
96
|
1,
|
package/dist/chat-helper.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
const
|
|
1
|
+
var b = Object.defineProperty;
|
|
2
|
+
var f = (r, t, e) => t in r ? b(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
3
|
+
var n = (r, t, e) => (f(r, typeof t != "symbol" ? t + "" : t, e), e);
|
|
4
|
+
const m = (r) => {
|
|
5
5
|
try {
|
|
6
|
-
return JSON.parse(
|
|
6
|
+
return JSON.parse(r), !0;
|
|
7
7
|
} catch {
|
|
8
8
|
return !1;
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
|
-
class
|
|
12
|
-
constructor(t, e,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this.url = t, this.handleStart = e, this.handleReceiveMessage =
|
|
11
|
+
class y {
|
|
12
|
+
constructor(t, e, a, o, h) {
|
|
13
|
+
n(this, "controllerMap");
|
|
14
|
+
n(this, "handleEnd");
|
|
15
|
+
n(this, "handleError");
|
|
16
|
+
n(this, "handleReceiveMessage");
|
|
17
|
+
n(this, "handleStart");
|
|
18
|
+
n(this, "url");
|
|
19
|
+
this.url = t, this.handleStart = e, this.handleReceiveMessage = a, this.handleEnd = o, this.handleError = h, this.controllerMap = {};
|
|
20
20
|
}
|
|
21
21
|
stop(t) {
|
|
22
|
-
var e,
|
|
23
|
-
return (
|
|
22
|
+
var e, a;
|
|
23
|
+
return (a = (e = this.controllerMap[t]) == null ? void 0 : e.abort) == null || a.call(e), this.handleEnd(t);
|
|
24
24
|
}
|
|
25
25
|
async stream(t, e) {
|
|
26
|
-
const
|
|
27
|
-
this.controllerMap[e] =
|
|
26
|
+
const a = new AbortController();
|
|
27
|
+
this.controllerMap[e] = a, fetch(this.url, {
|
|
28
28
|
method: "post",
|
|
29
|
-
signal:
|
|
29
|
+
signal: a.signal,
|
|
30
30
|
headers: {
|
|
31
31
|
"Content-Type": "application/json"
|
|
32
32
|
},
|
|
@@ -37,26 +37,33 @@ class m {
|
|
|
37
37
|
const h = o.body.pipeThrough(new window.TextDecoderStream()).getReader();
|
|
38
38
|
for (; ; )
|
|
39
39
|
try {
|
|
40
|
-
const { value:
|
|
41
|
-
if (
|
|
40
|
+
const { value: s, done: d } = await h.read();
|
|
41
|
+
if (d)
|
|
42
42
|
break;
|
|
43
|
-
|
|
44
|
-
`).forEach((
|
|
45
|
-
const l =
|
|
46
|
-
if (
|
|
47
|
-
const { event:
|
|
48
|
-
|
|
43
|
+
s.toString().split(`
|
|
44
|
+
`).forEach((p) => {
|
|
45
|
+
const l = p.trim();
|
|
46
|
+
if (m(l)) {
|
|
47
|
+
const { event: u, content: g, result: E, code: c, message: i } = JSON.parse(l);
|
|
48
|
+
if (E === !1) {
|
|
49
|
+
this.handleError(i, c, e);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
switch (u) {
|
|
49
53
|
case "text":
|
|
50
|
-
this.handleReceiveMessage(
|
|
54
|
+
this.handleReceiveMessage(g, e);
|
|
51
55
|
break;
|
|
52
56
|
case "done":
|
|
53
57
|
this.handleEnd(e);
|
|
54
58
|
break;
|
|
59
|
+
case "error":
|
|
60
|
+
this.handleError(i, c, e);
|
|
61
|
+
break;
|
|
55
62
|
}
|
|
56
63
|
}
|
|
57
64
|
});
|
|
58
|
-
} catch (
|
|
59
|
-
(
|
|
65
|
+
} catch (s) {
|
|
66
|
+
(s == null ? void 0 : s.code) !== 20 && this.handleError(s.message, s.code, e);
|
|
60
67
|
break;
|
|
61
68
|
}
|
|
62
69
|
}).catch((o) => {
|
|
@@ -65,5 +72,5 @@ class m {
|
|
|
65
72
|
}
|
|
66
73
|
}
|
|
67
74
|
export {
|
|
68
|
-
|
|
75
|
+
y as ChatHelper
|
|
69
76
|
};
|