edit
This commit is contained in:
parent
f02f6a8384
commit
a708eb59b5
|
@ -25,7 +25,7 @@
|
||||||
<i class="iconfont icon-jiahao"></i>
|
<i class="iconfont icon-jiahao"></i>
|
||||||
{{ curTemplate.ex3 == 1 ? '复制并创建个人模板' : '添加提示词' }}
|
{{ curTemplate.ex3 == 1 ? '复制并创建个人模板' : '添加提示词' }}
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button type="primary" :disabled="!(childTempList.length)" @click="getCompletion">一键研读</el-button>
|
<el-button type="primary" :disabled="!(childTempList.length)" @click="getModelResult">一键研读</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!--List-->
|
<!--List-->
|
||||||
|
@ -68,7 +68,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="ai-btn" v-if="item.answer">
|
<div class="ai-btn" v-if="item.answer">
|
||||||
<el-button type="primary" link @click="againResult(index, item)">
|
<el-button type="primary" link @click="getModelResult(index, item)">
|
||||||
<i class="iconfont icon-zhongxinshiyang"></i>
|
<i class="iconfont icon-zhongxinshiyang"></i>
|
||||||
重新研读
|
重新研读
|
||||||
</el-button>
|
</el-button>
|
||||||
|
@ -207,12 +207,114 @@ const getTempResult = () => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const prompt = ref('')
|
||||||
|
|
||||||
|
// 是否重新研读
|
||||||
|
const isAgain = ref(false)
|
||||||
|
|
||||||
|
// 研读
|
||||||
|
const getModelResult = async (index, item) => {
|
||||||
|
|
||||||
|
let str = prompt.value
|
||||||
|
// 重新研读
|
||||||
|
if(index && item){
|
||||||
|
isAgain.value = true
|
||||||
|
// 清空研读结果
|
||||||
|
childTempList.value[index].answer = ''
|
||||||
|
// 设置需要打字机效果
|
||||||
|
childTempList.value[index].showTypewriter = true
|
||||||
|
// 滚动到该项的位置
|
||||||
|
if (messageElements.value[index]) {
|
||||||
|
messageElements.value[index].scrollIntoView({
|
||||||
|
behavior: 'smooth',
|
||||||
|
block: 'start',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// 设置当前模板prompt
|
||||||
|
str = str.replace('{模板标题}',item.name)
|
||||||
|
str = str.replace('{模板内容}',item.prompt)
|
||||||
|
params.prompt = str
|
||||||
|
params.template = item.prompt
|
||||||
|
// 请求数据
|
||||||
|
try {
|
||||||
|
childTempList.value[index].loading = true
|
||||||
|
const data = await requestModelData()
|
||||||
|
childTempList.value[index].answer = data.answer;
|
||||||
|
// 保存重新研读后的结果
|
||||||
|
onEditResult(data.answer, index)
|
||||||
|
} finally {
|
||||||
|
childTempList.value[index].loading = false
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// 一键研读
|
||||||
|
else{
|
||||||
|
// 清空所有模板结果
|
||||||
|
childTempList.value.forEach(item => {
|
||||||
|
if (item.answer) {
|
||||||
|
item.answer = ''
|
||||||
|
item.showTypewriter = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// 设置滚动到第一个位置
|
||||||
|
messageElements.value[0].scrollIntoView({
|
||||||
|
behavior: 'smooth',
|
||||||
|
block: 'start',
|
||||||
|
})
|
||||||
|
for (let item of childTempList.value) {
|
||||||
|
try {
|
||||||
|
item.loading = true
|
||||||
|
|
||||||
|
str = str.replace('{模板标题}',item.name)
|
||||||
|
str = str.replace('{模板内容}',item.prompt)
|
||||||
|
params.prompt = str
|
||||||
|
params.template = item.prompt
|
||||||
|
// 请求数据
|
||||||
|
const data = await requestModelData()
|
||||||
|
|
||||||
|
item.answer = data.answer
|
||||||
|
await onSaveTemp(item)
|
||||||
|
} finally {
|
||||||
|
item.loading = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置一个延迟函数 ms: 毫秒
|
||||||
|
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
|
||||||
|
// 请求大模型接口获取模板研读结果 知识库模型 or 教学大模型
|
||||||
|
const requestModelData = async () =>{
|
||||||
|
// 教学大模型
|
||||||
|
let data = null
|
||||||
|
if (curMode.value == 1) {
|
||||||
|
const res = await sendChart({
|
||||||
|
content: params.prompt,
|
||||||
|
conversationId: conversation_id.value,
|
||||||
|
stream: false
|
||||||
|
})
|
||||||
|
// 一键研读 设置一个1s 延迟 防止百度千帆请求过于频繁
|
||||||
|
if(!isAdjust.value){
|
||||||
|
await delay(1000); // 每个请求之间延迟 1 秒
|
||||||
|
}
|
||||||
|
data = res.data
|
||||||
|
}
|
||||||
|
// 知识库模型
|
||||||
|
else {
|
||||||
|
const res = await completion(params)
|
||||||
|
data = res.data
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const messageElements = ref([]); // 存储所有消息元素的引用
|
const messageElements = ref([]); // 存储所有消息元素的引用
|
||||||
|
|
||||||
|
|
||||||
// 处理页面滚动
|
// 处理页面滚动
|
||||||
const outerContainer = ref()
|
const outerContainer = ref()
|
||||||
let lastScrollTime = 0;
|
let lastScrollTime = 0;
|
||||||
|
@ -223,8 +325,6 @@ const handleScroll = (index) => {
|
||||||
const container = document.querySelector('.container-right-list');
|
const container = document.querySelector('.container-right-list');
|
||||||
if(isAgain.value){
|
if(isAgain.value){
|
||||||
scrollToTmp(index)
|
scrollToTmp(index)
|
||||||
// const item = messageElements.value[index]
|
|
||||||
// item.scrollIntoView({ behavior: 'smooth', block: 'end' })
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|
||||||
|
@ -244,38 +344,29 @@ const handleScroll = (index) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lastScrollTime = now;
|
lastScrollTime = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// const tmpViewContainer = document.querySelector('.container-right-list')
|
// 处理重新研读 滚动
|
||||||
const scrollToTmp = (index) =>{
|
const scrollToTmp = (index) =>{
|
||||||
|
// 最后一个 滚到底部
|
||||||
const now = Date.now();
|
if(index == childTempList.value.length - 1){
|
||||||
if (now - lastScrollTime >= scrollInterval) {
|
requestAnimationFrame(() => {
|
||||||
// 最后一个 滚到底部
|
outerContainer.value.scrollTo({
|
||||||
if(index == childTempList.value.length - 1){
|
top: outerContainer.value.scrollHeight,
|
||||||
console.log(outerContainer.value.scrollHeight)
|
behavior: 'smooth',
|
||||||
requestAnimationFrame(() => {
|
|
||||||
outerContainer.value.scrollTo({
|
|
||||||
top: outerContainer.value.scrollHeight,
|
|
||||||
behavior: 'smooth',
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
const item = messageElements.value[index]
|
||||||
|
if(item.clientHeight > outerContainer.value.clientHeight ){
|
||||||
|
item.scrollIntoView({ behavior: 'smooth', block: 'end' })
|
||||||
}
|
}
|
||||||
else{
|
}
|
||||||
const item = messageElements.value[index]
|
|
||||||
if(item.clientHeight > outerContainer.value.clientHeight ){
|
|
||||||
item.scrollIntoView({ behavior: 'smooth', block: 'end' })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
lastScrollTime = now;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 打字机完成后触发
|
// 打字机完成后触发
|
||||||
|
@ -285,16 +376,6 @@ const handleDone = () =>{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const handleComplete = (index) => {
|
|
||||||
// if (index < childTempList.value.length - 1) {
|
|
||||||
// document.querySelector(`.template-item:nth-child(${index + 2})`).scrollIntoView({ behavior: 'smooth' });
|
|
||||||
// } else {
|
|
||||||
// outerContainer.value.scrollTop = outerContainer.value.scrollHeight;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 模板切换
|
// 模板切换
|
||||||
const changeTemplate = (val) => {
|
const changeTemplate = (val) => {
|
||||||
ElMessageBox.confirm(
|
ElMessageBox.confirm(
|
||||||
|
@ -362,106 +443,7 @@ const onEdit = (index, item) => {
|
||||||
isEdit.value = true
|
isEdit.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重新研读
|
|
||||||
const prompt = ref('')
|
|
||||||
|
|
||||||
// 重新研读
|
|
||||||
const isAgain = ref(false)
|
|
||||||
const againResult = async (index, item) => {
|
|
||||||
|
|
||||||
isAgain.value = true
|
|
||||||
childTempList.value[index].answer = ''
|
|
||||||
childTempList.value[index].showTypewriter = true
|
|
||||||
return
|
|
||||||
// 滚动到该项的位置
|
|
||||||
if (messageElements.value[index]) {
|
|
||||||
messageElements.value[index].scrollIntoView({
|
|
||||||
behavior: 'smooth',
|
|
||||||
block: 'start',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await nextTick()
|
|
||||||
childTempList.value[index].loading = true
|
|
||||||
item.aiShow = true
|
|
||||||
|
|
||||||
let str = cloneDeep(prompt.value)
|
|
||||||
str = str.replace('{模板标题}',item.name)
|
|
||||||
str = str.replace('{模板内容}',item.prompt)
|
|
||||||
params.prompt = str
|
|
||||||
params.template = item.prompt
|
|
||||||
|
|
||||||
let data = null;
|
|
||||||
// 教学大模型
|
|
||||||
if (curMode.value == 1) {
|
|
||||||
const res = await sendChart({
|
|
||||||
content: params.prompt,
|
|
||||||
conversationId: conversation_id.value,
|
|
||||||
stream: false
|
|
||||||
})
|
|
||||||
data = res.data
|
|
||||||
} else {
|
|
||||||
// 知识库模型
|
|
||||||
const res = await completion(params)
|
|
||||||
data = res.data
|
|
||||||
}
|
|
||||||
|
|
||||||
childTempList.value[index].answer = data.answer;
|
|
||||||
|
|
||||||
onEditResult(data.answer, index)
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
childTempList.value[index].loading = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
||||||
// 一键研读
|
|
||||||
const getCompletion = async () => {
|
|
||||||
|
|
||||||
childTempList.value.forEach(item => {
|
|
||||||
if (item.answer) {
|
|
||||||
item.answer = ''
|
|
||||||
item.showTypewriter = true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
for (let item of childTempList.value) {
|
|
||||||
try {
|
|
||||||
item.loading = true
|
|
||||||
item.aiShow = true
|
|
||||||
let str = cloneDeep(prompt.value)
|
|
||||||
str = str.replace('{模板标题}',item.name)
|
|
||||||
str = str.replace('{模板内容}',item.prompt)
|
|
||||||
params.prompt = str
|
|
||||||
params.template = item.prompt
|
|
||||||
// 教学大模型
|
|
||||||
let data = null
|
|
||||||
if (curMode.value == 1) {
|
|
||||||
const res = await sendChart({
|
|
||||||
content: params.prompt,
|
|
||||||
conversationId: conversation_id.value,
|
|
||||||
stream: false
|
|
||||||
})
|
|
||||||
await delay(1000); // 每个请求之间延迟 1 秒
|
|
||||||
data = res.data
|
|
||||||
}
|
|
||||||
// 知识库模型
|
|
||||||
else {
|
|
||||||
const res = await completion(params)
|
|
||||||
data = res.data
|
|
||||||
}
|
|
||||||
|
|
||||||
item.answer = data.answer
|
|
||||||
|
|
||||||
await onSaveTemp(item)
|
|
||||||
} finally {
|
|
||||||
item.loading = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 保存编辑后的研读内容
|
// 保存编辑后的研读内容
|
||||||
const onEditResult = async (answer, index) => {
|
const onEditResult = async (answer, index) => {
|
||||||
|
|
Loading…
Reference in New Issue