Commit e4cff086 authored by mhw's avatar mhw

文件对话添加

parent 43074339
...@@ -65,17 +65,17 @@ const TemplateFrameworkDict = new DictionaryBase('模板框架', [ ...@@ -65,17 +65,17 @@ const TemplateFrameworkDict = new DictionaryBase('模板框架', [
}, },
{ {
id: 1, id: 1,
name: 'Basic Prompt Framework', name: '基本提示框架',
symbol: 'Basic Prompt Framework' symbol: 'Basic Prompt Framework'
}, },
{ {
id: 2, id: 2,
name: 'CRISPE Prompt Framework', name: 'CRISPE提示框架',
symbol: 'CRISPE Prompt Framework' symbol: 'CRISPE Prompt Framework'
}, },
{ {
id: 3, id: 3,
name: 'Few-shot Prompt', name: '少样本提示',
symbol: 'Few-shot Prompt' symbol: 'Few-shot Prompt'
} }
]); ]);
...@@ -409,6 +409,11 @@ const ModeOfSpeaking = new DictionaryBase('对话模式', [ ...@@ -409,6 +409,11 @@ const ModeOfSpeaking = new DictionaryBase('对话模式', [
id: 1, id: 1,
name: '知识库问答', name: '知识库问答',
symbol: 'repository' symbol: 'repository'
},
{
id: 3,
name: '文件对话',
symbol: 'fileSession'
} }
// { // {
// id: 2, // id: 2,
......
<!--左侧操作界面 --> <!--左侧操作界面 -->
<template> <template>
<el-form label-position="left" ref="form" label-width="120px" :model="form" :size="defaultFormItemSize" style="padding:20px;width:400px"> <el-form label-position="left" ref="form" label-width="120px" :model="form" :size="defaultFormItemSize" style="padding:20px;width:400px" v-loading.fullscreen.lock="fullscreenLoading">
<el-form-item label="对话模式:"> <el-form-item label="对话模式:">
<el-select v-model="form.pattern" placeholder="请选择" > <el-select v-model="form.pattern" placeholder="请选择" @change="patternChange">
<el-option v-for="item in ModeOfSpeaking.getList()" :key="item.id" :label="item.name" :value="item.name"> <el-option v-for="item in ModeOfSpeaking.getList()" :key="item.id" :label="item.name" :value="item.name">
</el-option> </el-option>
</el-select> </el-select>
...@@ -66,7 +66,28 @@ ...@@ -66,7 +66,28 @@
</el-collapse-item> </el-collapse-item>
</el-collapse> </el-collapse>
</el-form-item> </el-form-item>
<el-form-item label-width="0px" v-if="form.pattern == '文件对话'">
<el-collapse value="1">
<el-collapse-item name="1">
<template slot="title">文件配置</template>
<el-form-item label="上传文件:" style="margin-bottom:30px">
<el-button @click="clickUp" :size="defaultFormItemSize" type="primary">选择文件</el-button>
<input style="display:none" ref="upFile" type="file" @change="fileinfo($event.target.files)">
<div class="itemFile" v-for="(item,index) in files" :key="item.name">{{ item.name }}
<i class="el-icon-circle-close" style="color:#0092FF;cursor: pointer;" @click="clearFile(index)"></i>
</div>
<el-button style="display:block;margin-top:10px" :size="defaultFormItemSize" type="primary" @click="uploadFiles" :disabled="files.length===0" >上传</el-button>
</el-form-item>
<el-form-item label="匹配知识条数:" style="margin-bottom:30px">
<el-input-number v-model="form.fileConfige.top_k" :min="1" :max="20"></el-input-number>
</el-form-item>
<el-form-item label="知识匹配分数阈值:">
<el-slider v-model="fileThreshold" :format-tooltip="formatTooltip" @change="form.fileConfige.score_threshold = fileThreshold / 100"></el-slider>
</el-form-item>
</el-collapse-item>
</el-collapse>
</el-form-item>
</el-form> </el-form>
</template> </template>
...@@ -76,6 +97,8 @@ import promptWordTemplate from '../promptWordTemplate'; ...@@ -76,6 +97,8 @@ import promptWordTemplate from '../promptWordTemplate';
export default { export default {
data () { data () {
return { return {
files: [],
fullscreenLoading: false,
isPromptTemplate: true, isPromptTemplate: true,
promptTemplate: '', promptTemplate: '',
templateControllerList: [], templateControllerList: [],
...@@ -85,7 +108,7 @@ export default { ...@@ -85,7 +108,7 @@ export default {
temperature: 70, temperature: 70,
knowledgeList: [], knowledgeList: [],
knowledgeScoreThreshold: 50, knowledgeScoreThreshold: 50,
fileThreshold: 50,
form: { form: {
pattern: 'LLM 对话', // 对话模式 pattern: 'LLM 对话', // 对话模式
model_name: undefined, // 模型名称 model_name: undefined, // 模型名称
...@@ -100,7 +123,21 @@ export default { ...@@ -100,7 +123,21 @@ export default {
searchConfige: {// 搜索引擎配置 searchConfige: {// 搜索引擎配置
search_engine_name: 'bing', search_engine_name: 'bing',
top_k: 1 top_k: 1
},
fileConfige: {
top_k: 1,
score_threshold: 0.5,
knowledge_id: undefined,
// max_tokens: 0,
prompt_name: 'default'
} }
},
filesForm: {
filesArr: undefined,
chunk_size: 250,
chunk_overlap: 50,
zh_title_enhance: false
} }
}; };
}, },
...@@ -227,7 +264,38 @@ export default { ...@@ -227,7 +264,38 @@ export default {
}, },
changePromptTemplate () { changePromptTemplate () {
this.$bus.$emit('isPromptTemplate', this.isPromptTemplate); this.$bus.$emit('isPromptTemplate', this.isPromptTemplate);
},
fileinfo (files) {
if (this.files.map((item) => item.name).indexOf(files[0].name) === -1) {
this.files.push(files[0])
this.filesForm.filesArr = this.files
} else {
console.log('重复上传');
}
},
clickUp () {
this.$refs.upFile.click()
},
clearFile (index) {
this.files.splice(index, 1)
},
uploadFiles () {
this.fullscreenLoading = true
let params = this.filesForm
this.upload('/2api/knowledge_base/upload_temp_docs', params, false).then(res => {
this.$message.success('上传成功');
this.fullscreenLoading = false;
this.form.fileConfige.knowledge_id = res.data.id
}).catch(e => {
console.log(e);
});
},
patternChange () {
// console.log(111);
// Object.assign(this.$data.form, this.$options.data().form);
} }
} }
} }
......
...@@ -104,19 +104,27 @@ export default { ...@@ -104,19 +104,27 @@ export default {
} else if (this.chatForm.pattern === '搜索引擎问答') { } else if (this.chatForm.pattern === '搜索引擎问答') {
apiUrl = '/2api/chat/search_engine_chat' apiUrl = '/2api/chat/search_engine_chat'
this.param = { ...this.param, ...this.chatForm.searchConfige } this.param = { ...this.param, ...this.chatForm.searchConfige }
} else if (this.chatForm.pattern === '文件对话') {
apiUrl = '/2api/chat/file_chat'
this.param = { ...this.param, ...this.chatForm.fileConfige }
if (!this.chatForm.fileConfige.knowledge_id) {
this.$message.error('请先上传文件');
return
}
} }
if (!this.inputContent) return if (!this.inputContent) return
this.param.query = this.inputContent; this.param.query = this.inputContent;
this.myHistory.push({ this.myHistory.push({
'role': 'user', 'role': 'user',
'content': this.inputContent, 'content': this.inputContent,
'answer': '' 'answer': '',
'excludeReferenceAnswer': ''
}) })
this.inputContent = null; this.inputContent = null;
this.myHistory.slice(0, -1).slice(-this.heistoryRotate).forEach((item) => { this.myHistory.slice(0, -1).slice(-this.heistoryRotate).forEach((item) => {
this.param.history.push(...[{ role: item.role, content: item.content }, { role: 'assistant', content: item.answer}]) this.param.history.push(...[{ role: item.role, content: item.content }, { role: 'assistant', content: item.excludeReferenceAnswer}])
}) })
this.$emit('submit') this.$emit('submit')
...@@ -126,19 +134,36 @@ export default { ...@@ -126,19 +134,36 @@ export default {
success () { success () {
this.isSuccess = true this.isSuccess = true
}, },
onmessage (data) { onmessage (data) {
let nowChat = this.myHistory[this.myHistory.length - 1] let nowChat = this.myHistory[this.myHistory.length - 1]
if (this.chatForm.pattern === 'LLM 对话') { if (this.chatForm.pattern === 'LLM 对话') {
nowChat.answer += data nowChat.answer += data
} else if (this.chatForm.pattern === '知识库问答') { } else if (this.chatForm.pattern === '知识库问答') {
console.log(data);
let temporary = JSON.parse(`[${data}]`.replace(/}{/g, '},{')) let temporary = JSON.parse(`[${data}]`.replace(/}{/g, '},{'))
console.log(temporary);
temporary.forEach((item) => { temporary.forEach((item) => {
if (item.docs) {
item.docs = item.docs.map((item2) => {
return item2.replace('出处', '知识溯源')
})
}
nowChat.excludeReferenceAnswer += item.answer || '' // 排除回答中的引用内容
nowChat.answer += item.answer || '\n' + item.docs nowChat.answer += item.answer || '\n' + item.docs
}) })
} else if (this.chatForm.pattern === '搜索引擎问答') { } else if (this.chatForm.pattern === '搜索引擎问答') {
} else if (this.chatForm.pattern === '文件对话') {
let temporary = JSON.parse(`[${data}]`.replace(/}{/g, '},{'))
temporary.forEach((item) => {
if (item.docs) {
item.docs = item.docs.map((item2) => {
return item2.replace('出处', '知识溯源')
})
}
nowChat.excludeReferenceAnswer += item.answer || '' // 排除回答中的引用内容
nowChat.answer += item.answer || '\n' + item.docs
})
} }
this.$nextTick(() => { this.$nextTick(() => {
......
...@@ -21,7 +21,9 @@ ...@@ -21,7 +21,9 @@
</el-form-item> </el-form-item>
<template v-if="form.scenarioType === 0 "> <template v-if="form.scenarioType === 0 ">
<el-form-item label="模板框架:" class="templateFramework" v-if=" !isEdit"> <el-form-item label="模板框架:" class="templateFramework" v-if=" !isEdit">
<el-radio v-model="form.templateFramework" v-for="item in TemplateFrameworkDict.getList()" :label="item.id" :size="defaultFormItemSize" :key="item.id" @input="$refs.promptInput.init()">{{ item.name }}</el-radio> <el-tooltip class="item" effect="dark" :content="item.name" placement="top" v-for="item in TemplateFrameworkDict.getList()" :label="item.id" :size="defaultFormItemSize" :key="item.id">
<el-radio v-model="form.templateFramework" @input="$refs.promptInput.init()" :label="item.id">{{ item.symbol }}</el-radio>
</el-tooltip>
</el-form-item> </el-form-item>
<el-form-item label="Prompt:" prop="templateContent"> <el-form-item label="Prompt:" prop="templateContent">
<promptInput ref="promptInput" v-model="form.templateContent" :templateFramework="form.templateFramework" :isEdit="isEdit" /> <promptInput ref="promptInput" v-model="form.templateContent" :templateFramework="form.templateFramework" :isEdit="isEdit" />
......
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