Skip to content

Commit 54e2cdf

Browse files
perf: Optimize embedded page style layout
1 parent 314b83c commit 54e2cdf

File tree

8 files changed

+42
-35
lines changed

8 files changed

+42
-35
lines changed

backend/apps/chat/curd/chat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def get_chat_with_records_with_data(session: SessionDep, chart_id: int, current_
9595
current_assistant: CurrentAssistant) -> ChatInfo:
9696
return get_chat_with_records(session, chart_id, current_user, current_assistant, True)
9797

98-
98+
dynamic_ds_types = [1, 3]
9999
def get_chat_with_records(session: SessionDep, chart_id: int, current_user: CurrentUser,
100100
current_assistant: CurrentAssistant, with_data: bool = False) -> ChatInfo:
101101
chat = session.get(Chat, chart_id)
@@ -104,7 +104,7 @@ def get_chat_with_records(session: SessionDep, chart_id: int, current_user: Curr
104104

105105
chat_info = ChatInfo(**chat.model_dump())
106106

107-
if current_assistant and current_assistant.type == 1:
107+
if current_assistant and current_assistant.type in dynamic_ds_types:
108108
out_ds_instance = AssistantOutDsFactory.get_instance(current_assistant)
109109
ds = out_ds_instance.get_ds(chat.datasource)
110110
else:

backend/apps/chat/task/llm.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
executor = ThreadPoolExecutor(max_workers=200)
4444

45+
dynamic_ds_types = [1, 3]
4546

4647
class LLMService:
4748
ds: CoreDatasource
@@ -79,7 +80,7 @@ def __init__(self, current_user: CurrentUser, chat_question: ChatQuestion,
7980
if chat.datasource:
8081
# Get available datasource
8182
# ds = self.session.query(CoreDatasource).filter(CoreDatasource.id == chat.datasource).first()
82-
if current_assistant and current_assistant.type == 1:
83+
if current_assistant and current_assistant.type in dynamic_ds_types:
8384
self.out_ds_instance = AssistantOutDsFactory.get_instance(current_assistant)
8485
ds = self.out_ds_instance.get_ds(chat.datasource)
8586
if not ds:
@@ -355,7 +356,7 @@ def generate_recommend_questions_task(self):
355356
def select_datasource(self):
356357
datasource_msg: List[Union[BaseMessage, dict[str, Any]]] = []
357358
datasource_msg.append(SystemMessage(self.chat_question.datasource_sys_question()))
358-
if self.current_assistant:
359+
if self.current_assistant and self.current_assistant.type != 4:
359360
_ds_list = get_assistant_ds(session=self.session, llm_service=self)
360361
else:
361362
oid: str = self.current_user.oid
@@ -426,7 +427,7 @@ def select_datasource(self):
426427
_datasource = data['id']
427428
_chat = self.session.get(Chat, self.record.chat_id)
428429
_chat.datasource = _datasource
429-
if self.current_assistant and self.current_assistant.type == 1:
430+
if self.current_assistant and self.current_assistant.type in dynamic_ds_types:
430431
_ds = self.out_ds_instance.get_ds(data['id'])
431432
self.ds = _ds
432433
self.chat_question.engine = _ds.type
@@ -851,7 +852,7 @@ def run_task(self, in_chat: bool = True):
851852

852853
# filter sql
853854
SQLBotLogUtil.info(full_sql_text)
854-
use_dynamic_ds: bool = self.current_assistant and self.current_assistant.type == 1
855+
use_dynamic_ds: bool = self.current_assistant and self.current_assistant.type in dynamic_ds_types
855856

856857
# todo row permission
857858
if (not self.current_assistant and is_normal_user(self.current_user)) or use_dynamic_ds:
@@ -1037,7 +1038,7 @@ def run_analysis_or_predict_task(self, action_type: str):
10371038

10381039
def validate_history_ds(self):
10391040
_ds = self.ds
1040-
if not self.current_assistant:
1041+
if not self.current_assistant or self.current_assistant.type == 4:
10411042
try:
10421043
current_ds = self.session.get(CoreDatasource, _ds.id)
10431044
if not current_ds:

backend/apps/system/crud/assistant.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def get_assistant_user(*, id: int):
3232
def get_assistant_ds(session: Session, llm_service) -> list[dict]:
3333
assistant: AssistantHeader = llm_service.current_assistant
3434
type = assistant.type
35-
if type == 0:
35+
if type == 0 or type == 2:
3636
configuration = assistant.configuration
3737
if configuration:
3838
config: dict[any] = json.loads(configuration)

frontend/src/stores/assistant.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ export const AssistantStore = defineStore('assistant', {
5757
getOnline(): boolean {
5858
return this.online
5959
},
60+
getEmbedded(): boolean {
61+
return this.assistant && this.type === 4
62+
},
6063
},
6164
actions: {
6265
refreshCertificate<T>() {

frontend/src/views/chat/ChatListContainer.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const emits = defineEmits([
4343
])
4444
4545
const assistantStore = useAssistantStore()
46-
const isAssistant = computed(() => assistantStore.getAssistant)
46+
const isCompletePage = computed(() => !assistantStore.getAssistant || assistantStore.getEmbedded)
4747
4848
const search = ref<string>()
4949
@@ -145,7 +145,7 @@ const createNewChat = async () => {
145145
}
146146
147147
async function doCreateNewChat() {
148-
if (isAssistant.value) {
148+
if (!isCompletePage.value) {
149149
return
150150
}
151151
chatCreatorRef.value?.showDs()
@@ -252,7 +252,7 @@ function onChatRenamed(chat: Chat) {
252252
/>
253253
</el-main>
254254

255-
<ChatCreator v-if="!isAssistant" ref="chatCreatorRef" @on-chat-created="onChatCreated" />
255+
<ChatCreator v-if="isCompletePage" ref="chatCreatorRef" @on-chat-created="onChatCreated" />
256256
</el-container>
257257
</template>
258258

frontend/src/views/chat/ErrorInfo.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const props = defineProps<{
1010
const { t } = useI18n()
1111
1212
const assistantStore = useAssistantStore()
13-
const isAssistant = computed(() => assistantStore.getAssistant)
13+
const isCompletePage = computed(() => !assistantStore.getAssistant || assistantStore.getEmbedded)
1414
1515
const showBlock = computed(() => {
1616
return props.error && props.error?.trim().length > 0
@@ -54,7 +54,7 @@ function showTraceBack() {
5454

5555
<el-drawer
5656
v-model="show"
57-
:size="isAssistant ? '100%' : '600px'"
57+
:size="!isCompletePage ? '100%' : '600px'"
5858
:title="t('chat.error')"
5959
direction="rtl"
6060
body-class="chart-sql-error-body"

frontend/src/views/chat/chat-block/ChartBlock.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const dataObject = computed<{
6161
return {}
6262
})
6363
const assistantStore = useAssistantStore()
64-
const isAssistant = computed(() => assistantStore.getAssistant)
64+
const isCompletePage = computed(() => !assistantStore.getAssistant || assistantStore.getEmbedded)
6565
6666
const chartId = computed(() => props.message?.record?.id + (props.enlarge ? '-fullscreen' : ''))
6767
@@ -409,7 +409,7 @@ watch(
409409
<el-tooltip
410410
effect="dark"
411411
:offset="8"
412-
:content="isAssistant ? $t('common.zoom_in') : t('chat.full_screen')"
412+
:content="!isCompletePage ? $t('common.zoom_in') : t('chat.full_screen')"
413413
placement="top"
414414
>
415415
<el-button class="tool-btn" text @click="openFullScreen">
@@ -423,7 +423,7 @@ watch(
423423
<el-tooltip
424424
effect="dark"
425425
:offset="8"
426-
:content="isAssistant ? $t('common.zoom_out') : t('chat.exit_full_screen')"
426+
:content="!isCompletePage ? $t('common.zoom_out') : t('chat.exit_full_screen')"
427427
placement="top"
428428
>
429429
<el-button class="tool-btn" text @click="closeFullScreen">
@@ -473,7 +473,7 @@ watch(
473473

474474
<el-drawer
475475
v-model="sqlShow"
476-
:size="isAssistant ? '100%' : '600px'"
476+
:size="!isCompletePage ? '100%' : '600px'"
477477
:title="t('chat.show_sql')"
478478
direction="rtl"
479479
body-class="chart-sql-drawer-body"

frontend/src/views/chat/index.vue

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<el-container class="chat-container no-padding">
3-
<el-aside v-if="!isAssistant && chatListSideBarShow" class="chat-container-left">
3+
<el-aside v-if="isCompletePage && chatListSideBarShow" class="chat-container-left">
44
<ChatListContainer
55
v-model:chat-list="chatList"
66
v-model:current-chat-id="currentChatId"
@@ -16,9 +16,9 @@
1616
/>
1717
</el-aside>
1818
<div
19-
v-if="isAssistant || !chatListSideBarShow"
19+
v-if="!isCompletePage || !chatListSideBarShow"
2020
class="hidden-sidebar-btn"
21-
:class="{ 'assistant-popover-sidebar': isAssistant }"
21+
:class="{ 'assistant-popover-sidebar': !isCompletePage }"
2222
>
2323
<el-popover
2424
:width="280"
@@ -86,13 +86,13 @@
8686
<el-main
8787
class="chat-record-list"
8888
:class="{
89-
'hide-sidebar': !isAssistant && !chatListSideBarShow,
90-
'assistant-chat-main': isAssistant,
89+
'hide-sidebar': isCompletePage && !chatListSideBarShow,
90+
'assistant-chat-main': !isCompletePage,
9191
}"
9292
>
9393
<div v-if="computedMessages.length == 0 && !loading" class="welcome-content-block">
9494
<div class="welcome-content">
95-
<template v-if="!isAssistant">
95+
<template v-if="isCompletePage">
9696
<div class="greeting">
9797
<el-icon size="32">
9898
<logo_fold />
@@ -111,7 +111,7 @@
111111
</div>
112112

113113
<el-button
114-
v-if="!isAssistant && currentChatId === undefined"
114+
v-if="isCompletePage && currentChatId === undefined"
115115
size="large"
116116
type="primary"
117117
class="greeting-btn"
@@ -132,7 +132,10 @@
132132
<el-scrollbar v-if="computedMessages.length > 0" ref="chatListRef" class="no-horizontal">
133133
<div
134134
class="chat-scroll"
135-
:class="{ 'no-sidebar': !isAssistant && !chatListSideBarShow, pad16: isAssistant }"
135+
:class="{
136+
'no-sidebar': isCompletePage && !chatListSideBarShow,
137+
pad16: !isCompletePage,
138+
}"
136139
>
137140
<template v-for="(message, _index) in computedMessages" :key="_index">
138141
<ChatRow :current-chat="currentChat" :msg="message" :hide-avatar="message.first_chat">
@@ -287,9 +290,9 @@
287290
</div>
288291
</el-scrollbar>
289292
</el-main>
290-
<el-footer v-if="computedMessages.length > 0 || isAssistant" class="chat-footer">
293+
<el-footer v-if="computedMessages.length > 0 || !isCompletePage" class="chat-footer">
291294
<div class="input-wrapper" @click="clickInput">
292-
<div v-if="!isAssistant" class="datasource">
295+
<div v-if="isCompletePage" class="datasource">
293296
<template v-if="currentChat.datasource && currentChat.datasource_name">
294297
{{ t('qa.selected_datasource') }}:
295298
<img
@@ -311,7 +314,7 @@
311314
:disabled="isTyping"
312315
clearable
313316
class="input-area"
314-
:class="isAssistant && 'is-assistant'"
317+
:class="!isCompletePage && 'is-assistant'"
315318
type="textarea"
316319
:autosize="{ minRows: 1, maxRows: 8.583 }"
317320
:placeholder="t('qa.question_placeholder')"
@@ -334,7 +337,7 @@
334337
</el-footer>
335338
</el-container>
336339

337-
<ChatCreator v-if="!isAssistant" ref="chatCreatorRef" @on-chat-created="onChatCreatedQuick" />
340+
<ChatCreator v-if="isCompletePage" ref="chatCreatorRef" @on-chat-created="onChatCreatedQuick" />
338341
<ChatCreator ref="hiddenChatCreatorRef" hidden @on-chat-created="onChatCreatedQuick" />
339342
</el-container>
340343
</template>
@@ -384,7 +387,7 @@ const defaultFloatPopoverStyle = ref({
384387
borderRadius: '6px',
385388
})
386389
387-
const isAssistant = computed(() => assistantStore.getAssistant)
390+
const isCompletePage = computed(() => !assistantStore.getAssistant || assistantStore.getEmbedded)
388391
389392
const { t } = useI18n()
390393
@@ -479,7 +482,7 @@ const createNewChat = async () => {
479482
return
480483
}
481484
goEmpty()
482-
if (isAssistant.value) {
485+
if (!isCompletePage.value) {
483486
currentChat.value = new ChatInfo()
484487
currentChatId.value = undefined
485488
return
@@ -526,7 +529,7 @@ function onChatRenamed(chat: Chat) {
526529
527530
const chatListSideBarShow = ref<boolean>(true)
528531
function hideSideBar() {
529-
if (isAssistant.value) {
532+
if (!isCompletePage.value) {
530533
floatPopoverVisible.value = false
531534
return
532535
}
@@ -598,7 +601,7 @@ function onChatStop() {
598601
}
599602
const assistantPrepareSend = async () => {
600603
if (
601-
isAssistant.value &&
604+
!isCompletePage.value &&
602605
(currentChatId.value == null || typeof currentChatId.value == 'undefined')
603606
) {
604607
const assistantChat = await assistantStore.setChat()
@@ -821,12 +824,12 @@ function stop(func?: (...p: any[]) => void, ...param: any[]) {
821824
}
822825
}
823826
const showFloatPopover = () => {
824-
if (isAssistant.value && !floatPopoverVisible.value) {
827+
if (!isCompletePage.value && !floatPopoverVisible.value) {
825828
floatPopoverVisible.value = true
826829
}
827830
}
828831
const assistantPrepareInit = () => {
829-
if (!isAssistant.value) {
832+
if (isCompletePage.value) {
830833
return
831834
}
832835
Object.assign(defaultFloatPopoverStyle.value, {

0 commit comments

Comments
 (0)