|
|
@@ -1,10 +1,20 @@
|
|
|
<template>
|
|
|
<div id="xiaoshi_AI_wrapper">
|
|
|
<div ref="AIMessage" class="AI_message">
|
|
|
- <div v-if="!chatHistory || chatHistory.length == 0" class="empty">
|
|
|
+ <div v-if="(!chatHistory || chatHistory.length == 0) && (!parameters || !parameters.opening_statement)" class="empty">
|
|
|
<h1>你好,我是小世AI助手</h1>
|
|
|
</div>
|
|
|
<div v-else class="AI_message_wrapper">
|
|
|
+ <div class="AI messageBox_item" v-if="parameters && parameters.opening_statement">
|
|
|
+ <div class="icon">
|
|
|
+ <svg-icon class="xiaoshiIcon" iconClass="小世AI" iconName="小世AI"></svg-icon>
|
|
|
+ </div>
|
|
|
+ <div class="message_wrapper">
|
|
|
+ <div class="message">
|
|
|
+ <div style="font-size:12px !important" v-html="getParameters(parameters.opening_statement)"></div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
<div v-for="(chat,chatIndex) in chatHistory" :key="chat.id" class="messageBox" :id="'chat_'+chat.id">
|
|
|
<div class="user messageBox_item">
|
|
|
<div class="icon">
|
|
|
@@ -125,6 +135,7 @@ export default {
|
|
|
scrollLock:false,
|
|
|
currentTaskId:null,
|
|
|
md: null,
|
|
|
+ parameters:{}
|
|
|
};
|
|
|
},
|
|
|
watch: {
|
|
|
@@ -152,6 +163,7 @@ export default {
|
|
|
|
|
|
},
|
|
|
created() {
|
|
|
+ this.init()
|
|
|
this.getChatHistory()
|
|
|
},
|
|
|
mounted() {
|
|
|
@@ -171,6 +183,49 @@ export default {
|
|
|
},
|
|
|
methods: {
|
|
|
renderMarkdown,
|
|
|
+ //获取开场白内容
|
|
|
+ getParameters(html){
|
|
|
+ if(!html){
|
|
|
+ return ''
|
|
|
+ }
|
|
|
+ // 创建一个新的 DOMParser 实例
|
|
|
+ const parser = new DOMParser();
|
|
|
+ var text1 = `${html}`
|
|
|
+ // 解析包含 HTML 实体的字符串
|
|
|
+ const doc = parser.parseFromString(text1, "text/html");
|
|
|
+ // 提取 body 中的文本内容,此时 HTML 实体已被转换
|
|
|
+ return doc.body.innerHTML;
|
|
|
+ },
|
|
|
+ // 初始化
|
|
|
+ async init(){
|
|
|
+ let API_KEY = 'app-DDGJt4QUmzlc2aFQ5voOAXIj'
|
|
|
+ let res = await fetch('https://ai.xsip.cn/v1/parameters', {
|
|
|
+ method: 'GET',
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'application/json',
|
|
|
+ 'Authorization': `Bearer ${API_KEY}`,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ if(res.ok){
|
|
|
+ const reader = res.body.getReader();
|
|
|
+ const decoder = new TextDecoder('utf-8');
|
|
|
+ while (true) {
|
|
|
+ const { done, value } = await reader.read();
|
|
|
+ if(done){
|
|
|
+ break
|
|
|
+ }
|
|
|
+ const chunk = decoder.decode(value);
|
|
|
+ if(chunk){
|
|
|
+ try{
|
|
|
+ let json = JSON.parse(chunk)
|
|
|
+ this.parameters = json
|
|
|
+ }catch(e){
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
// 监听滚动事件
|
|
|
async handleScroll() {
|
|
|
const messageBox = this.$refs.AIMessage;
|