perf: chat增加提示词 (#3603)

Co-authored-by: “huailei000” <2280131253@qq.com>
Co-authored-by: huailei <31801270+huailei000@users.noreply.github.com>
This commit is contained in:
fit2bot
2023-12-14 16:37:48 +08:00
committed by GitHub
parent 3bf7eed52e
commit 9b7a360ea1
9 changed files with 95 additions and 31 deletions

View File

@@ -1,18 +1,27 @@
<template> <template>
<div class="container"> <div class="container">
<div class="chat-action">
<Select2
v-model="select.value"
:disabled="isLoading"
v-bind="select"
@change="onSelectChange"
/>
</div>
<div class="chat-input"> <div class="chat-input">
<el-input <el-input
v-model="value" v-model="inputValue"
:disabled="isLoading"
:placeholder="$t('common.EnterMessage')"
type="textarea" type="textarea"
:disabled="isLoading"
:placeholder="$tc('common.InputMessage')"
@compositionstart="isIM = true"
@compositionend="isIM = false" @compositionend="isIM = false"
@compositionstart="isIM = true" @compositionstart="isIM = true"
@keypress.native="onKeyEnter" @keypress.native="onKeyEnter"
/> />
<div class="input-action"> <div class="input-action">
<span class="right"> <span class="right">
<i :class="{'active': value }" class="fa fa-send" @click="onSendHandle" /> <i class="fa fa-send" :class="{'active': inputValue }" @click="onSendHandle" />
</span> </span>
</div> </div>
</div> </div>
@@ -21,17 +30,30 @@
<script> <script>
import { mapState } from 'vuex' import { mapState } from 'vuex'
import Select2 from '../../../../Form/FormFields/Select2.vue'
import { useChat } from '../../useChat.js' import { useChat } from '../../useChat.js'
const { setLoading } = useChat() const { setLoading } = useChat()
export default { export default {
components: { Select2 },
props: { props: {
}, },
data() { data() {
return { return {
isIM: false, isIM: false,
value: '' inputValue: '',
select: {
url: '/api/v1/settings/chatai-prompts/',
value: '',
multiple: false,
placeholder: this.$t('common.Prompt'),
ajax: {
transformOption: (item) => {
return { label: item.name, value: item.content }
}
}
}
} }
}, },
computed: { computed: {
@@ -54,11 +76,15 @@ export default {
} }
}, },
onSendHandle() { onSendHandle() {
if (!this.value) return if (!this.inputValue) return
setLoading(true) setLoading(true)
this.$emit('send', this.value) this.$emit('send', this.inputValue)
this.value = '' this.inputValue = ''
},
onSelectChange(value) {
this.inputValue = value
this.$emit('select-prompt', value)
} }
} }
} }
@@ -69,18 +95,25 @@ export default {
display: flex; display: flex;
height: 100%; height: 100%;
flex-direction: column; flex-direction: column;
.action { .chat-action {
height: 44px;
line-height: 44px;
width: 100%; width: 100%;
margin: 6px 0;
&>>> .el-select { &>>> .el-select {
width: 50%;
.el-input__inner { .el-input__inner {
height: 28px; height: 28px;
line-height: 28px; line-height: 28px;
border-radius: 16px; border-radius: 16px;
border-color: transparent;
background-color: #f7f7f8; background-color: #f7f7f8;
font-size: 13px; font-size: 13px;
color: rgba(0, 0, 0, 0.45); color: rgba(0, 0, 0, 0.45);
&:hover {
background-color: #ededed;
}
}
.el-input__icon {
line-height: 0px;
} }
} }
} }
@@ -88,7 +121,6 @@ export default {
flex: 1; flex: 1;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
margin-top: 16px;
border: 1px solid #DCDFE6; border: 1px solid #DCDFE6;
border-radius: 12px; border-radius: 12px;
&:has(.el-textarea__inner:focus) { &:has(.el-textarea__inner:focus) {

View File

@@ -135,7 +135,7 @@ export default {
display: -webkit-box; display: -webkit-box;
.message-content { .message-content {
flex: 1; flex: 1;
padding: 8px 12px; padding: 6px 10px;
border-radius: 2px 12px 12px; border-radius: 2px 12px 12px;
background-color: #f0f1f5; background-color: #f0f1f5;
} }
@@ -148,12 +148,15 @@ export default {
.el-dropdown { .el-dropdown {
height: 32px; height: 32px;
line-height: 37px; line-height: 37px;
margin-left: 4px;
font-size: 13px; font-size: 13px;
.el-dropdown-link { .el-dropdown-link {
i { i {
padding: 4px 5px;
font-size: 15px; font-size: 15px;
color: #8d9091; color: #8d9091;
&:hover {
color: #7b8085
}
} }
} }
} }

View File

@@ -19,6 +19,7 @@ import hljs from 'highlight.js'
import 'highlight.js/styles/atom-one-dark.css' import 'highlight.js/styles/atom-one-dark.css'
import { copy } from '@/utils/common' import { copy } from '@/utils/common'
/* eslint-disable vue/no-v-html */
export default { export default {
props: { props: {
message: { message: {
@@ -37,7 +38,7 @@ export default {
if (value && this.markdown) { if (value && this.markdown) {
return this.markdown?.render(value) return this.markdown?.render(value)
} }
return value return this.$xss.process(value)
} }
}, },
mounted() { mounted() {
@@ -96,8 +97,14 @@ export default {
<style lang="scss" scoped> <style lang="scss" scoped>
.markdown-body { .markdown-body {
font-size: 13px; font-size: 13px;
&>>> p {
margin-bottom: 0 !important;
}
&>>> pre { &>>> pre {
padding: 10px; padding: 6px 0;
.hljs.code-block-body {
border-radius: 4px;
}
} }
background-color: transparent; background-color: transparent;
&>>> .code-block-wrapper { &>>> .code-block-wrapper {
@@ -135,7 +142,7 @@ export default {
margin-right: 5px; margin-right: 5px;
border-radius: 50%; border-radius: 50%;
vertical-align: middle; vertical-align: middle;
background: rgb(182, 189, 198); background: #676A6c;
animation: load 1.2s ease infinite; animation: load 1.2s ease infinite;
} }
.loading-box span:last-child{ .loading-box span:last-child{

View File

@@ -23,7 +23,7 @@
size="small" size="small"
@click="onStopHandle" @click="onStopHandle"
>{{ $tc('common.Stop') }}</el-button> >{{ $tc('common.Stop') }}</el-button>
<ChatInput @send="onSendHandle" /> <ChatInput @send="onSendHandle" @select-prompt="onSelectPromptHandle" />
</div> </div>
</div> </div>
</template> </template>
@@ -56,6 +56,7 @@ export default {
data() { data() {
return { return {
socket: {}, socket: {},
prompt: [],
currentConversationId: '', currentConversationId: '',
showIntroduction: false, showIntroduction: false,
introduction: [ introduction: [
@@ -152,6 +153,7 @@ export default {
} }
const message = { const message = {
content: value, content: value,
prompt: this.prompt,
conversation_id: this.currentConversationId || '' conversation_id: this.currentConversationId || ''
} }
addChatMessageById(chat) addChatMessageById(chat)
@@ -171,9 +173,13 @@ export default {
setLoading(true) setLoading(true)
} }
}, },
onSelectPromptHandle(value) {
this.prompt = value
this.currentConversationId = ''
},
onStopHandle() { onStopHandle() {
this.$axios.post( this.$axios.post(
'/kael/chat/interrupt_current_ask/', '/kael/interrupt_current_ask/',
{ id: this.currentConversationId || '' } { id: this.currentConversationId || '' }
).finally(() => { ).finally(() => {
removeLoadingMessageInChat() removeLoadingMessageInChat()
@@ -229,20 +235,20 @@ export default {
.chat-list { .chat-list {
flex: 1; flex: 1;
position: relative; position: relative;
padding: 0 15px 15px; padding: 0 15px 25px;
overflow-y: auto; overflow-y: auto;
user-select: text; user-select: text;
} }
.input-box { .input-box {
position: relative; position: relative;
height: 154px; height: 160px;
padding: 0 15px; padding: 0 15px;
margin-bottom: 15px; margin-bottom: 15px;
border-top: 1px solid #ececec; border-top: 1px solid #ececec;
} }
.stop { .stop {
position: absolute; position: absolute;
top: -36px; top: -37px;
left: 50%; left: 50%;
z-index: 11; z-index: 11;
transform: translateX(-50%); transform: translateX(-50%);

View File

@@ -1,7 +1,7 @@
<template> <template>
<div class="container"> <div class="container">
<div class="top"> <div class="close-sidebar">
<svg-icon icon-class="collapse" @click="onClose" /> <i class="el-icon-close" @click="onClose" />
</div> </div>
<el-tabs v-model="active" :tab-position="'right'" @tab-click="handleClick"> <el-tabs v-model="active" :tab-position="'right'" @tab-click="handleClick">
<el-tab-pane v-for="(item) in submenu" :key="item.name" :name="item.name"> <el-tab-pane v-for="(item) in submenu" :key="item.name" :name="item.name">
@@ -47,14 +47,19 @@ export default {
width: 100%; width: 100%;
height: 100%; height: 100%;
background-color: #f0f1f5; background-color: #f0f1f5;
.top { .close-sidebar {
text-align: center; text-align: center;
font-size: 14px; font-size: 14px;
padding: 14px 0; padding: 12px 0;
cursor: pointer; cursor: pointer;
>>> .svg-icon { i {
font-size: 16px;
font-weight: 600;
padding: 4px;
border-radius: 2px;
&:hover { &:hover {
color: #7b8085; color: var(--color-primary);
background: var(--menu-hover);
} }
} }
} }

View File

@@ -141,6 +141,7 @@ export default {
min-width: 260px; min-width: 260px;
height: 100vh; height: 100vh;
user-select: none; user-select: none;
border-radius: 20px 0 0 20px;
transition: transform .25s cubic-bezier(.7, .3, .1, 1); transition: transform .25s cubic-bezier(.7, .3, .1, 1);
box-shadow: 0 0 8px 4px #00000014; box-shadow: 0 0 8px 4px #00000014;
transform: translate(100%); transform: translate(100%);
@@ -191,9 +192,13 @@ export default {
cursor: pointer; cursor: pointer;
&:hover { &:hover {
left: -52px !important; left: -50px !important;
width: 52px !important; width: 50px !important;
transform: scale(1.1); transform: scale(1.06);
background-color: rgba(182, 181, 186, .9);
img {
filter: grayscale(1);
}
} }
i { i {
font-size: 20px; font-size: 20px;

View File

@@ -742,6 +742,8 @@
"Reconnect": "Reconnect", "Reconnect": "Reconnect",
"NewChat": "New Chat", "NewChat": "New Chat",
"Chat": "Chat", "Chat": "Chat",
"Prompt": "Prompt",
"InputMessage": "Input message...",
"CollapseSidebar": "Collapse the sidebar", "CollapseSidebar": "Collapse the sidebar",
"introduction": { "introduction": {
"ConceptTitle": "🤔 Python interpreter", "ConceptTitle": "🤔 Python interpreter",

View File

@@ -743,6 +743,8 @@
"Reconnect": "再接続", "Reconnect": "再接続",
"NewChat": "新しいチャット", "NewChat": "新しいチャット",
"Chat": "チャット", "Chat": "チャット",
"Prompt": "ヒント",
"InputMessage": "メッセージの入力...",
"CollapseSidebar": "サイドバーを閉じる", "CollapseSidebar": "サイドバーを閉じる",
"introduction": { "introduction": {
"ConceptTitle": "🤔 Python インタプリタ", "ConceptTitle": "🤔 Python インタプリタ",

View File

@@ -795,6 +795,8 @@
"Reconnect": "重新连接", "Reconnect": "重新连接",
"NewChat": "新聊天", "NewChat": "新聊天",
"Chat": "聊天", "Chat": "聊天",
"Prompt": "提示词",
"InputMessage": "输入消息..."
"EnterMessage": "请输入问题, Enter 发送", "EnterMessage": "请输入问题, Enter 发送",
"CollapseSidebar": "收起侧边栏", "CollapseSidebar": "收起侧边栏",
"introduction": { "introduction": {