Skip to content

Commit f34556b

Browse files
perf: Assistant empty chat
1 parent d442c06 commit f34556b

File tree

3 files changed

+50
-14
lines changed

3 files changed

+50
-14
lines changed

frontend/src/views/chat/ChatListContainer.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,17 @@ function goEmpty(func?: (...p: any[]) => void, ...params: any[]) {
114114
const createNewChat = async () => {
115115
goEmpty(doCreateNewChat)
116116
}
117-
117+
const isAssistantRepeatEmpty = () => {
118+
return (
119+
isAssistant.value &&
120+
(_currentChatId.value === null || typeof _currentChatId.value === 'undefined')
121+
)
122+
}
118123
async function doCreateNewChat() {
119124
if (isAssistant.value) {
125+
if (isAssistantRepeatEmpty()) {
126+
return
127+
}
120128
const assistantChat = await assistantStore.setChat()
121129
if (assistantChat) {
122130
onChatCreated(assistantChat)

frontend/src/views/chat/index.vue

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,27 @@
5858
<el-container :loading="loading">
5959
<el-main
6060
class="chat-record-list"
61-
:class="{ 'hide-sidebar': !isAssistant && !chatListSideBarShow }"
61+
:class="{
62+
'hide-sidebar': !isAssistant && !chatListSideBarShow,
63+
'assistant-chat-main': isAssistant,
64+
}"
6265
>
6366
<div v-if="computedMessages.length == 0 && !loading" class="welcome-content-block">
6467
<div class="welcome-content">
6568
<div class="greeting">
6669
<el-icon size="32">
6770
<logo_fold />
6871
</el-icon>
69-
{{ t('qa.greeting') }}
72+
{{ isAssistant ? t('embedded.i_am_sqlbot') : t('qa.greeting') }}
73+
</div>
74+
<div class="sub">
75+
{{ isAssistant ? t('embedded.predict_data_etc') : t('qa.hint_description') }}
76+
</div>
77+
<div v-if="isAssistant" class="sub assistant-sub">
78+
{{ t('embedded.intelligent_data_query') }}
7079
</div>
71-
<div class="sub">{{ t('qa.hint_description') }}</div>
7280
<el-button
73-
v-if="currentChatId === undefined"
81+
v-if="!isAssistant && currentChatId === undefined"
7482
size="large"
7583
type="primary"
7684
class="greeting-btn"
@@ -256,12 +264,9 @@
256264
</div>
257265
</el-scrollbar>
258266
</el-main>
259-
<el-footer
260-
v-if="computedMessages.length > 0 || (isAssistant && currentChatId)"
261-
class="chat-footer"
262-
>
267+
<el-footer v-if="computedMessages.length > 0 || isAssistant" class="chat-footer">
263268
<div class="input-wrapper" @click="clickInput">
264-
<div class="datasource">
269+
<div v-if="!isAssistant" class="datasource">
265270
<template v-if="currentChat.datasource && currentChat.datasource_name">
266271
{{ t('qa.selected_datasource') }}:
267272
<img
@@ -414,9 +419,17 @@ const createNewChatSimple = async () => {
414419
currentChatId.value = undefined
415420
await createNewChat()
416421
}
417-
422+
const isAssistantRepeatEmpty = () => {
423+
return (
424+
isAssistant.value &&
425+
(currentChatId.value === null || typeof currentChatId.value === 'undefined')
426+
)
427+
}
418428
const createNewChat = async () => {
419429
goEmpty()
430+
if (isAssistantRepeatEmpty()) {
431+
return
432+
}
420433
if (isAssistant.value) {
421434
const assistantChat = await assistantStore.setChat()
422435
if (assistantChat) {
@@ -531,13 +544,23 @@ function onChatStop() {
531544
isTyping.value = false
532545
console.debug('onChatStop')
533546
}
534-
547+
const assistantPrepareSend = async () => {
548+
if (
549+
isAssistant.value &&
550+
(currentChatId.value == null || typeof currentChatId.value == 'undefined')
551+
) {
552+
const assistantChat = await assistantStore.setChat()
553+
if (assistantChat) {
554+
onChatCreatedQuick(assistantChat as any)
555+
}
556+
}
557+
}
535558
const sendMessage = async () => {
536559
if (!inputMessage.value.trim()) return
537560
538561
loading.value = true
539562
isTyping.value = true
540-
563+
assistantPrepareSend()
541564
const currentRecord = new ChatRecord()
542565
currentRecord.create_time = new Date()
543566
currentRecord.chat_id = currentChatId.value
@@ -840,6 +863,9 @@ onMounted(() => {
840863
border-radius: 12px;
841864
}
842865
}
866+
.assistant-chat-main {
867+
padding: 0 0 20px 0;
868+
}
843869
844870
.chat-scroll {
845871
width: 100%;

frontend/src/views/embedded/index.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
</el-icon>
1919
</el-tooltip>
2020
</div>
21-
<chat-component v-if="!loading" ref="chatRef" class="sqlbot-chat-container" />
21+
<div class="sqlbot-chat-container">
22+
<chat-component v-if="!loading" ref="chatRef" />
23+
</div>
2224
<div class="drawer-assistant" @click="openHistory"></div>
2325
</div>
2426
</template>

0 commit comments

Comments
 (0)