inl-ui 0.1.4 → 0.1.6
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/components/index.cjs +118 -51
- package/dist/components/index.js +119 -52
- package/dist/index.cjs +119 -52
- package/dist/index.d.ts +1 -1
- package/dist/index.js +120 -53
- package/dist/style.css +1 -1
- package/package.json +1 -1
|
@@ -11234,13 +11234,16 @@ var index = installComponent(SszComment, "ssz-comment");
|
|
|
11234
11234
|
function formatDataString(str) {
|
|
11235
11235
|
const lines = str.split("\n");
|
|
11236
11236
|
const result = lines.filter(line => !!line.trim()).map(line => {
|
|
11237
|
-
const data = JSON.parse(line.replace(
|
|
11237
|
+
const data = JSON.parse(line.replace(/^data: /, ""));
|
|
11238
11238
|
return data.text;
|
|
11239
11239
|
}).filter(line => line !== void 0).join("");
|
|
11240
11240
|
return result;
|
|
11241
11241
|
}
|
|
11242
11242
|
function request(question, streamCallback, doneCallback) {
|
|
11243
|
+
const controller = new AbortController();
|
|
11244
|
+
const signal = controller.signal;
|
|
11243
11245
|
fetch("/mt_cpp_gpt/chat", {
|
|
11246
|
+
signal,
|
|
11244
11247
|
method: "POST",
|
|
11245
11248
|
headers: {
|
|
11246
11249
|
"Content-Type": "application/json"
|
|
@@ -11249,7 +11252,8 @@ function request(question, streamCallback, doneCallback) {
|
|
|
11249
11252
|
query: question,
|
|
11250
11253
|
conversation_id: ""
|
|
11251
11254
|
})
|
|
11252
|
-
}).then(res =>
|
|
11255
|
+
}).then(res => {
|
|
11256
|
+
const stream = res.body;
|
|
11253
11257
|
const decoder = new TextDecoder();
|
|
11254
11258
|
const reader = stream.getReader();
|
|
11255
11259
|
let result = "";
|
|
@@ -11262,22 +11266,32 @@ function request(question, streamCallback, doneCallback) {
|
|
|
11262
11266
|
doneCallback();
|
|
11263
11267
|
return;
|
|
11264
11268
|
}
|
|
11265
|
-
|
|
11266
|
-
|
|
11267
|
-
|
|
11268
|
-
|
|
11269
|
-
|
|
11270
|
-
|
|
11269
|
+
try {
|
|
11270
|
+
const dataString = decoder.decode(value, {
|
|
11271
|
+
stream: true
|
|
11272
|
+
});
|
|
11273
|
+
const str = formatDataString(dataString);
|
|
11274
|
+
result += str;
|
|
11275
|
+
streamCallback(result);
|
|
11276
|
+
} catch (e) {}
|
|
11271
11277
|
return processText();
|
|
11278
|
+
}).catch(() => {
|
|
11279
|
+
doneCallback();
|
|
11272
11280
|
});
|
|
11273
11281
|
}
|
|
11274
11282
|
return processText();
|
|
11283
|
+
}).catch(() => {
|
|
11284
|
+
doneCallback();
|
|
11275
11285
|
});
|
|
11286
|
+
return function stop() {
|
|
11287
|
+
controller.abort();
|
|
11288
|
+
};
|
|
11276
11289
|
}
|
|
11277
11290
|
function useQA() {
|
|
11278
11291
|
const context = vue.ref([]);
|
|
11279
11292
|
const answerLoading = vue.ref(false);
|
|
11280
11293
|
const answer = vue.ref("");
|
|
11294
|
+
let abort = null;
|
|
11281
11295
|
setTimeout(() => {
|
|
11282
11296
|
const questionItem = {
|
|
11283
11297
|
type: "answer",
|
|
@@ -11314,19 +11328,27 @@ function useQA() {
|
|
|
11314
11328
|
id: /* @__PURE__ */new Date().getTime()
|
|
11315
11329
|
});
|
|
11316
11330
|
questionItem.answers.push(answerItem.value);
|
|
11317
|
-
request(question, data => {
|
|
11331
|
+
abort = request(question, data => {
|
|
11318
11332
|
answer.value = data;
|
|
11319
11333
|
answerItem.value.content = data;
|
|
11320
11334
|
}, () => {
|
|
11321
11335
|
answerLoading.value = false;
|
|
11322
11336
|
answerItem.value.loadEnd = true;
|
|
11337
|
+
abort = null;
|
|
11323
11338
|
});
|
|
11324
11339
|
}
|
|
11340
|
+
function abortRequest() {
|
|
11341
|
+
if (abort) {
|
|
11342
|
+
abort();
|
|
11343
|
+
abort = null;
|
|
11344
|
+
}
|
|
11345
|
+
}
|
|
11325
11346
|
return {
|
|
11326
11347
|
context,
|
|
11327
11348
|
answerLoading,
|
|
11328
11349
|
answer,
|
|
11329
|
-
sendQuestion
|
|
11350
|
+
sendQuestion,
|
|
11351
|
+
abortRequest
|
|
11330
11352
|
};
|
|
11331
11353
|
}
|
|
11332
11354
|
|
|
@@ -11336,9 +11358,10 @@ const Input = vue.defineComponent({
|
|
|
11336
11358
|
emit,
|
|
11337
11359
|
expose
|
|
11338
11360
|
}) {
|
|
11361
|
+
const abortRequest = vue.inject("abortRequest");
|
|
11362
|
+
const loading = vue.inject("answerLoading");
|
|
11339
11363
|
const value = vue.ref("");
|
|
11340
11364
|
const isFocus = vue.ref(false);
|
|
11341
|
-
const loading = vue.inject("answerLoading");
|
|
11342
11365
|
const send = () => {
|
|
11343
11366
|
if (loading.value) return;
|
|
11344
11367
|
if (value.value.length === 0) {
|
|
@@ -11348,6 +11371,12 @@ const Input = vue.defineComponent({
|
|
|
11348
11371
|
emit("send", value.value);
|
|
11349
11372
|
value.value = "";
|
|
11350
11373
|
};
|
|
11374
|
+
const handleAbord = () => {
|
|
11375
|
+
abortRequest();
|
|
11376
|
+
};
|
|
11377
|
+
const handleMicClick = () => {
|
|
11378
|
+
antDesignVue.message.info("\u6682\u4E0D\u652F\u6301\u8BED\u97F3\u8F93\u5165");
|
|
11379
|
+
};
|
|
11351
11380
|
const clear = () => value.value = "";
|
|
11352
11381
|
expose({
|
|
11353
11382
|
clear
|
|
@@ -11359,7 +11388,8 @@ const Input = vue.defineComponent({
|
|
|
11359
11388
|
}, [vue.createVNode("img", {
|
|
11360
11389
|
"class": "img img-mic",
|
|
11361
11390
|
"src": "/micro-assets/largeLanguageModel/mic.png",
|
|
11362
|
-
"alt": ""
|
|
11391
|
+
"alt": "",
|
|
11392
|
+
"onClick": handleMicClick
|
|
11363
11393
|
}, null), vue.createVNode(vue.resolveComponent("a-input"), {
|
|
11364
11394
|
"value": value.value,
|
|
11365
11395
|
"onUpdate:value": $event => value.value = $event,
|
|
@@ -11368,9 +11398,11 @@ const Input = vue.defineComponent({
|
|
|
11368
11398
|
"onFocus": () => isFocus.value = true,
|
|
11369
11399
|
"onBlur": () => isFocus.value = false,
|
|
11370
11400
|
"onPressEnter": send
|
|
11371
|
-
}, null), loading.value ? vue.createVNode(
|
|
11372
|
-
"class": "btn-
|
|
11373
|
-
"title": "\u4E2D\u6B62\u56DE\u7B54"
|
|
11401
|
+
}, null), loading.value ? vue.createVNode("img", {
|
|
11402
|
+
"class": "btn-abort",
|
|
11403
|
+
"title": "\u4E2D\u6B62\u56DE\u7B54",
|
|
11404
|
+
"src": "/micro-assets/largeLanguageModel/btn-abort.png",
|
|
11405
|
+
"onClick": handleAbord
|
|
11374
11406
|
}, null) : vue.createVNode("img", {
|
|
11375
11407
|
"class": "img img-send",
|
|
11376
11408
|
"src": "/micro-assets/largeLanguageModel/send.png",
|
|
@@ -11446,12 +11478,15 @@ const QuestionBubble = vue.defineComponent({
|
|
|
11446
11478
|
}
|
|
11447
11479
|
},
|
|
11448
11480
|
setup(props) {
|
|
11481
|
+
const userinfo = JSON.parse(sessionStorage.getItem("userinfo") || "{}");
|
|
11482
|
+
const avatar = userinfo.photo || "/micro-assets/platform_app/avatar.png";
|
|
11483
|
+
const name = userinfo.employeeName || userinfo.userName || "\u7528\u6237";
|
|
11449
11484
|
return () => vue.createVNode("div", {
|
|
11450
11485
|
"class": "question-bubble chat-bubble"
|
|
11451
11486
|
}, [vue.createVNode(Avatar, {
|
|
11452
11487
|
"reverse": true,
|
|
11453
|
-
"avatar":
|
|
11454
|
-
"name":
|
|
11488
|
+
"avatar": avatar,
|
|
11489
|
+
"name": name
|
|
11455
11490
|
}, null), vue.createVNode("div", {
|
|
11456
11491
|
"class": "bubble question"
|
|
11457
11492
|
}, [props.content]), vue.createVNode("div", {
|
|
@@ -11460,12 +11495,18 @@ const QuestionBubble = vue.defineComponent({
|
|
|
11460
11495
|
}
|
|
11461
11496
|
});
|
|
11462
11497
|
|
|
11498
|
+
const commonStyle = `
|
|
11499
|
+
:host > p {
|
|
11500
|
+
margin: 0;
|
|
11501
|
+
}
|
|
11502
|
+
:host {
|
|
11503
|
+
font-size: 14px;
|
|
11504
|
+
}
|
|
11505
|
+
`;
|
|
11463
11506
|
const styleDark = `
|
|
11464
11507
|
<style>
|
|
11465
|
-
|
|
11466
|
-
|
|
11467
|
-
}
|
|
11468
|
-
|
|
11508
|
+
${commonStyle}
|
|
11509
|
+
|
|
11469
11510
|
* {
|
|
11470
11511
|
color: #fff;
|
|
11471
11512
|
}
|
|
@@ -11476,6 +11517,8 @@ const styleDark = `
|
|
|
11476
11517
|
`;
|
|
11477
11518
|
const styleLight = `
|
|
11478
11519
|
<style>
|
|
11520
|
+
${commonStyle}
|
|
11521
|
+
|
|
11479
11522
|
* {
|
|
11480
11523
|
color: #20242B;
|
|
11481
11524
|
}
|
|
@@ -11487,7 +11530,7 @@ const styleLight = `
|
|
|
11487
11530
|
|
|
11488
11531
|
const suggestionList = ["\u7F8E\u5C0F\u817E\u80FD\u5E2E\u6211\u505A\u4EC0\u4E48\uFF1F", "\u8FD1\u4E00\u4E2A\u6708\u7684\u4ECB\u8017\u60C5\u51B5\u5982\u4F55\uFF1F", "\u5C3E\u77FF\u8DD1\u7C97\u7684\u6392\u67E5\u5904\u7406\u65B9\u6CD5\u6709\u54EA\u4E9B\uFF1F\u5C3E\u77FF\u8DD1\u7C97\u7684\u6392\u67E5\u5904\u7406\u65B9\u6CD5\u6709\u54EA\u4E9B\u5C3E\u77FF\u8DD1\u7C97\u7684\u6392\u67E5\u5904\u7406\u65B9\u6CD5\u6709\u54EA\u4E9B\u5C3E\u77FF\u8DD1\u7C97\u7684\u6392\u67E5\u5904\u7406\u65B9\u6CD5\u6709\u54EA\u4E9B"];
|
|
11489
11532
|
const AnswerBubble = vue.defineComponent({
|
|
11490
|
-
emits: ["send", "render", "delete"],
|
|
11533
|
+
emits: ["send", "render", "delete", "regenerate"],
|
|
11491
11534
|
props: {
|
|
11492
11535
|
content: {
|
|
11493
11536
|
type: Array,
|
|
@@ -11518,7 +11561,9 @@ const AnswerBubble = vue.defineComponent({
|
|
|
11518
11561
|
});
|
|
11519
11562
|
const renderText = () => {
|
|
11520
11563
|
if (!shadowRoot) return;
|
|
11521
|
-
|
|
11564
|
+
vue.nextTick(() => {
|
|
11565
|
+
emit("render", activeAnswer.value.content);
|
|
11566
|
+
});
|
|
11522
11567
|
const themeStyle = chatTheme === "dark" ? styleDark : styleLight;
|
|
11523
11568
|
const html = `
|
|
11524
11569
|
${trasformMd(activeAnswer.value.content)}
|
|
@@ -11527,9 +11572,12 @@ const AnswerBubble = vue.defineComponent({
|
|
|
11527
11572
|
`;
|
|
11528
11573
|
shadowRoot.innerHTML = html;
|
|
11529
11574
|
};
|
|
11530
|
-
vue.watch([
|
|
11575
|
+
vue.watch([activeAnswer, activeAnswerIndex], renderText, {
|
|
11531
11576
|
deep: true
|
|
11532
11577
|
});
|
|
11578
|
+
const switchAnswer = step => {
|
|
11579
|
+
activeAnswerIndex.value += step;
|
|
11580
|
+
};
|
|
11533
11581
|
const operateList = vue.reactive([{
|
|
11534
11582
|
title: "\u590D\u5236",
|
|
11535
11583
|
key: "copy",
|
|
@@ -11558,7 +11606,7 @@ const AnswerBubble = vue.defineComponent({
|
|
|
11558
11606
|
const handleOperate = key => {
|
|
11559
11607
|
switch (key) {
|
|
11560
11608
|
case "like":
|
|
11561
|
-
if (!activeAnswer.value.
|
|
11609
|
+
if (!activeAnswer.value.isLike && !activeAnswer.value.isDislike) {
|
|
11562
11610
|
activeAnswer.value.isLike = !activeAnswer.value.isLike;
|
|
11563
11611
|
}
|
|
11564
11612
|
break;
|
|
@@ -11576,12 +11624,25 @@ const AnswerBubble = vue.defineComponent({
|
|
|
11576
11624
|
title: "\u786E\u5B9A\u5220\u9664\u8FD9\u4E2A\u56DE\u7B54\u5417\uFF1F",
|
|
11577
11625
|
onOk: () => {
|
|
11578
11626
|
emit("delete", activeAnswer.value.id);
|
|
11627
|
+
if (activeAnswerIndex.value > 0 && activeAnswerIndex.value === props.content.length - 1) {
|
|
11628
|
+
activeAnswerIndex.value--;
|
|
11629
|
+
}
|
|
11579
11630
|
}
|
|
11580
11631
|
});
|
|
11581
11632
|
break;
|
|
11582
11633
|
case "comment":
|
|
11583
11634
|
antDesignVue.message.info("\u6682\u672A\u5F00\u653E");
|
|
11584
11635
|
break;
|
|
11636
|
+
case "regenerate":
|
|
11637
|
+
if (props.content.length >= 5) {
|
|
11638
|
+
antDesignVue.message.info("\u6700\u591A\u652F\u6301\u751F\u62105\u6761\u56DE\u7B54");
|
|
11639
|
+
return;
|
|
11640
|
+
}
|
|
11641
|
+
emit("regenerate", activeAnswer.value.id);
|
|
11642
|
+
vue.nextTick(() => {
|
|
11643
|
+
activeAnswerIndex.value = props.content.length - 1;
|
|
11644
|
+
});
|
|
11645
|
+
break;
|
|
11585
11646
|
}
|
|
11586
11647
|
};
|
|
11587
11648
|
return () => {
|
|
@@ -11590,30 +11651,30 @@ const AnswerBubble = vue.defineComponent({
|
|
|
11590
11651
|
"onClick": () => emit("send", item)
|
|
11591
11652
|
}, [item]));
|
|
11592
11653
|
const showOperates = !activeAnswer.value.hideOperates && activeAnswer.value.loadEnd;
|
|
11593
|
-
const operateDom = operateList.map(item => {
|
|
11594
|
-
|
|
11595
|
-
|
|
11596
|
-
|
|
11597
|
-
|
|
11598
|
-
|
|
11599
|
-
|
|
11600
|
-
|
|
11601
|
-
|
|
11602
|
-
|
|
11603
|
-
});
|
|
11604
|
-
});
|
|
11654
|
+
const operateDom = operateList.map(item => vue.createVNode(vue.resolveComponent("a-tooltip"), {
|
|
11655
|
+
"title": item.title
|
|
11656
|
+
}, {
|
|
11657
|
+
default: () => [vue.createVNode("div", {
|
|
11658
|
+
"class": ["operate-item", item.key, {
|
|
11659
|
+
active: item.isActive
|
|
11660
|
+
}],
|
|
11661
|
+
"onClick": () => handleOperate(item.key)
|
|
11662
|
+
}, null)]
|
|
11663
|
+
}));
|
|
11605
11664
|
const prevDisabled = activeAnswerIndex.value === 0;
|
|
11606
11665
|
const nextDisabled = activeAnswerIndex.value === props.content.length - 1;
|
|
11607
11666
|
const answerNav = vue.createVNode("div", {
|
|
11608
|
-
"class": "operate-item"
|
|
11667
|
+
"class": "operate-item operate-nav"
|
|
11609
11668
|
}, [vue.createVNode("span", {
|
|
11610
11669
|
"class": ["nav", {
|
|
11611
|
-
|
|
11612
|
-
}]
|
|
11613
|
-
|
|
11670
|
+
disabled: prevDisabled
|
|
11671
|
+
}],
|
|
11672
|
+
"onClick": () => switchAnswer(-1)
|
|
11673
|
+
}, ["<"]), vue.createVNode("span", null, [activeAnswerIndex.value + 1]), " ", vue.createVNode("span", null, [vue.createTextVNode("/")]), vue.createVNode("span", null, [props.content.length]), vue.createVNode("span", {
|
|
11614
11674
|
"class": ["nav", {
|
|
11615
|
-
|
|
11616
|
-
}]
|
|
11675
|
+
disabled: nextDisabled
|
|
11676
|
+
}],
|
|
11677
|
+
"onClick": () => switchAnswer(1)
|
|
11617
11678
|
}, [">"])]);
|
|
11618
11679
|
return vue.createVNode("div", {
|
|
11619
11680
|
"class": "answer-bubble chat-bubble"
|
|
@@ -11623,21 +11684,24 @@ const AnswerBubble = vue.defineComponent({
|
|
|
11623
11684
|
}, null), vue.createVNode("div", {
|
|
11624
11685
|
"ref": bubbleRef,
|
|
11625
11686
|
"class": "bubble answer"
|
|
11626
|
-
}, null),
|
|
11687
|
+
}, null), vue.createVNode("div", {
|
|
11627
11688
|
"class": "operates"
|
|
11628
|
-
}, [props.content.length > 1 && answerNav, operateDom])]);
|
|
11689
|
+
}, [props.content.length > 1 && answerNav, showOperates && operateDom])]);
|
|
11629
11690
|
};
|
|
11630
11691
|
}
|
|
11631
11692
|
});
|
|
11632
11693
|
|
|
11633
11694
|
const QaContext = vue.defineComponent({
|
|
11695
|
+
emits: ["regenerate"],
|
|
11634
11696
|
props: {
|
|
11635
11697
|
list: {
|
|
11636
11698
|
type: Array,
|
|
11637
11699
|
default: () => []
|
|
11638
11700
|
}
|
|
11639
11701
|
},
|
|
11640
|
-
setup(props
|
|
11702
|
+
setup(props, {
|
|
11703
|
+
emit
|
|
11704
|
+
}) {
|
|
11641
11705
|
const containerRef = vue.ref();
|
|
11642
11706
|
const onAnswerRender = text => {
|
|
11643
11707
|
containerRef.value.scrollTo({
|
|
@@ -11676,7 +11740,8 @@ const QaContext = vue.defineComponent({
|
|
|
11676
11740
|
contextList.push(vue.createVNode(AnswerBubble, {
|
|
11677
11741
|
"onRender": onAnswerRender,
|
|
11678
11742
|
"content": questionItem.answers,
|
|
11679
|
-
"onDelete": answerId => handleDeleteAnswer(questionItem.id, answerId)
|
|
11743
|
+
"onDelete": answerId => handleDeleteAnswer(questionItem.id, answerId),
|
|
11744
|
+
"onRegenerate": () => emit("regenerate", questionItem.id)
|
|
11680
11745
|
}, null));
|
|
11681
11746
|
}
|
|
11682
11747
|
}
|
|
@@ -11708,17 +11773,19 @@ const ChatBox = vue.defineComponent({
|
|
|
11708
11773
|
context,
|
|
11709
11774
|
answerLoading,
|
|
11710
11775
|
sendQuestion,
|
|
11711
|
-
|
|
11776
|
+
abortRequest
|
|
11712
11777
|
} = useQA();
|
|
11713
11778
|
vue.provide("answerLoading", answerLoading);
|
|
11714
|
-
|
|
11715
|
-
|
|
11779
|
+
vue.provide("abortRequest", abortRequest);
|
|
11780
|
+
const handleSend = (msg, questionId) => {
|
|
11781
|
+
sendQuestion(msg, questionId);
|
|
11716
11782
|
};
|
|
11717
11783
|
return () => {
|
|
11718
11784
|
return vue.createVNode("div", {
|
|
11719
11785
|
"class": ["inl-chat-box", `inl-chat-box-${props.theme}`]
|
|
11720
11786
|
}, [vue.createVNode(QaContext, {
|
|
11721
|
-
"list": context.value
|
|
11787
|
+
"list": context.value,
|
|
11788
|
+
"onRegenerate": qId => handleSend("", qId)
|
|
11722
11789
|
}, null), vue.createVNode(Bottom, {
|
|
11723
11790
|
"onSend": handleSend
|
|
11724
11791
|
}, null)]);
|