Skip to content

Commit a5ab618

Browse files
committed
Merge branch 'main' of https://github.com/dataease/SQLBot
2 parents 13a7f42 + 71bb6a8 commit a5ab618

File tree

9 files changed

+43
-36
lines changed

9 files changed

+43
-36
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)

backend/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ dependencies = [
4444
"python-calamine>=0.4.0",
4545
"xlrd>=2.0.2",
4646
"clickhouse-sqlalchemy>=0.3.2",
47-
"dmpython>=2.5.22",
47+
"dmpython>=2.5.22; platform_system != 'Darwin'",
4848
]
4949
[[tool.uv.index]]
5050
name = "default"

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"
@@ -138,7 +138,10 @@
138138
<div
139139
ref="innerRef"
140140
class="chat-scroll"
141-
:class="{ 'no-sidebar': !isAssistant && !chatListSideBarShow, pad16: isAssistant }"
141+
:class="{
142+
'no-sidebar': isCompletePage && !chatListSideBarShow,
143+
pad16: !isCompletePage,
144+
}"
142145
>
143146
<template v-for="(message, _index) in computedMessages" :key="_index">
144147
<ChatRow :current-chat="currentChat" :msg="message" :hide-avatar="message.first_chat">
@@ -293,9 +296,9 @@
293296
</div>
294297
</el-scrollbar>
295298
</el-main>
296-
<el-footer v-if="computedMessages.length > 0 || isAssistant" class="chat-footer">
299+
<el-footer v-if="computedMessages.length > 0 || !isCompletePage" class="chat-footer">
297300
<div class="input-wrapper" @click="clickInput">
298-
<div v-if="!isAssistant" class="datasource">
301+
<div v-if="isCompletePage" class="datasource">
299302
<template v-if="currentChat.datasource && currentChat.datasource_name">
300303
{{ t('qa.selected_datasource') }}:
301304
<img
@@ -317,7 +320,7 @@
317320
:disabled="isTyping"
318321
clearable
319322
class="input-area"
320-
:class="isAssistant && 'is-assistant'"
323+
:class="!isCompletePage && 'is-assistant'"
321324
type="textarea"
322325
:autosize="{ minRows: 1, maxRows: 8.583 }"
323326
:placeholder="t('qa.question_placeholder')"
@@ -340,7 +343,7 @@
340343
</el-footer>
341344
</el-container>
342345

343-
<ChatCreator v-if="!isAssistant" ref="chatCreatorRef" @on-chat-created="onChatCreatedQuick" />
346+
<ChatCreator v-if="isCompletePage" ref="chatCreatorRef" @on-chat-created="onChatCreatedQuick" />
344347
<ChatCreator ref="hiddenChatCreatorRef" hidden @on-chat-created="onChatCreatedQuick" />
345348
</el-container>
346349
</template>
@@ -390,7 +393,7 @@ const defaultFloatPopoverStyle = ref({
390393
borderRadius: '6px',
391394
})
392395
393-
const isAssistant = computed(() => assistantStore.getAssistant)
396+
const isCompletePage = computed(() => !assistantStore.getAssistant || assistantStore.getEmbedded)
394397
395398
const { t } = useI18n()
396399
@@ -527,7 +530,7 @@ const createNewChat = async () => {
527530
return
528531
}
529532
goEmpty()
530-
if (isAssistant.value) {
533+
if (!isCompletePage.value) {
531534
currentChat.value = new ChatInfo()
532535
currentChatId.value = undefined
533536
return
@@ -574,7 +577,7 @@ function onChatRenamed(chat: Chat) {
574577
575578
const chatListSideBarShow = ref<boolean>(true)
576579
function hideSideBar() {
577-
if (isAssistant.value) {
580+
if (!isCompletePage.value) {
578581
floatPopoverVisible.value = false
579582
return
580583
}
@@ -646,7 +649,7 @@ function onChatStop() {
646649
}
647650
const assistantPrepareSend = async () => {
648651
if (
649-
isAssistant.value &&
652+
!isCompletePage.value &&
650653
(currentChatId.value == null || typeof currentChatId.value == 'undefined')
651654
) {
652655
const assistantChat = await assistantStore.setChat()
@@ -873,12 +876,12 @@ function stop(func?: (...p: any[]) => void, ...param: any[]) {
873876
}
874877
}
875878
const showFloatPopover = () => {
876-
if (isAssistant.value && !floatPopoverVisible.value) {
879+
if (!isCompletePage.value && !floatPopoverVisible.value) {
877880
floatPopoverVisible.value = true
878881
}
879882
}
880883
const assistantPrepareInit = () => {
881-
if (!isAssistant.value) {
884+
if (isCompletePage.value) {
882885
return
883886
}
884887
Object.assign(defaultFloatPopoverStyle.value, {

0 commit comments

Comments
 (0)