diff --git a/backend/apps/chat/task/llm.py b/backend/apps/chat/task/llm.py index 060bacc9..e5d3a083 100644 --- a/backend/apps/chat/task/llm.py +++ b/backend/apps/chat/task/llm.py @@ -296,7 +296,7 @@ class LLMService: # get schema if self.ds and not self.chat_question.db_schema: - self.chat_question.db_schema = get_table_schema(session=self.session, ds=self.ds) + self.chat_question.db_schema = get_table_schema(session=self.session, current_user=self.current_user, ds=self.ds) guess_msg: List[Union[BaseMessage, dict[str, Any]]] = [] 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): yield orjson.dumps({'id': llm_service.ds.id, 'datasource_name': llm_service.ds.name, 'engine_type': llm_service.ds.type_name, 'type': 'datasource'}).decode() + '\n\n' - llm_service.chat_question.db_schema = get_table_schema(session=llm_service.session, ds=llm_service.ds) + llm_service.chat_question.db_schema = get_table_schema(session=llm_service.session, current_user=llm_service.current_user, ds=llm_service.ds) # generate sql sql_res = llm_service.generate_sql() diff --git a/frontend/src/assets/svg/icon_new_chat_outlined.svg b/frontend/src/assets/svg/icon_new_chat_outlined.svg index c1ff4c6f..3bb65ed6 100644 --- a/frontend/src/assets/svg/icon_new_chat_outlined.svg +++ b/frontend/src/assets/svg/icon_new_chat_outlined.svg @@ -1,4 +1 @@ - - - - + \ No newline at end of file diff --git a/frontend/src/views/chat/index.vue b/frontend/src/views/chat/index.vue index 65446265..87f283ee 100644 --- a/frontend/src/views/chat/index.vue +++ b/frontend/src/views/chat/index.vue @@ -292,7 +292,7 @@ const createNewChat = async () => { if (isAssistant.value) { const assistantChat = await assistantStore.setChat() if (assistantChat) { - onChatCreated(assistantChat as any) + onChatCreatedQuick(assistantChat as any) } return } @@ -317,6 +317,26 @@ function onClickHistory(chat: Chat) { scrollToBottom() } +function toAssistantHistory(chat: Chat) { + currentChat.value = new ChatInfo(chat) + if (chat !== undefined && chat.id !== undefined && !loading.value) { + currentChatId.value = chat.id + loading.value = true + chatApi + .get(chat.id) + .then((res) => { + const info = chatApi.toChatInfo(res) + if (info) { + currentChat.value = info + onClickHistory(info) + } + }) + .finally(() => { + loading.value = false + }) + } +} + function onChatDeleted(id: number) { console.log('deleted', id) } @@ -434,11 +454,6 @@ const sendMessage = async () => { loading.value = true isTyping.value = true - /* const assistantChat = await assistantStore.setChat() - if (assistantChat) { - onChatCreated(assistantChat as any) - } */ - const currentRecord = new ChatRecord() currentRecord.create_time = new Date() currentRecord.chat_id = currentChatId.value @@ -833,10 +848,9 @@ const getCurrentChatId = () => { } defineExpose({ getHistoryList, - onClickHistory, - onChatDeleted, - onChatRenamed, + toAssistantHistory, getCurrentChatId, + createNewChat, }) diff --git a/frontend/src/views/embedded/assistant.vue b/frontend/src/views/embedded/assistant.vue index 1ee4d982..04316739 100644 --- a/frontend/src/views/embedded/assistant.vue +++ b/frontend/src/views/embedded/assistant.vue @@ -11,6 +11,9 @@
+ + + @@ -41,10 +44,10 @@ @click="onClickHistory(chat)" > {{ chat.brief ?? 'Untitled' }} -
+
@@ -58,8 +61,9 @@ import { onBeforeMount, ref } from 'vue' import ChatComponent from '@/views/chat/index.vue' import AssistantGif from '@/assets/img/assistant.gif' import history from '@/assets/svg/chart/history.svg' -import IconOpeEdit from '@/assets/svg/operate/ope-edit.svg' -import IconOpeDelete from '@/assets/svg/operate/ope-delete.svg' +import icon_new_chat_outlined from '@/assets/svg/icon_new_chat_outlined.svg' +/* import IconOpeEdit from '@/assets/svg/operate/ope-edit.svg' +import IconOpeDelete from '@/assets/svg/operate/ope-delete.svg' */ import { useRoute } from 'vue-router' import { assistantApi } from '@/api/assistant' import { useAssistantStore } from '@/stores/assistant' @@ -72,21 +76,24 @@ const chatList = ref>([]) const drawer = ref(false) const currentId = ref() +const createChat = () => { + chatRef.value?.createNewChat() +} const openHistory = () => { chatList.value = chatRef.value?.getHistoryList() currentId.value = chatRef.value?.getCurrentChatId() drawer.value = true } const onClickHistory = (chat: any) => { - chatRef.value?.onClickHistory(chat) + chatRef.value?.toAssistantHistory(chat) } -const EditPen = (chat: any) => { +/* const EditPen = (chat: any) => { chatRef.value?.onChatRenamed(chat) } const Delete = (chat: any) => { chatRef.value?.onChatDeleted(chat.id) -} +} */ const validator = ref({ id: '', valid: false, @@ -155,8 +162,13 @@ onBeforeMount(async () => { z-index: 2009; position: absolute; top: 16px; + display: flex; + column-gap: 16px; // right: 16px; font-size: 22px; + i:first-child { + color: var(--primary-color); + } } .sqlbot-history-container { width: 100%;