diff --git a/backend/apps/chat/task/llm.py b/backend/apps/chat/task/llm.py index e4357989..e5ee344f 100644 --- a/backend/apps/chat/task/llm.py +++ b/backend/apps/chat/task/llm.py @@ -630,7 +630,8 @@ def run_task(llm_service: LLMService, in_chat: bool = True): brief = rename_chat(session=llm_service.session, rename_object=RenameChat(id=llm_service.get_record().chat_id, brief=llm_service.chat_question.question.strip()[:20])) - yield orjson.dumps({'type': 'brief', 'brief': brief}).decode() + '\n\n' + if in_chat: + yield orjson.dumps({'type': 'brief', 'brief': brief}).decode() + '\n\n' # select datasource if datasource is none if not llm_service.ds: diff --git a/frontend/src/assets/svg/icon_new_chat_outlined.svg b/frontend/src/assets/svg/icon_new_chat_outlined.svg new file mode 100644 index 00000000..c1ff4c6f --- /dev/null +++ b/frontend/src/assets/svg/icon_new_chat_outlined.svg @@ -0,0 +1,4 @@ + + + + diff --git a/frontend/src/i18n/en.json b/frontend/src/i18n/en.json index 3215fea2..8e3d6560 100644 --- a/frontend/src/i18n/en.json +++ b/frontend/src/i18n/en.json @@ -48,7 +48,7 @@ "chart_selected": "Selected {0}" }, "qa": { - "New Conversation": "New Conversation", + "new_chat": "New Chat", "title": "Smart Query", "placeholder": "Enter your question", "ask": "Ask", @@ -243,4 +243,4 @@ "back_community": "Restore to Community Edition", "confirm_tips": "Are you sure to restore to Community Edition?" } -} \ No newline at end of file +} diff --git a/frontend/src/i18n/zh-CN.json b/frontend/src/i18n/zh-CN.json index db07ccb3..56fb28da 100644 --- a/frontend/src/i18n/zh-CN.json +++ b/frontend/src/i18n/zh-CN.json @@ -51,7 +51,7 @@ "chart_selected": "已选{0}" }, "qa": { - "New Conversation": "开启新问数", + "new_chat": "新建对话", "title": "智能问数", "placeholder": "请输入您的问题", "ask": "提问", @@ -65,7 +65,12 @@ "view_more": "查看更多", "selected_datasource": "已选择数据源", "empty_datasource": "数据源为空,请新建后再开启智能问数!", - "datasource_not_exist": "数据源不存在" + "datasource_not_exist": "数据源不存在", + "guess_u_ask": "猜你想问:", + "continue_to_ask": "继续提问:", + "data_analysis": "数据预测", + "data_predict": "数据分析", + "chat_search": "搜索" }, "ds": { "title": "数据源", diff --git a/frontend/src/views/chat/ChatListContainer.vue b/frontend/src/views/chat/ChatListContainer.vue new file mode 100644 index 00000000..af3aca6f --- /dev/null +++ b/frontend/src/views/chat/ChatListContainer.vue @@ -0,0 +1,282 @@ + + + + + + + {{ t('qa.title') }} + + + + + + + + + + + {{ t('qa.new_chat') }} + + + + + + + + + + + + diff --git a/frontend/src/views/chat/ChatRecordFirst.vue b/frontend/src/views/chat/ChatRecordFirst.vue index 84839537..db8dba60 100644 --- a/frontend/src/views/chat/ChatRecordFirst.vue +++ b/frontend/src/views/chat/ChatRecordFirst.vue @@ -1,10 +1,7 @@ - + + + + diff --git a/frontend/src/views/chat/RecommendQuestion.vue b/frontend/src/views/chat/RecommendQuestion.vue index 9f3345cf..c8c19cfd 100644 --- a/frontend/src/views/chat/RecommendQuestion.vue +++ b/frontend/src/views/chat/RecommendQuestion.vue @@ -1,13 +1,16 @@ + + + + + {{ t('qa.data_analysis') }} + + + {{ t('qa.data_predict') }} + + {{ message?.content }} + + + + diff --git a/frontend/src/views/chat/index.vue b/frontend/src/views/chat/index.vue index 92706ceb..c363a12e 100644 --- a/frontend/src/views/chat/index.vue +++ b/frontend/src/views/chat/index.vue @@ -1,36 +1,51 @@ - - - - - 智能问数 - - - - - - - - - - - {{ t('qa.New Conversation') }} - - - - - - - + + + + + + + + + + + + + + + + + + + + + @@ -47,14 +62,21 @@ - {{ t('qa.New Conversation') }} + {{ t('qa.new_chat') }} - - + + + + - - - - - - - - - - - - - - - - + class="analysis-container" + > + + + + + + + + + + + + + + + + + + @@ -159,7 +183,7 @@ - + @@ -167,16 +191,17 @@ import { computed, nextTick, onMounted, ref } from 'vue' import { Plus, Position } from '@element-plus/icons-vue' import { Chat, chatApi, ChatInfo, type ChatMessage, ChatRecord, questionApi } from '@/api/chat' -import ChatList from './ChatList.vue' import ChatRow from './ChatRow.vue' import ChatAnswer from './ChatAnswer.vue' +import UserChat from './chat-block/UserChat.vue' import MdComponent from './component/MdComponent.vue' -// import PredictChartBlock from './component/PredictChartBlock.vue' import RecommendQuestion from './RecommendQuestion.vue' -import ChatCreator from './ChatCreator.vue' +import ChatListContainer from './ChatListContainer.vue' +import ChatCreator from '@/views/chat/ChatCreator.vue' import { useI18n } from 'vue-i18n' -import icon_sidebar_outlined from '@/assets/svg/icon_sidebar_outlined.svg' import { endsWith, find, startsWith } from 'lodash-es' +import icon_new_chat_outlined from '@/assets/svg/icon_new_chat_outlined.svg' +import icon_sidebar_outlined from '@/assets/svg/icon_sidebar_outlined.svg' import { useAssistantStore } from '@/stores/assistant' const assistantStore = useAssistantStore() @@ -219,6 +244,7 @@ const computedMessages = computed>(() => { messages.push({ role: 'user', create_time: record.create_time, + record: record, content: record.question, }) } @@ -236,13 +262,9 @@ const computedMessages = computed>(() => { }) const goEmpty = () => { - currentChat.value = new ChatInfo() - currentChatId.value = undefined inputMessage.value = '' } -const search = ref() - const createNewChat = async () => { goEmpty() if (isAssistant.value) { @@ -252,6 +274,7 @@ const createNewChat = async () => { } return } + console.log(chatCreatorRef.value) chatCreatorRef.value?.showDs() } @@ -268,70 +291,41 @@ function getChatList() { } function onClickHistory(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 - - scrollToBottom() - } - }) - .finally(() => { - loading.value = false - }) - } + console.log('click history', chat) + scrollToBottom() } function onChatDeleted(id: number) { - for (let i = 0; i < chatList.value.length; i++) { - if (chatList.value[i].id === id) { - chatList.value.splice(i, 1) - break - } - } - if (id === currentChatId.value) { - goEmpty() - } + console.log('deleted', id) } function onChatRenamed(chat: Chat) { - chatList.value.forEach((c: Chat) => { - if (c.id === chat.id) { - c.brief = chat.brief - } - }) - if (currentChat.value.id === chat.id) { - currentChat.value.brief = chat.brief - } + console.log('renamed', chat) } -function onChatCreated(chat: ChatInfo) { +const chatListSideBarShow = ref(true) +function hideSideBar() { + chatListSideBarShow.value = false +} + +function showSideBar() { + chatListSideBarShow.value = true +} + +function onChatCreatedQuick(chat: ChatInfo) { chatList.value.unshift(chat) currentChatId.value = chat.id currentChat.value = chat + onChatCreated(chat) +} + +function onChatCreated(chat: ChatInfo) { if (chat.records.length === 1) { getRecommendQuestions(chat.records[0].id) } } async function getRecommendQuestions(record_id?: number) { - /*chatApi.recommendQuestions(record_id).then((res) => { - if (res && res.length > 0 && startsWith(res.trim(), '[') && endsWith(res.trim(), ']')) { - if (currentChat.value?.records) { - for (let record of currentChat.value.records) { - if (record.id === record_id) { - record.recommended_question = res - } - } - } - } - })*/ const response = await chatApi.recommendQuestions(record_id) const reader = response.body.getReader() const decoder = new TextDecoder() @@ -827,6 +821,15 @@ defineExpose({