Skip to content

Commit 6728d05

Browse files
perf: Assistant chat ui
1 parent 5865b5d commit 6728d05

File tree

4 files changed

+45
-22
lines changed

4 files changed

+45
-22
lines changed

backend/apps/chat/task/llm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def generate_recommend_questions_task(self):
296296

297297
# get schema
298298
if self.ds and not self.chat_question.db_schema:
299-
self.chat_question.db_schema = get_table_schema(session=self.session, ds=self.ds)
299+
self.chat_question.db_schema = get_table_schema(session=self.session, current_user=self.current_user, ds=self.ds)
300300

301301
guess_msg: List[Union[BaseMessage, dict[str, Any]]] = []
302302
guess_msg.append(SystemMessage(content=self.chat_question.guess_sys_question()))
@@ -726,7 +726,7 @@ def run_task(llm_service: LLMService, in_chat: bool = True):
726726
yield orjson.dumps({'id': llm_service.ds.id, 'datasource_name': llm_service.ds.name,
727727
'engine_type': llm_service.ds.type_name, 'type': 'datasource'}).decode() + '\n\n'
728728

729-
llm_service.chat_question.db_schema = get_table_schema(session=llm_service.session, ds=llm_service.ds)
729+
llm_service.chat_question.db_schema = get_table_schema(session=llm_service.session, current_user=llm_service.current_user, ds=llm_service.ds)
730730

731731
# generate sql
732732
sql_res = llm_service.generate_sql()
Lines changed: 1 addition & 4 deletions
Loading

frontend/src/views/chat/index.vue

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ const createNewChat = async () => {
292292
if (isAssistant.value) {
293293
const assistantChat = await assistantStore.setChat()
294294
if (assistantChat) {
295-
onChatCreated(assistantChat as any)
295+
onChatCreatedQuick(assistantChat as any)
296296
}
297297
return
298298
}
@@ -317,6 +317,26 @@ function onClickHistory(chat: Chat) {
317317
scrollToBottom()
318318
}
319319
320+
function toAssistantHistory(chat: Chat) {
321+
currentChat.value = new ChatInfo(chat)
322+
if (chat !== undefined && chat.id !== undefined && !loading.value) {
323+
currentChatId.value = chat.id
324+
loading.value = true
325+
chatApi
326+
.get(chat.id)
327+
.then((res) => {
328+
const info = chatApi.toChatInfo(res)
329+
if (info) {
330+
currentChat.value = info
331+
onClickHistory(info)
332+
}
333+
})
334+
.finally(() => {
335+
loading.value = false
336+
})
337+
}
338+
}
339+
320340
function onChatDeleted(id: number) {
321341
console.log('deleted', id)
322342
}
@@ -434,11 +454,6 @@ const sendMessage = async () => {
434454
loading.value = true
435455
isTyping.value = true
436456
437-
/* const assistantChat = await assistantStore.setChat()
438-
if (assistantChat) {
439-
onChatCreated(assistantChat as any)
440-
} */
441-
442457
const currentRecord = new ChatRecord()
443458
currentRecord.create_time = new Date()
444459
currentRecord.chat_id = currentChatId.value
@@ -833,10 +848,9 @@ const getCurrentChatId = () => {
833848
}
834849
defineExpose({
835850
getHistoryList,
836-
onClickHistory,
837-
onChatDeleted,
838-
onChatRenamed,
851+
toAssistantHistory,
839852
getCurrentChatId,
853+
createNewChat,
840854
})
841855
</script>
842856

frontend/src/views/embedded/assistant.vue

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
<chat-component v-if="!loading" ref="chatRef" class="sqlbot-chat-container" />
1212
</div>
1313
<div class="sqlbot-top-btn">
14+
<el-icon style="cursor: pointer" @click="createChat">
15+
<icon_new_chat_outlined />
16+
</el-icon>
1417
<el-icon style="cursor: pointer" @click="openHistory">
1518
<history></history>
1619
</el-icon>
@@ -41,10 +44,10 @@
4144
@click="onClickHistory(chat)"
4245
>
4346
<span class="title">{{ chat.brief ?? 'Untitled' }}</span>
44-
<div class="history-operate">
47+
<!-- <div class="history-operate">
4548
<el-icon @click="EditPen(chat)"><IconOpeEdit /></el-icon>
4649
<el-icon @click="Delete(chat)"><IconOpeDelete /></el-icon>
47-
</div>
50+
</div> -->
4851
</div>
4952
</template>
5053
</el-scrollbar>
@@ -58,8 +61,9 @@ import { onBeforeMount, ref } from 'vue'
5861
import ChatComponent from '@/views/chat/index.vue'
5962
import AssistantGif from '@/assets/img/assistant.gif'
6063
import history from '@/assets/svg/chart/history.svg'
61-
import IconOpeEdit from '@/assets/svg/operate/ope-edit.svg'
62-
import IconOpeDelete from '@/assets/svg/operate/ope-delete.svg'
64+
import icon_new_chat_outlined from '@/assets/svg/icon_new_chat_outlined.svg'
65+
/* import IconOpeEdit from '@/assets/svg/operate/ope-edit.svg'
66+
import IconOpeDelete from '@/assets/svg/operate/ope-delete.svg' */
6367
import { useRoute } from 'vue-router'
6468
import { assistantApi } from '@/api/assistant'
6569
import { useAssistantStore } from '@/stores/assistant'
@@ -72,21 +76,24 @@ const chatList = ref<Array<any>>([])
7276
const drawer = ref(false)
7377
const currentId = ref()
7478
79+
const createChat = () => {
80+
chatRef.value?.createNewChat()
81+
}
7582
const openHistory = () => {
7683
chatList.value = chatRef.value?.getHistoryList()
7784
currentId.value = chatRef.value?.getCurrentChatId()
7885
drawer.value = true
7986
}
8087
const onClickHistory = (chat: any) => {
81-
chatRef.value?.onClickHistory(chat)
88+
chatRef.value?.toAssistantHistory(chat)
8289
}
8390
84-
const EditPen = (chat: any) => {
91+
/* const EditPen = (chat: any) => {
8592
chatRef.value?.onChatRenamed(chat)
8693
}
8794
const Delete = (chat: any) => {
8895
chatRef.value?.onChatDeleted(chat.id)
89-
}
96+
} */
9097
const validator = ref({
9198
id: '',
9299
valid: false,
@@ -155,8 +162,13 @@ onBeforeMount(async () => {
155162
z-index: 2009;
156163
position: absolute;
157164
top: 16px;
165+
display: flex;
166+
column-gap: 16px;
158167
// right: 16px;
159168
font-size: 22px;
169+
i:first-child {
170+
color: var(--primary-color);
171+
}
160172
}
161173
.sqlbot-history-container {
162174
width: 100%;

0 commit comments

Comments
 (0)