Commit b62a22ec authored by mhw's avatar mhw

版本跟新

parent b7558ad7
...@@ -6,11 +6,12 @@ export default class DatasetData { ...@@ -6,11 +6,12 @@ export default class DatasetData {
static view (sender, params, axiosOption, httpOption) { static view (sender, params, axiosOption, httpOption) {
return sender.doUrl('/admin/app/datasetData/view', 'get', params, axiosOption, httpOption); return sender.doUrl('/admin/app/datasetData/view', 'get', params, axiosOption, httpOption);
} }
static update (sender, params, axiosOption, httpOption) { static update (sender, params, axiosOption, httpOption) {
return sender.doUrl('/admin/app/datasetData/update', 'post', params, axiosOption, httpOption); return sender.doUrl('/admin/app/datasetData/update', 'post', params, axiosOption, httpOption);
} }
static add (sender, params, axiosOption, httpOption) {
return sender.doUrl('/admin/app/datasetData/add', 'post', params, axiosOption, httpOption);
}
static delete (sender, params, axiosOption, httpOption) { static delete (sender, params, axiosOption, httpOption) {
return sender.doUrl('/admin/app/datasetData/delete', 'post', params, axiosOption, httpOption); return sender.doUrl('/admin/app/datasetData/delete', 'post', params, axiosOption, httpOption);
} }
...@@ -20,5 +21,4 @@ export default class DatasetData { ...@@ -20,5 +21,4 @@ export default class DatasetData {
static summaryCount (sender, params, axiosOption, httpOption) { static summaryCount (sender, params, axiosOption, httpOption) {
return sender.doUrl('/admin/app/datasetData/summaryCount', 'get', params, axiosOption, httpOption); return sender.doUrl('/admin/app/datasetData/summaryCount', 'get', params, axiosOption, httpOption);
} }
DatasetData
} }
module.exports = { module.exports = {
// baseUrl: 'http://218.76.0.69:8082/', // baseUrl: 'http://218.76.0.69:8082/',
baseUrl: 'http://192.168.0.34:8082/', // baseUrl: 'http://192.168.0.34:8082/',
// baseUrl: 'http://192.168.0.36:8082/', // baseUrl: 'http://192.168.0.36:8082/',
// baseUrl: 'http://192.168.0.168:8082/', baseUrl: 'http://192.168.0.36:8082/',
wsUrl: 'ws://218.76.0.69:7860/', wsUrl: 'ws://218.76.0.69:7860/',
projectName: '灵境大模型平台' projectName: '灵境大模型平台'
} }
...@@ -101,9 +101,8 @@ class GetStreaming { ...@@ -101,9 +101,8 @@ class GetStreaming {
} catch { } catch {
console.error('onmessage error'); console.error('onmessage error');
} }
that.onmessage(data) that.onmessage(JSON.stringify(data))
console.info(data); if (data?.status === 0) {
if (data.status === 0) {
that.success() that.success()
} }
}, },
......
...@@ -15,6 +15,7 @@ class SocketService { ...@@ -15,6 +15,7 @@ class SocketService {
} }
// 初始化weosocket // 初始化weosocket
async initWebSocket () { async initWebSocket () {
console.log(1111123123123123);
this.ws = await new WebSocket(this.url); this.ws = await new WebSocket(this.url);
this.ws.onopen = await this.websocketonopen.bind(this); this.ws.onopen = await this.websocketonopen.bind(this);
this.ws.onerror = await this.websocketonerror.bind(this); this.ws.onerror = await this.websocketonerror.bind(this);
...@@ -63,6 +64,9 @@ class SocketService { ...@@ -63,6 +64,9 @@ class SocketService {
websocketclose (e) { // 关闭 websocketclose (e) { // 关闭
// Message('connection closed (' + e.code + ')') // Message('connection closed (' + e.code + ')')
} }
close () {
this.ws.close();
}
} }
export { SocketService } export { SocketService }
...@@ -31,10 +31,10 @@ import { DatasetData } from '@/api/gptController.js' ...@@ -31,10 +31,10 @@ import { DatasetData } from '@/api/gptController.js'
export default { export default {
data() { data() {
return { return {
form: JSON.parse(JSON.stringify(this.row)) form: this.deepCopy(this.row)
} }
}, },
props: ['row', 'columnList', 'refresh', 'isEdit'], props: ['row', 'columnList', 'refresh', 'isEdit', 'versionId'],
components: {}, components: {},
computed: {}, computed: {},
...@@ -42,6 +42,13 @@ export default { ...@@ -42,6 +42,13 @@ export default {
mounted() {}, mounted() {},
methods: { methods: {
deepCopy(data) {
try {
return JSON.parse(JSON.stringify(data))
} catch (error) {
return { data: { instruction: '', output: '' } }
}
},
onCancel(isSuccess) { onCancel(isSuccess) {
if (this.observer != null) { if (this.observer != null) {
this.observer.cancel(isSuccess) this.observer.cancel(isSuccess)
...@@ -50,9 +57,10 @@ export default { ...@@ -50,9 +57,10 @@ export default {
onSubmit() { onSubmit() {
let params = {} let params = {}
params.datasetMongoDto = this.form params.datasetMongoDto = this.form
DatasetData.update(this, params) params.datasetMongoDto.versionId = this.versionId
DatasetData[this.versionId ? 'add' : 'update'](this, params)
.then((res) => { .then((res) => {
this.$message.success('编辑成功') this.$message.success(this.versionId ? '添加成功' : '编辑成功')
this.onCancel(true) this.onCancel(true)
}) })
.catch((e) => {}) .catch((e) => {})
......
...@@ -2,17 +2,20 @@ ...@@ -2,17 +2,20 @@
<template> <template>
<div class="tableBox"> <div class="tableBox">
<el-breadcrumb separator="|"> <div class="topBox">
<el-breadcrumb-item :class="nowPage==0?'isactive':''" @click.native="breadcrumbClick(0)">全部({{ allNum}}</el-breadcrumb-item> <el-breadcrumb separator="|">
<el-breadcrumb-item :class="nowPage==1?'isactive':''" @click.native="breadcrumbClick(1)">无标注信息({{ unmarkedNum}}</el-breadcrumb-item> <el-breadcrumb-item :class="nowPage==0?'isactive':''" @click.native="breadcrumbClick(0)">全部({{ allNum}}</el-breadcrumb-item>
<el-breadcrumb-item :class="nowPage==2?'isactive':''" @click.native="breadcrumbClick(2)">有标注信息({{ markedNum}}</el-breadcrumb-item> <el-breadcrumb-item :class="nowPage==1?'isactive':''" @click.native="breadcrumbClick(1)">无标注信息({{ unmarkedNum}}</el-breadcrumb-item>
</el-breadcrumb> <el-breadcrumb-item :class="nowPage==2?'isactive':''" @click.native="breadcrumbClick(2)">有标注信息({{ markedNum}}</el-breadcrumb-item>
</el-breadcrumb>
<el-button :size="defaultFormItemSize" @click="add()">新增</el-button>
</div>
<vxe-table border show-header-overflow show-overflow :row-config="{ isHover: true }" :data="myDataSetPage.tableData.impl.dataList" min-height="96"> <vxe-table border show-header-overflow show-overflow :row-config="{ isHover: true }" :data="myDataSetPage.tableData.impl.dataList" min-height="96">
<!-- <vxe-column field="index" title="序号"></vxe-column> --> <!-- <vxe-column field="index" title="序号"></vxe-column> -->
<!-- <vxe-column :field="'data.'+item" :title="item" v-for="item in columnList" :key="item"></vxe-column> --> <!-- <vxe-column :field="'data.'+item" :title="item" v-for="item in columnList" :key="item"></vxe-column> -->
<vxe-column field="data.instruction" title="问题"></vxe-column> <vxe-column field="data.instruction" title="问题"></vxe-column>
<vxe-column field="data.output" title="回答"></vxe-column> <vxe-column field="data.output" title="回答"></vxe-column>
<vxe-column field="operation" title="操作" width="150px"> <vxe-column field="operation" title="操作" width="150px">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button type="text" :size="defaultFormItemSize" @click="check(scope.row)">查看</el-button> <el-button type="text" :size="defaultFormItemSize" @click="check(scope.row)">查看</el-button>
...@@ -150,9 +153,28 @@ export default { ...@@ -150,9 +153,28 @@ export default {
) )
.then((res) => { .then((res) => {
this.refresh() this.refresh()
this.summaryCount()
}) })
.catch((e) => {}) .catch((e) => {})
}, },
add() {
// 添加
this.$dialog
.show(
'添加',
label,
{
area: ['70%', '50%']
},
{ versionId: this.versionItem.versionId, refresh: this.refresh, isEdit: true }
)
.then((res) => {
this.refresh()
this.summaryCount()
})
.catch((e) => {})
},
del(item) { del(item) {
this.$confirm('是否确认删除', '提示', { this.$confirm('是否确认删除', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
...@@ -164,6 +186,7 @@ export default { ...@@ -164,6 +186,7 @@ export default {
.then((res) => { .then((res) => {
this.$message.success('删除成功') this.$message.success('删除成功')
this.refresh() this.refresh()
this.summaryCount()
}) })
.catch((e) => { .catch((e) => {
console.log(e) console.log(e)
...@@ -282,4 +305,10 @@ export default { ...@@ -282,4 +305,10 @@ export default {
/deep/ .isactive .el-breadcrumb__inner { /deep/ .isactive .el-breadcrumb__inner {
color: #0092ff !important; color: #0092ff !important;
} }
.topBox {
display: flex;
height: auto;
align-items: center;
justify-content: space-between;
}
</style> </style>
<!--详情 --> <!--详情 -->
<template> <template>
<div class="tableBox"> <div class="tableBox">
<el-breadcrumb separator="|"> <el-breadcrumb separator="|">
<el-breadcrumb-item :class="nowPage==0?'isactive':''" @click.native="breadcrumbClick(0)">全部({{ allNum}}</el-breadcrumb-item> <el-breadcrumb-item :class="nowPage==0?'isactive':''" @click.native="breadcrumbClick(0)">全部({{ allNum}}</el-breadcrumb-item>
...@@ -150,6 +149,7 @@ export default { ...@@ -150,6 +149,7 @@ export default {
) )
.then((res) => { .then((res) => {
this.refresh() this.refresh()
this.summaryCount()
}) })
.catch((e) => {}) .catch((e) => {})
}, },
...@@ -164,6 +164,7 @@ export default { ...@@ -164,6 +164,7 @@ export default {
.then((res) => { .then((res) => {
this.$message.success('删除成功') this.$message.success('删除成功')
this.refresh() this.refresh()
this.summaryCount()
}) })
.catch((e) => { .catch((e) => {
console.log(e) console.log(e)
......
...@@ -7,15 +7,15 @@ ...@@ -7,15 +7,15 @@
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import Clipboard from 'clipboard'; import Clipboard from 'clipboard'
import { TuningRun } from '@/api/gptController.js'; import { TuningRun } from '@/api/gptController.js'
// import { getSessionHash } from '@/utils/index'; // import { getSessionHash } from '@/utils/index';
export default { export default {
data () { data() {
return { return {
clipboard: null, clipboard: null,
result: '', result: '',
...@@ -26,59 +26,62 @@ export default { ...@@ -26,59 +26,62 @@ export default {
fn_index: 18, fn_index: 18,
session_hash: this.item.runId session_hash: this.item.runId
} }
}; }
}, },
components: {}, components: {},
computed: { computed: {
resultAdjust () { resultAdjust() {
return this.result.replace(/\n/g, '<br/>').replace('```bash', '') return this.result.replace(/\n/g, '<br/>').replace('```bash', '')
} }
}, },
props: ['item'], props: ['item'],
mounted () { mounted() {
this.SocketService.initWebSocket() this.SocketService.initWebSocket()
this.clipboard = new Clipboard(this.$refs.copy.$el); this.clipboard = new Clipboard(this.$refs.copy.$el)
}, },
methods: { methods: {
successful() {
successful () { // 连接成功 // 连接成功
this.send(`{"fn_index":${this.wsData.fn_index},"session_hash":"${this.wsData.session_hash}"}`) this.send(`{"fn_index":${this.wsData.fn_index},"session_hash":"${this.wsData.session_hash}"}`)
this.getPreviewCommand() this.getPreviewCommand()
}, },
getPreviewCommand () { // 获取参数 getPreviewCommand() {
TuningRun.getPreviewCommand(this, {runId: this.item.runId}).then((res) => { // 获取参数
TuningRun.getPreviewCommand(this, { runId: this.item.runId }).then((res) => {
this.wsData.data = res.data this.wsData.data = res.data
this.send(JSON.stringify(this.wsData)) this.send(JSON.stringify(this.wsData))
}) })
}, },
send (data) { // 发送参数 send(data) {
// 发送参数
this.SocketService.websocketsend(data) this.SocketService.websocketsend(data)
}, },
websocketonmessage (e) { // 返回接收参数 websocketonmessage(e) {
// 返回接收参数
console.log(e)
if (JSON.parse(e.data).msg === 'process_generating') { if (JSON.parse(e.data).msg === 'process_generating') {
this.result = JSON.parse(e.data).output.data[0] this.result = JSON.parse(e.data).output.data[0]
} }
}, },
copy () { copy() {
try { try {
this.clipboard.on('success', e => { this.clipboard.on('success', (e) => {
this.$message.success('接入信息复制成功!'); this.$message.success('接入信息复制成功!')
this.clipboard = null this.clipboard = null
}); })
this.clipboard.on('error', e => { this.clipboard.on('error', (e) => {
this.$message.error('浏览器不支持复制'); this.$message.error('浏览器不支持复制')
this.clipboard = null this.clipboard = null
}); })
} catch (e) { } catch (e) {
console.log(e); console.log(e)
} }
} }
} }
} }
</script> </script>
<style scoped> <style scoped>
</style> </style>
<!-- 任务列表操作 --> <!-- 任务列表操作 -->
<template> <template>
<div class="tableBox">
<div class="tableBox"> <el-button :size="defaultFormItemSize" type="primary" @click="preview">预览命令</el-button>
<el-button :size="defaultFormItemSize" type="primary" @click="preview">预览命令</el-button> <el-button :size="defaultFormItemSize" type="primary" @click="start" :disabled="istraining">开始训练</el-button>
<el-button :size="defaultFormItemSize" type="primary" @click="start" :disabled="istraining" >开始训练</el-button> <el-button :size="defaultFormItemSize" type="primary" @click="pause" :disabled="!istraining">中断训练</el-button>
<el-button :size="defaultFormItemSize" type="primary" @click="pause" :disabled="!istraining">中断训练</el-button> <el-tabs v-model="activeName" :size="defaultFormItemSize">
<el-tabs v-model="activeName" :size="defaultFormItemSize"> <el-tab-pane label="运行详情" name="particulars">
<el-tab-pane label="运行详情" name="particulars"><particulars :item="item" /></el-tab-pane> <particulars :item="item" />
<el-tab-pane label="评估报告" name="assessmentReport"><assessmentReport ref="assessmentReport" :item="item" :result="result" :img="img" /></el-tab-pane> </el-tab-pane>
<el-tab-pane label="训练日志" name="trainingLog"><trainingLog :item="item" :result="result" /></el-tab-pane> <el-tab-pane label="评估报告" name="assessmentReport">
</el-tabs> <assessmentReport ref="assessmentReport" :item="item" :result="result" :img="img" />
</div> </el-tab-pane>
<el-tab-pane label="训练日志" name="trainingLog">
<trainingLog :item="item" :result="result" />
</el-tab-pane>
</el-tabs>
</div>
</template> </template>
<script> <script>
import particulars from './operate/particulars'; import particulars from './operate/particulars'
import assessmentReport from './operate/assessmentReport'; import assessmentReport from './operate/assessmentReport'
import trainingLog from './operate/trainingLog'; import trainingLog from './operate/trainingLog'
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
import previewCommand from './previewCommand'; import previewCommand from './previewCommand'
// import { getSessionHash } from '@/utils/index'; // import { getSessionHash } from '@/utils/index';
import { TuningRun, PyApi } from '@/api/gptController.js'; import { TuningRun, PyApi } from '@/api/gptController.js'
export default { export default {
data () { data() {
return { return {
istraining: false, // 是否在训练中 istraining: false, // 是否在训练中
img: '', img: '',
...@@ -36,34 +41,32 @@ export default { ...@@ -36,34 +41,32 @@ export default {
}, },
activeName: this.page, activeName: this.page,
timeImg: null timeImg: null
}; }
}, },
props: ['page', 'item'], props: ['page', 'item'],
components: {particulars, assessmentReport, trainingLog}, components: { particulars, assessmentReport, trainingLog },
computed: {}, computed: {},
mounted () { mounted() {},
},
methods: { methods: {
PyApi(index, data = []) {
PyApi (index, data = []) {
let param = { let param = {
data: data, data: data,
event_data: null, event_data: null,
fn_index: index, fn_index: index,
session_hash: this.item.runId session_hash: this.item.runId
} }
return PyApi.predict(this, param).then((res) => { return PyApi.predict(this, param).then((res) => {
if (index === 22) { // 图片 if (index === 22) {
// 图片
// console.log(res); // console.log(res);
this.img = JSON.parse(res.data).data[0]?.plot; this.img = JSON.parse(res.data).data[0]?.plot
console.log(this.img); console.log(this.img)
} else if (index === 20) { // 暂停 } else if (index === 20) {
// 暂停
this.$message({ this.$message({
message: '已暂停', message: '已暂停',
type: 'success' type: 'success'
...@@ -72,62 +75,76 @@ export default { ...@@ -72,62 +75,76 @@ export default {
// this.result = {output: {data: []}} // this.result = {output: {data: []}}
}) })
}, },
preview () { preview() {
this.$dialog.show('预览命令', previewCommand, { this.$dialog
area: ['50%', '70%'] .show(
}, {item: this.item}).then(res => { '预览命令',
this.refresh(); previewCommand,
}).catch(e => { }); {
area: ['50%', '70%']
},
{ item: this.item }
)
.then((res) => {
this.refresh()
})
.catch((e) => {})
}, },
start () { start() {
this.SocketService.initWebSocket() this.SocketService.initWebSocket()
}, },
async pause () { async pause() {
await this.PyApi(20) await this.PyApi(20)
TuningRun.updateById(this, {tuningRunDto: {runId: this.item.runId, runStatus: -2}}).then(res => { TuningRun.updateById(this, { tuningRunDto: { runId: this.item.runId, runStatus: -2 } })
console.log(res); .then((res) => {
}).catch(e => { console.log(res)
})
}); .catch((e) => {})
}, },
getPreviewCommand () { // 获取参数 getPreviewCommand() {
TuningRun.getPreviewCommand(this, {runId: this.item.runId}).then((res) => { // 获取参数
TuningRun.getPreviewCommand(this, { runId: this.item.runId }).then((res) => {
this.wsData.data = res.data this.wsData.data = res.data
this.send(JSON.stringify(this.wsData)) this.send(JSON.stringify(this.wsData))
}) })
}, },
successful () { // 连接成功 successful() {
// 连接成功
this.send(`{"fn_index":${this.wsData.fn_index},"session_hash":"${this.wsData.session_hash}"}`) this.send(`{"fn_index":${this.wsData.fn_index},"session_hash":"${this.wsData.session_hash}"}`)
// this.getPreviewCommand() // this.getPreviewCommand()
}, },
send (data) { // 发送参数 send(data) {
// 发送参数
this.SocketService.websocketsend(data) this.SocketService.websocketsend(data)
}, },
websocketonmessage (e) { // 返回接收参数 websocketonmessage(e) {
if (JSON.parse(e.data).msg === 'process_generating') { // 开始训练 // 返回接收参数
if (JSON.parse(e.data).msg === 'process_generating') {
// 开始训练
this.istraining = true this.istraining = true
this.result = JSON.parse(e.data) this.result = JSON.parse(e.data)
if (!this.timeImg) { if (!this.timeImg) {
// this.startGetImg() // this.startGetImg()
} }
} else if (JSON.parse(e.data).msg === 'process_completed') { // 训练结束 } else if (JSON.parse(e.data).msg === 'process_completed') {
// 训练结束
this.$refs.assessmentReport.completed() this.$refs.assessmentReport.completed()
clearInterval(this.timeImg) clearInterval(this.timeImg)
this.timeImg = null this.timeImg = null
this.istraining = false this.istraining = false
this.$refs.assessmentReport.init(true) this.$refs.assessmentReport.init(true)
} else if (JSON.parse(e.data).msg === 'send_data') { // 可以发送训练数据 } else if (JSON.parse(e.data).msg === 'send_data') {
// 可以发送训练数据
this.getPreviewCommand() this.getPreviewCommand()
} }
}, },
startGetImg () { startGetImg() {
this.timeImg = setInterval(() => { this.timeImg = setInterval(() => {
this.PyApi(22, [this.wsData.data[1], this.wsData.data[3], this.wsData.data[37]]) this.PyApi(22, [this.wsData.data[1], this.wsData.data[3], this.wsData.data[37]])
}, 10000); }, 10000)
} }
} }
} }
</script> </script>
<style scoped> <style scoped>
</style> </style>
...@@ -64,6 +64,7 @@ export default { ...@@ -64,6 +64,7 @@ export default {
this.getDataList() this.getDataList()
if (this.isCopy) { if (this.isCopy) {
this.form.modelEstimateDto = { ...this.item } this.form.modelEstimateDto = { ...this.item }
this.form.modelEstimateDto.datasetVersionIds = this.item.datasetVersionIds
} else if (this.modelVersionId) { } else if (this.modelVersionId) {
this.form.modelEstimateDto.modelVersionId = this.modelVersionId this.form.modelEstimateDto.modelVersionId = this.modelVersionId
} }
......
<!-- 答案内容预览 --> <!-- 答案内容预览 -->
<template> <template>
<vue-markdown :source="content" <vue-markdown :source="content" v-highlight class="markdown-body">
v-highlight
class="markdown-body">
</vue-markdown> </vue-markdown>
</template> </template>
<script> <script>
import 'vis-network/dist/dist/vis-network.css'; import 'vis-network/dist/dist/vis-network.css'
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
import { Network } from 'vis-network/dist/vis-network.esm.js'; import { Network } from 'vis-network/dist/vis-network.esm.js'
import hljs from 'highlight.js' // 代码块高亮 import hljs from 'highlight.js' // 代码块高亮
// import 'highlight.js/styles/github.css' // 代码块高亮样式 // import 'highlight.js/styles/github.css' // 代码块高亮样式
...@@ -17,11 +15,10 @@ import './github-markdown.css' // 整体 markdown 样式 ...@@ -17,11 +15,10 @@ import './github-markdown.css' // 整体 markdown 样式
import VueMarkdown from 'vue-markdown' import VueMarkdown from 'vue-markdown'
import filePreview from './filePreview' import filePreview from './filePreview'
export default { export default {
data () { data() {
return { return {
result: undefined result: undefined
}
};
}, },
props: ['content'], props: ['content'],
components: { VueMarkdown }, components: { VueMarkdown },
...@@ -32,30 +29,26 @@ export default { ...@@ -32,30 +29,26 @@ export default {
highlight: { highlight: {
// 指令的定义 // 指令的定义
inserted: function (el) { inserted: function (el) {
let blocks = el.querySelectorAll('pre code'); let blocks = el.querySelectorAll('pre code')
blocks.forEach((block, index) => { blocks.forEach((block, index) => {
/** 代码高亮 */ /** 代码高亮 */
hljs.highlightBlock(block); hljs.highlightBlock(block)
/** 手动添加一个hljs类名,防止不支持的语言背景变空白 */ /** 手动添加一个hljs类名,防止不支持的语言背景变空白 */
block.classList.add('hljs'); block.classList.add('hljs')
}) })
} }
} }
}, },
mounted () { mounted() {},
watch: {},
},
watch: {
},
methods: { methods: {
isSuccess () { isSuccess() {
this.$nextTick(() => { this.$nextTick(() => {
const anchorTags = Object.values(this.$el.getElementsByTagName('a')); const anchorTags = Object.values(this.$el.getElementsByTagName('a'))
this.preview(anchorTags) this.preview(anchorTags)
}) })
}, },
preview (anchorTags) { preview(anchorTags) {
let that = this let that = this
// 遍历并输出链接的 href 属性 // 遍历并输出链接的 href 属性
...@@ -63,54 +56,97 @@ export default { ...@@ -63,54 +56,97 @@ export default {
let tagUrl = aTag.getAttribute('href') || '' 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 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 let isFile2 =
if (isFile2 || aTag.className === 'show_detail') { // 判断知识库以及基于文件问答 的文件类型,并添加dom以及样式 || 添加特殊a标签展示详情内容 [
'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.className === 'show_detail') {
// 判断知识库以及基于文件问答 的文件类型,并添加dom以及样式 || 添加特殊a标签展示详情内容
this.setDescribeStyle(aTag) this.setDescribeStyle(aTag)
} }
aTag.addEventListener('click', function (event) { aTag.addEventListener('click', function (event) {
if (isFile) { // 判断可预览文件类型 if (isFile) {
// 判断可预览文件类型
// 阻止默认点击事件 // 阻止默认点击事件
event.preventDefault(); event.preventDefault()
that.$dialog.show('文件预览', filePreview, { that.$dialog
area: ['100%', '100%'] .show(
}, { url: tagUrl }).then(res => { '文件预览',
filePreview,
}).catch(e => { }); {
area: ['100%', '100%']
},
{ url: tagUrl }
)
.then((res) => {})
.catch((e) => {})
} }
}); })
}); })
}, },
setDescribeStyle (aTag) { setDescribeStyle(aTag) {
// let describeDom = aTag.nextElementSibling // let describeDom = aTag.nextElementSibling
// 在当前元素前插入新的 HTML 内容 // 在当前元素前插入新的 HTML 内容
aTag.insertAdjacentHTML('afterend', ` aTag.insertAdjacentHTML(
'afterend',
`
<button style="margin-top:10px" type="button" class="el-button el-button--primary el-button--mini is-round"> <button style="margin-top:10px" type="button" class="el-button el-button--primary el-button--mini is-round">
<span style="margin-right:5px">详情</span> <span style="margin-right:5px">详情</span>
<i class="el-icon-arrow-down"></i> <i class="el-icon-arrow-down"></i>
</button> </button>
`); `
)
var buttonDom = aTag.nextElementSibling;// 下拉按钮 var buttonDom = aTag.nextElementSibling // 下拉按钮
let describeDom = aTag.parentNode.querySelector('.describe-view') || aTag.parentNode.parentNode.querySelector('.describe-view')// 详情 let describeDom = aTag.parentNode.querySelector('.describe-view') || aTag.parentNode.parentNode.querySelector('.describe-view') // 详情
this.initNetwork(describeDom, describeDom.getAttribute('data')) this.initNetwork(describeDom, describeDom.getAttribute('data'))
let height = describeDom.scrollHeight let height = describeDom.scrollHeight
describeDom.setAttribute('style', 'height:0px;') describeDom.setAttribute('style', 'height:0px;')
buttonDom.addEventListener('click', function (event) { buttonDom.addEventListener('click', function (event) {
if (height > 0 && (describeDom.style.height !== '0px' && describeDom.style.height !== '')) { if (height > 0 && describeDom.style.height !== '0px' && describeDom.style.height !== '') {
describeDom.setAttribute('style', 'height:0px;') describeDom.setAttribute('style', 'height:0px;')
} else { } else {
describeDom.setAttribute('style', `height:${height}px;`) describeDom.setAttribute('style', `height:${height}px;`)
} }
}) })
}, },
initNetwork (target, data) { initNetwork(target, data) {
// 判断有没有data属性 // 判断有没有data属性
if (target.hasAttribute('data') && target.getAttribute('data') !== null) { if (target.hasAttribute('data') && target.getAttribute('data') !== null) {
const container = document.createElement('div'); const container = document.createElement('div')
container.style.width = '100%' container.style.width = '100%'
container.style.border = '1px solid lightgray' container.style.border = '1px solid lightgray'
container.style.height = '400px' container.style.height = '400px'
container.style.position = 'relative'; container.style.position = 'relative'
container.style.borderRadius = '10px' container.style.borderRadius = '10px'
container.style.marginBottom = '10px' container.style.marginBottom = '10px'
container.style.zIndex = '10000' container.style.zIndex = '10000'
...@@ -126,7 +162,6 @@ export default { ...@@ -126,7 +162,6 @@ export default {
widthConstraint: 100, // 设置数字,将节点的最小和最大宽度设为该值,当值设为很小的时候,label会换行,节点会保持一个最小值,里边的内容会换行 widthConstraint: 100, // 设置数字,将节点的最小和最大宽度设为该值,当值设为很小的时候,label会换行,节点会保持一个最小值,里边的内容会换行
color: { color: {
background: '#0092FF' background: '#0092FF'
}, },
font: { font: {
color: '#7a7a7a' // 修改节点内文字颜色为黑色 color: '#7a7a7a' // 修改节点内文字颜色为黑色
...@@ -150,12 +185,11 @@ export default { ...@@ -150,12 +185,11 @@ export default {
barnesHut: { barnesHut: {
gravitationalConstant: -2000 gravitationalConstant: -2000
} }
} }
}; }
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
const network = new Network(container, data, options); const network = new Network(container, data, options)
target.appendChild(container); target.appendChild(container)
container.setAttribute('isfull', '0') container.setAttribute('isfull', '0')
let fullDom = document.createElement('div') let fullDom = document.createElement('div')
fullDom.classList.add('el-icon-full-screen', 'full') fullDom.classList.add('el-icon-full-screen', 'full')
...@@ -163,8 +197,8 @@ export default { ...@@ -163,8 +197,8 @@ export default {
container.appendChild(fullDom) container.appendChild(fullDom)
fullDom.addEventListener('click', () => { fullDom.addEventListener('click', () => {
if (container.getAttribute('isfull') !== '0') { if (container.getAttribute('isfull') !== '0') {
container.style.height = '400px'; container.style.height = '400px'
container.style.position = 'relative'; container.style.position = 'relative'
container.style.background = 'none' container.style.background = 'none'
container.setAttribute('isfull', '0') container.setAttribute('isfull', '0')
container.style.border = '1px solid lightgray' container.style.border = '1px solid lightgray'
...@@ -178,10 +212,10 @@ export default { ...@@ -178,10 +212,10 @@ export default {
fullDom.classList.remove('el-icon-full-screen') fullDom.classList.remove('el-icon-full-screen')
fullDom.classList.add('el-icon-close') fullDom.classList.add('el-icon-close')
container.style.height = '100%'; container.style.height = '100%'
container.style.position = 'fixed'; container.style.position = 'fixed'
container.style.top = 0; container.style.top = 0
container.style.left = 0; container.style.left = 0
container.style.border = 'none' container.style.border = 'none'
container.style.background = '#00000096' container.style.background = '#00000096'
container.setAttribute('isfull', '1') container.setAttribute('isfull', '1')
...@@ -196,28 +230,26 @@ export default { ...@@ -196,28 +230,26 @@ export default {
container.appendChild(downDom) container.appendChild(downDom)
} }
}, },
downloadCanvas (canvas) { downloadCanvas(canvas) {
// 获取 Canvas 的内容作为DataURL // 获取 Canvas 的内容作为DataURL
var dataURL = canvas.toDataURL('image/png'); var dataURL = canvas.toDataURL('image/png')
// 创建一个下载链接 // 创建一个下载链接
var downloadLink = document.createElement('a'); var downloadLink = document.createElement('a')
downloadLink.href = dataURL; downloadLink.href = dataURL
downloadLink.download = 'Image.png'; // 设置下载文件的名称 downloadLink.download = 'Image.png' // 设置下载文件的名称
// 将下载链接添加到页面 // 将下载链接添加到页面
document.body.appendChild(downloadLink); document.body.appendChild(downloadLink)
// 模拟点击下载链接 // 模拟点击下载链接
downloadLink.click(); downloadLink.click()
// 移除下载链接 // 移除下载链接
document.body.removeChild(downloadLink); document.body.removeChild(downloadLink)
} }
} }
} }
</script> </script>
<style scoped> <style scoped>
.markdown-body { .markdown-body {
......
...@@ -146,48 +146,51 @@ export default { ...@@ -146,48 +146,51 @@ export default {
}, },
onmessage(data) { onmessage(data) {
console.log(data) let nowChat = this.myHistory[this.myHistory.length - 1]
// let nowChat = this.myHistory[this.myHistory.length - 1] if (this.chatForm.pattern === 0) {
// if (this.chatForm.pattern === 0) { let temporary = JSON.parse(`[${data}]`.replace(/}{/g, '},{'))
// // 通用智能问答 // 通用智能问答
// // data = data.replace(/^data:\s+|\s+$/g, '') // data = data.replace(/^data:\s+|\s+$/g, '')
// nowChat.excludeReferenceAnswer += data // nowChat.excludeReferenceAnswer += data.answer
// nowChat.answer += data // nowChat.answer += data.answer
// } else if (this.chatForm.pattern === 1) { temporary.forEach((item) => {
// // 专业知识库问答 this.modifyContent(item) // 修改返回内容
// // console.log(data) nowChat.excludeReferenceAnswer += item.answer || '' // 排除回答中的引用内容
// let temporary = JSON.parse(`[${data}]`.replace(/}{/g, '},{')) nowChat.answer += item.answer || '\n' + (item.docs || '')
// temporary.forEach((item) => { })
// this.modifyContent(item) // 修改返回内容 } else if (this.chatForm.pattern === 1) {
// nowChat.excludeReferenceAnswer += item.answer || '' // 排除回答中的引用内容 // 专业知识库问答
// nowChat.answer += item.answer || '\n' + item.docs // console.log(data)
// }) let temporary = JSON.parse(`[${data}]`.replace(/}{/g, '},{'))
// } else if (this.chatForm.pattern === 2) { temporary.forEach((item) => {
// // 搜索引擎问答 this.modifyContent(item) // 修改返回内容
// } else if (this.chatForm.pattern === 3) { nowChat.excludeReferenceAnswer += item.answer || '' // 排除回答中的引用内容
// // 基于文件问答 nowChat.answer += item.answer || '\n' + (item.docs || '')
// let temporary = JSON.parse(`[${data}]`.replace(/}{/g, '},{')) })
} else if (this.chatForm.pattern === 2) {
// temporary.forEach((item) => { // 搜索引擎问答
// this.modifyContent(item) // 修改返回内容 } else if (this.chatForm.pattern === 3) {
// nowChat.excludeReferenceAnswer += item.answer || '' // 排除回答中的引用内容 // 基于文件问答
// nowChat.answer += item.answer || '\n' + item.docs let temporary = JSON.parse(`[${data}]`.replace(/}{/g, '},{'))
// })
// } else if (this.chatForm.pattern === 4) {
// let temporary = JSON.parse(`[${data}]`.replace(/}{/g, '},{'))
// temporary.forEach((item) => { temporary.forEach((item) => {
// console.log(item) this.modifyContent(item) // 修改返回内容
// this.modifyContent(item) // 修改返回内容 nowChat.excludeReferenceAnswer += item.answer || '' // 排除回答中的引用内容
// nowChat.excludeReferenceAnswer += item.answer || '' // 排除回答中的引用内容 nowChat.answer += item.answer || '\n' + (item.docs || '')
// nowChat.answer += item.answer || '\n' + item.docs.join() })
// // nowChat.answer += item.answer += '\n' + item.docs.join() } else if (this.chatForm.pattern === 4) {
// }) let temporary = JSON.parse(`[${data}]`.replace(/}{/g, '},{'))
// } temporary.forEach((item) => {
this.modifyContent(item) // 修改返回内容
nowChat.excludeReferenceAnswer += item.answer || '' // 排除回答中的引用内容
nowChat.answer += item.answer || '\n' + (item.docs.join() || '')
// nowChat.answer += item.answer += '\n' + item.docs.join()
})
}
// this.$nextTick(() => { this.$nextTick(() => {
// this.$refs.contentBox.scrollTo(0, this.$refs.contentBox.scrollHeight) this.$refs.contentBox.scrollTo(0, this.$refs.contentBox.scrollHeight)
// }) })
}, },
modifyContent(item) { modifyContent(item) {
// 修改返回内容 // 修改返回内容
......
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