From 54e2cdf9530a7dd24868ebd9ceafe963ef8ac11c Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Thu, 21 Aug 2025 12:06:48 +0800 Subject: [PATCH 1/2] perf: Optimize embedded page style layout --- backend/apps/chat/curd/chat.py | 4 +- backend/apps/chat/task/llm.py | 11 +++--- backend/apps/system/crud/assistant.py | 2 +- frontend/src/stores/assistant.ts | 3 ++ frontend/src/views/chat/ChatListContainer.vue | 6 +-- frontend/src/views/chat/ErrorInfo.vue | 4 +- .../src/views/chat/chat-block/ChartBlock.vue | 8 ++-- frontend/src/views/chat/index.vue | 39 ++++++++++--------- 8 files changed, 42 insertions(+), 35 deletions(-) diff --git a/backend/apps/chat/curd/chat.py b/backend/apps/chat/curd/chat.py index b715b32e..0d48669d 100644 --- a/backend/apps/chat/curd/chat.py +++ b/backend/apps/chat/curd/chat.py @@ -95,7 +95,7 @@ def get_chat_with_records_with_data(session: SessionDep, chart_id: int, current_ current_assistant: CurrentAssistant) -> ChatInfo: return get_chat_with_records(session, chart_id, current_user, current_assistant, True) - +dynamic_ds_types = [1, 3] def get_chat_with_records(session: SessionDep, chart_id: int, current_user: CurrentUser, current_assistant: CurrentAssistant, with_data: bool = False) -> ChatInfo: chat = session.get(Chat, chart_id) @@ -104,7 +104,7 @@ def get_chat_with_records(session: SessionDep, chart_id: int, current_user: Curr chat_info = ChatInfo(**chat.model_dump()) - if current_assistant and current_assistant.type == 1: + if current_assistant and current_assistant.type in dynamic_ds_types: out_ds_instance = AssistantOutDsFactory.get_instance(current_assistant) ds = out_ds_instance.get_ds(chat.datasource) else: diff --git a/backend/apps/chat/task/llm.py b/backend/apps/chat/task/llm.py index b0b00bc7..10efb3e7 100644 --- a/backend/apps/chat/task/llm.py +++ b/backend/apps/chat/task/llm.py @@ -42,6 +42,7 @@ base_message_count_limit = 5 executor = ThreadPoolExecutor(max_workers=200) +dynamic_ds_types = [1, 3] class LLMService: ds: CoreDatasource @@ -79,7 +80,7 @@ class LLMService: if chat.datasource: # Get available datasource # ds = self.session.query(CoreDatasource).filter(CoreDatasource.id == chat.datasource).first() - if current_assistant and current_assistant.type == 1: + if current_assistant and current_assistant.type in dynamic_ds_types: self.out_ds_instance = AssistantOutDsFactory.get_instance(current_assistant) ds = self.out_ds_instance.get_ds(chat.datasource) if not ds: @@ -355,7 +356,7 @@ class LLMService: def select_datasource(self): datasource_msg: List[Union[BaseMessage, dict[str, Any]]] = [] datasource_msg.append(SystemMessage(self.chat_question.datasource_sys_question())) - if self.current_assistant: + if self.current_assistant and self.current_assistant.type != 4: _ds_list = get_assistant_ds(session=self.session, llm_service=self) else: oid: str = self.current_user.oid @@ -426,7 +427,7 @@ class LLMService: _datasource = data['id'] _chat = self.session.get(Chat, self.record.chat_id) _chat.datasource = _datasource - if self.current_assistant and self.current_assistant.type == 1: + if self.current_assistant and self.current_assistant.type in dynamic_ds_types: _ds = self.out_ds_instance.get_ds(data['id']) self.ds = _ds self.chat_question.engine = _ds.type @@ -851,7 +852,7 @@ class LLMService: # filter sql SQLBotLogUtil.info(full_sql_text) - use_dynamic_ds: bool = self.current_assistant and self.current_assistant.type == 1 + use_dynamic_ds: bool = self.current_assistant and self.current_assistant.type in dynamic_ds_types # todo row permission if (not self.current_assistant and is_normal_user(self.current_user)) or use_dynamic_ds: @@ -1037,7 +1038,7 @@ class LLMService: def validate_history_ds(self): _ds = self.ds - if not self.current_assistant: + if not self.current_assistant or self.current_assistant.type == 4: try: current_ds = self.session.get(CoreDatasource, _ds.id) if not current_ds: diff --git a/backend/apps/system/crud/assistant.py b/backend/apps/system/crud/assistant.py index 0699ec06..7b2c6fd8 100644 --- a/backend/apps/system/crud/assistant.py +++ b/backend/apps/system/crud/assistant.py @@ -32,7 +32,7 @@ def get_assistant_user(*, id: int): def get_assistant_ds(session: Session, llm_service) -> list[dict]: assistant: AssistantHeader = llm_service.current_assistant type = assistant.type - if type == 0: + if type == 0 or type == 2: configuration = assistant.configuration if configuration: config: dict[any] = json.loads(configuration) diff --git a/frontend/src/stores/assistant.ts b/frontend/src/stores/assistant.ts index 0c7c08fd..b85c5fed 100644 --- a/frontend/src/stores/assistant.ts +++ b/frontend/src/stores/assistant.ts @@ -57,6 +57,9 @@ export const AssistantStore = defineStore('assistant', { getOnline(): boolean { return this.online }, + getEmbedded(): boolean { + return this.assistant && this.type === 4 + }, }, actions: { refreshCertificate() { diff --git a/frontend/src/views/chat/ChatListContainer.vue b/frontend/src/views/chat/ChatListContainer.vue index 7aa0a8d4..550288ba 100644 --- a/frontend/src/views/chat/ChatListContainer.vue +++ b/frontend/src/views/chat/ChatListContainer.vue @@ -43,7 +43,7 @@ const emits = defineEmits([ ]) const assistantStore = useAssistantStore() -const isAssistant = computed(() => assistantStore.getAssistant) +const isCompletePage = computed(() => !assistantStore.getAssistant || assistantStore.getEmbedded) const search = ref() @@ -145,7 +145,7 @@ const createNewChat = async () => { } async function doCreateNewChat() { - if (isAssistant.value) { + if (!isCompletePage.value) { return } chatCreatorRef.value?.showDs() @@ -252,7 +252,7 @@ function onChatRenamed(chat: Chat) { /> - + diff --git a/frontend/src/views/chat/ErrorInfo.vue b/frontend/src/views/chat/ErrorInfo.vue index 0c95043e..37bd0b4d 100644 --- a/frontend/src/views/chat/ErrorInfo.vue +++ b/frontend/src/views/chat/ErrorInfo.vue @@ -10,7 +10,7 @@ const props = defineProps<{ const { t } = useI18n() const assistantStore = useAssistantStore() -const isAssistant = computed(() => assistantStore.getAssistant) +const isCompletePage = computed(() => !assistantStore.getAssistant || assistantStore.getEmbedded) const showBlock = computed(() => { return props.error && props.error?.trim().length > 0 @@ -54,7 +54,7 @@ function showTraceBack() { assistantStore.getAssistant) +const isCompletePage = computed(() => !assistantStore.getAssistant || assistantStore.getEmbedded) const chartId = computed(() => props.message?.record?.id + (props.enlarge ? '-fullscreen' : '')) @@ -409,7 +409,7 @@ watch( @@ -423,7 +423,7 @@ watch( @@ -473,7 +473,7 @@ watch( - +
-