Commit ffe31662 authored by mhw's avatar mhw

知识图谱更新

parent f2b9b2b4
......@@ -19216,6 +19216,16 @@
"extsprintf": "^1.2.0"
}
},
"vis-data": {
"version": "7.1.9",
"resolved": "https://registry.npmmirror.com/vis-data/-/vis-data-7.1.9.tgz",
"integrity": "sha512-COQsxlVrmcRIbZMMTYwD+C2bxYCFDNQ2EHESklPiInbD/Pk3JZ6qNL84Bp9wWjYjAzXfSlsNaFtRk+hO9yBPWA=="
},
"vis-network": {
"version": "9.1.9",
"resolved": "https://registry.npmmirror.com/vis-network/-/vis-network-9.1.9.tgz",
"integrity": "sha512-Ft+hLBVyiLstVYSb69Q1OIQeh3FeUxHJn0WdFcq+BFPqs+Vq1ibMi2sb//cxgq1CP7PH4yOXnHxEH/B2VzpZYA=="
},
"vm-browserify": {
"version": "1.1.2",
"resolved": "https://registry.npmmirror.com/vm-browserify/-/vm-browserify-1.1.2.tgz",
......
module.exports = {
baseUrl: 'http://192.168.0.34:8082/',
wsUrl: 'ws://192.168.0.36:7860/',
baseUrl: 'http://218.76.0.69:8082/',
wsUrl: 'ws://218.76.0.69:7860/',
projectName: '灵境大模型平台'
}
......@@ -5,6 +5,9 @@
</template>
<script>
import 'vis-network/dist/dist/vis-network.css';
// eslint-disable-next-line no-unused-vars
import { Network } from 'vis-network/dist/vis-network.esm.js';
import hljs from 'highlight.js' // 代码块高亮
// import 'highlight.js/styles/github.css' // 代码块高亮样式
......@@ -56,9 +59,11 @@ export default {
anchorTags.forEach((aTag) => {
let tagUrl = aTag.getAttribute('href') || ''
let isFile = ['pdf', 'jpg', 'gif', 'jpeg', 'png', 'docx', 'doc', 'xlsx', 'xls', 'mp4', 'webm', 'ogg', 'ogv', 'txt'].indexOf(tagUrl.split('.').pop().toLowerCase()) !== -1
let isFile2 = ['html', 'md', 'json', 'jsonl', 'csv', 'pdf', 'png', 'jpg', 'jpeg', 'bmp', 'eml', 'msg', 'epub', 'xlsx', 'xlsd', 'ipynb', 'odt', 'py', 'rst', 'rtf', 'srt', 'toml', 'tsv', 'docx', 'doc', 'xml', 'ppt', 'pptx', 'txt', 'htm'].indexOf(tagUrl.split('.').pop().toLowerCase()) !== -1
if (isFile2 || aTag.id === 'show_detail') { // 判断知识库以及文件对话 的文件类型,并添加dom以及样式 || 添加特殊a标签展示详情内容
console.log(tagUrl, isFile);
if (isFile2 || aTag.className === 'show_detail') { // 判断知识库以及文件对话 的文件类型,并添加dom以及样式 || 添加特殊a标签展示详情内容
this.setDescribeStyle(aTag)
}
aTag.addEventListener('click', function (event) {
......@@ -83,8 +88,10 @@ export default {
<i class="el-icon-arrow-down"></i>
</button>
`);
var buttonDom = aTag.nextElementSibling;// 下拉按钮
let describeDom = aTag.parentNode.nextElementSibling// 详情
let describeDom = aTag.parentNode.querySelector('.describe-view') || aTag.parentNode.parentNode.querySelector('.describe-view')// 详情
this.initNetwork(describeDom, describeDom.getAttribute('data'))
let height = describeDom.scrollHeight
describeDom.setAttribute('style', 'height:0px;')
buttonDom.addEventListener('click', function (event) {
......@@ -94,6 +101,113 @@ export default {
describeDom.setAttribute('style', `height:${height}px;`)
}
})
},
initNetwork (target, data) {
// 判断有没有data属性
if (target.hasAttribute('data') && target.getAttribute('data') !== null) {
const container = document.createElement('div');
container.style.width = '100%'
container.style.border = '1px solid lightgray'
container.style.height = '400px'
container.style.position = 'relative';
container.style.borderRadius = '10px'
container.style.marginBottom = '10px'
container.style.zIndex = '10000'
data = JSON.parse(data.replace(/'/g, '"')).network
data.edges = data.edges.map((item) => {
item.length = 300
return item
})
const options = {
autoResize: true, // 网络将自动检测其容器的大小调整,并相应地重绘自身
nodes: {
shape: 'circle',
widthConstraint: 100, // 设置数字,将节点的最小和最大宽度设为该值,当值设为很小的时候,label会换行,节点会保持一个最小值,里边的内容会换行
color: {
background: '#0092FF'
},
font: {
color: '#7a7a7a' // 修改节点内文字颜色为黑色
},
size: 30
},
edges: {
arrows: {
to: {
enabled: true,
scaleFactor: 0.4 // 箭头大小的缩放因子
}
},
font: {
size: 12
}
},
physics: {
enabled: true,
barnesHut: {
gravitationalConstant: -2000
}
}
};
// eslint-disable-next-line no-unused-vars
const network = new Network(container, data, options);
target.appendChild(container);
container.setAttribute('isfull', '0')
let fullDom = document.createElement('div')
fullDom.classList.add('el-icon-full-screen', 'full')
container.appendChild(fullDom)
fullDom.addEventListener('click', () => {
console.log(container.getAttribute('isfull'));
if (container.getAttribute('isfull') !== '0') {
container.style.height = '400px';
container.style.position = 'relative';
container.style.background = 'none'
container.setAttribute('isfull', '0')
container.style.border = '1px solid lightgray'
fullDom.classList.remove('el-icon-close')
fullDom.classList.add('el-icon-full-screen')
} else {
fullDom.classList.remove('el-icon-full-screen')
fullDom.classList.add('el-icon-close')
container.style.height = '100%';
container.style.position = 'fixed';
container.style.top = 0;
container.style.left = 0;
container.style.border = 'none'
container.style.background = '#00000096'
container.setAttribute('isfull', '1')
}
})
let downDom = document.createElement('div')
downDom.classList.add('el-icon-download', 'down')
downDom.addEventListener('click', () => {
this.downloadCanvas(container.querySelector('canvas'))
})
container.appendChild(downDom)
}
},
downloadCanvas (canvas) {
// 获取 Canvas 的内容作为DataURL
var dataURL = canvas.toDataURL('image/png');
// 创建一个下载链接
var downloadLink = document.createElement('a');
downloadLink.href = dataURL;
downloadLink.download = 'Image.png'; // 设置下载文件的名称
// 将下载链接添加到页面
document.body.appendChild(downloadLink);
// 模拟点击下载链接
downloadLink.click();
// 移除下载链接
document.body.removeChild(downloadLink);
}
}
......@@ -112,11 +226,43 @@ export default {
<style>
.describe-view {
overflow: hidden !important;
transition: 0.5s all;
transition:all 0.5s ;
color: #000;
font-size: 14px;
background-color: #fff;
border-radius: 10px;
padding: 0 20px 0 20px;
position: relative;
}
</style>
<style>
.vis-label {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.full{
width: 20px;
height: 20px;
background: #0092FF;
position: absolute;
right: 10px;
top: 10px;
font-size: 20px;
color: #fff;
border-radius: 5px;
/* transition: all 0.5s; */
}
.down{
width: 20px;
height: 20px;
background: #0092FF;
position: absolute;
right: 40px;
top: 10px;
font-size: 20px;
color: #fff;
border-radius: 5px;
}
</style>
<!-- 右侧聊天界面 -->
<template>
<div class="box">
<div class="box" ref="box">
<div class="contentBox" ref="contentBox" v-if="myHistory.length > 0">
<div v-for=" item in myHistory" :key="item.id">
......@@ -18,13 +18,13 @@
GPT
</div>
<div class="content">
<contentView :content="item.answer" :ref="'contentView'+item.id" />
<contentView :content="item.answer" :ref="'contentView' + item.id" />
</div>
</div>
</div>
</div>
<div class="initBox" v-else>
<div class="initBox" ref="initBox" v-else>
<div class="text">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;你好,<br>
我是人工智能语言模型<br>
......@@ -38,10 +38,12 @@
<el-button icon="el-icon-delete" style="margin-left:10px" @click="clear" type="danger" plain></el-button>
</div>
<div id="network"></div>
</div>
</template>
<script>
import { GetStreaming } from '@/utils/getStreaming.js';
// import codePreview from '../codePreview';
import contentView from '../contentView';
......@@ -128,7 +130,7 @@ export default {
this.inputContent = null;
this.param.history = []
this.myHistory.slice(0, -1).slice(-this.heistoryRotate).forEach((item) => {
this.param.history.push(...[{ role: item.role, content: item.content }, { role: 'assistant', content: item.excludeReferenceAnswer}])
this.param.history.push(...[{ role: item.role, content: item.content }, { role: 'assistant', content: item.excludeReferenceAnswer }])
})
this.$emit('submit')
......@@ -148,7 +150,9 @@ export default {
nowChat.excludeReferenceAnswer += data
nowChat.answer += data;
} else if (this.chatForm.pattern === '专业知识库问答') {
console.log(data);
let temporary = JSON.parse(`[${data}]`.replace(/}{/g, '},{'))
temporary.forEach((item) => {
this.modifyContent(item)// 修改返回内容
nowChat.excludeReferenceAnswer += item.answer || '' // 排除回答中的引用内容
......@@ -165,8 +169,9 @@ export default {
nowChat.answer += item.answer || '\n' + item.docs
})
} else if (this.chatForm.pattern === '知识图谱问答') {
console.log(data);
let temporary = JSON.parse(`[${data}]`.replace(/}{/g, '},{'))
temporary.forEach((item) => {
this.modifyContent(item)// 修改返回内容
nowChat.excludeReferenceAnswer += item.answer || '' // 排除回答中的引用内容
......@@ -183,7 +188,7 @@ export default {
item.docs = item.docs.map((item2) => {
let tagUrl = ((item2?.match(/\]\((.*?)\)/g) || [])[0] || '').slice(2, -1)
let url = ''
item2 = item2.replace(/\n/g, '<br>')
// item2 = item2.replace(/\n/g, '<br>')
if (tagUrl.indexOf('https') !== -1) {
url = tagUrl.replace(/^https:\/\/[^/]+\//, `https://${window.location.hostname}:${window.location.port}/`);
item2 = item2.replace(/\]\((.*?)\)/g, `](${url})`)
......@@ -203,15 +208,16 @@ export default {
console.log('未找到匹配的指定字符串');
}
/// ////////特殊标签后包装div
var specifiedString = '<a id="show_detail"></a>';
var match2 = item2.match(new RegExp(specifiedString + '(.*)')) || [];
if (match2 && match2.length > 1) {
var textAfterSpecifiedString = match2[1];
// var specifiedString = '<a class="show_detail"></a>';
// var match2 = item2.match(new RegExp(specifiedString + '(.*)')) || [];
const match2 = item2.match(/<a\s+class="show_detail"\s+data="([^"]*)"><\/a>([\s\S]*)/);
if (match2 && match2.length === 3) {
var textAfterSpecifiedString = match2[2];
var data = match2[1]
// 修改文本内容
textAfterSpecifiedString = `<div class="describe-view">${textAfterSpecifiedString}</div>`
textAfterSpecifiedString = `<div class="describe-view" data="${data}" >${textAfterSpecifiedString}</div>`
item2 = item2.replace(match2[1], textAfterSpecifiedString)
item2 = item2.replace(match2[2], textAfterSpecifiedString)
}
return item2.replace('出处', '知识溯源')
})
......@@ -314,4 +320,5 @@ export default {
.inputBox {
display: flex;
}</style>
}
</style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment