This commit is contained in:
lyc 2025-02-20 17:27:59 +08:00
parent f02f6a8384
commit a708eb59b5
1 changed files with 121 additions and 139 deletions

View File

@ -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,23 +344,16 @@ 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 (now - lastScrollTime >= scrollInterval) {
// //
if(index == childTempList.value.length - 1){ if(index == childTempList.value.length - 1){
console.log(outerContainer.value.scrollHeight)
requestAnimationFrame(() => { requestAnimationFrame(() => {
outerContainer.value.scrollTo({ outerContainer.value.scrollTo({
top: outerContainer.value.scrollHeight, top: outerContainer.value.scrollHeight,
@ -274,8 +367,6 @@ const scrollToTmp = (index) =>{
item.scrollIntoView({ behavior: 'smooth', block: 'end' }) 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) => {