fix: Generated prompt word issues
parent
709e60390a
commit
f065146d5f
|
|
@ -5,13 +5,20 @@
|
||||||
v-model="dialogVisible"
|
v-model="dialogVisible"
|
||||||
style="width: 600px"
|
style="width: 600px"
|
||||||
append-to-body
|
append-to-body
|
||||||
|
:close-on-click-modal="false"
|
||||||
|
:close-on-press-escape="false"
|
||||||
>
|
>
|
||||||
<div class="generate-prompt-dialog-bg border-r-8">
|
<div class="generate-prompt-dialog-bg border-r-8">
|
||||||
<div class="scrollbar-height">
|
<div class="scrollbar-height">
|
||||||
<!-- 生成内容 -->
|
<!-- 生成内容 -->
|
||||||
<div class="p-16 pb-0 lighter">
|
<div class="p-16 pb-0 lighter">
|
||||||
<el-scrollbar>
|
<el-scrollbar ref="scrollDiv">
|
||||||
<div v-if="answer" class="pre-wrap lighter" style="max-height: calc(100vh - 400px)">
|
<div
|
||||||
|
ref="dialogScrollbar"
|
||||||
|
v-if="answer"
|
||||||
|
class="pre-wrap lighter"
|
||||||
|
style="max-height: calc(100vh - 400px)"
|
||||||
|
>
|
||||||
{{ answer }}
|
{{ answer }}
|
||||||
</div>
|
</div>
|
||||||
<p v-else-if="loading" shadow="always" style="margin: 0.5rem 0">
|
<p v-else-if="loading" shadow="always" style="margin: 0.5rem 0">
|
||||||
|
|
@ -38,7 +45,7 @@
|
||||||
<div class="text-center mb-8" v-if="loading">
|
<div class="text-center mb-8" v-if="loading">
|
||||||
<el-button class="border-primary video-stop-button" @click="stopChat">
|
<el-button class="border-primary video-stop-button" @click="stopChat">
|
||||||
<app-icon iconName="app-video-stop" class="mr-8"></app-icon>
|
<app-icon iconName="app-video-stop" class="mr-8"></app-icon>
|
||||||
{{ $t('chat.operation.stopChat') }}
|
停止生成
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -51,6 +58,7 @@
|
||||||
:placeholder="$t('views.application.generateDialog.placeholder')"
|
:placeholder="$t('views.application.generateDialog.placeholder')"
|
||||||
:maxlength="100000"
|
:maxlength="100000"
|
||||||
class="chat-operate-textarea"
|
class="chat-operate-textarea"
|
||||||
|
@keydown.enter="handleSubmit($event)"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div class="operate">
|
<div class="operate">
|
||||||
|
|
@ -74,7 +82,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, reactive, ref } from 'vue'
|
import { computed, reactive, ref, nextTick, watch } from 'vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import systemGeneratePromptAPI from '@/api/system-resource-management/application'
|
import systemGeneratePromptAPI from '@/api/system-resource-management/application'
|
||||||
import generatePromptAPI from '@/api/application/application'
|
import generatePromptAPI from '@/api/application/application'
|
||||||
|
|
@ -215,20 +223,33 @@ function generatePrompt(inputValue: any) {
|
||||||
prompt: promptTemplates.INIT_TEMPLATE,
|
prompt: promptTemplates.INIT_TEMPLATE,
|
||||||
}
|
}
|
||||||
if (apiType.value === 'workspace') {
|
if (apiType.value === 'workspace') {
|
||||||
generatePromptAPI.generate_prompt(workspaceId, modelID.value, applicationID.value,requestData)
|
generatePromptAPI
|
||||||
.then((response) => {
|
.generate_prompt(workspaceId, modelID.value, applicationID.value, requestData)
|
||||||
const reader = response.body.getReader()
|
.then((response) => {
|
||||||
reader.read().then(getWrite(reader))
|
nextTick(() => {
|
||||||
})
|
if (dialogScrollbar.value) {
|
||||||
|
// 将滚动条滚动到最下面
|
||||||
|
scrollDiv.value.setScrollTop(getMaxHeight())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const reader = response.body.getReader()
|
||||||
|
reader.read().then(getWrite(reader))
|
||||||
|
})
|
||||||
} else if (apiType.value === 'systemManage') {
|
} else if (apiType.value === 'systemManage') {
|
||||||
console.log(apiType.value)
|
console.log(apiType.value)
|
||||||
systemGeneratePromptAPI.generate_prompt(applicationID.value, modelID.value, requestData)
|
systemGeneratePromptAPI
|
||||||
.then((response) => {
|
.generate_prompt(applicationID.value, modelID.value, requestData)
|
||||||
const reader = response.body.getReader()
|
.then((response) => {
|
||||||
reader.read().then(getWrite(reader))
|
nextTick(() => {
|
||||||
})
|
if (dialogScrollbar.value) {
|
||||||
|
// 将滚动条滚动到最下面
|
||||||
|
scrollDiv.value.setScrollTop(getMaxHeight())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const reader = response.body.getReader()
|
||||||
|
reader.read().then(getWrite(reader))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重新生成点击
|
// 重新生成点击
|
||||||
|
|
@ -238,12 +259,35 @@ const reAnswerClick = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSubmit = () => {
|
const quickInputRef = ref()
|
||||||
if (!originalUserInput.value) {
|
|
||||||
originalUserInput.value = inputValue.value
|
const handleSubmit = (event?: any) => {
|
||||||
|
if (!event?.ctrlKey && !event?.shiftKey && !event?.altKey && !event?.metaKey) {
|
||||||
|
// 如果没有按下组合键,则会阻止默认事件
|
||||||
|
event?.preventDefault()
|
||||||
|
if (!originalUserInput.value) {
|
||||||
|
originalUserInput.value = inputValue.value
|
||||||
|
}
|
||||||
|
generatePrompt(inputValue.value)
|
||||||
|
inputValue.value = ''
|
||||||
|
} else {
|
||||||
|
// 如果同时按下ctrl/shift/cmd/opt +enter,则会换行
|
||||||
|
insertNewlineAtCursor(event)
|
||||||
}
|
}
|
||||||
generatePrompt(inputValue.value)
|
}
|
||||||
inputValue.value = ''
|
const insertNewlineAtCursor = (event?: any) => {
|
||||||
|
const textarea = quickInputRef.value.$el.querySelector(
|
||||||
|
'.el-textarea__inner',
|
||||||
|
) as HTMLTextAreaElement
|
||||||
|
const startPos = textarea.selectionStart
|
||||||
|
const endPos = textarea.selectionEnd
|
||||||
|
// 阻止默认行为(避免额外的换行符)
|
||||||
|
event.preventDefault()
|
||||||
|
// 在光标处插入换行符
|
||||||
|
inputValue.value = inputValue.value.slice(0, startPos) + '\n' + inputValue.value.slice(endPos)
|
||||||
|
nextTick(() => {
|
||||||
|
textarea.setSelectionRange(startPos + 1, startPos + 1) // 光标定位到换行后位置
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const stopChat = () => {
|
const stopChat = () => {
|
||||||
|
|
@ -259,6 +303,34 @@ const open = (modelId: string, applicationId: string) => {
|
||||||
chatMessages.value = []
|
chatMessages.value = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const scrollDiv = ref()
|
||||||
|
const dialogScrollbar = ref()
|
||||||
|
|
||||||
|
const getMaxHeight = () => {
|
||||||
|
return dialogScrollbar.value!.scrollHeight
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理跟随滚动条
|
||||||
|
*/
|
||||||
|
const handleScroll = () => {
|
||||||
|
if (scrollDiv.value) {
|
||||||
|
// 内部高度小于外部高度 就需要出滚动条
|
||||||
|
if (scrollDiv.value.wrapRef.offsetHeight < dialogScrollbar.value?.scrollHeight) {
|
||||||
|
// 如果当前滚动条距离最下面的距离在 规定距离 滚动条就跟随
|
||||||
|
scrollDiv.value.setScrollTop(getMaxHeight())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
answer,
|
||||||
|
() => {
|
||||||
|
handleScroll()
|
||||||
|
},
|
||||||
|
{ deep: true, immediate: true },
|
||||||
|
)
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
open,
|
open,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue