diff --git a/backend/apps/chat/curd/chat.py b/backend/apps/chat/curd/chat.py
index 3f10f678..6369536d 100644
--- a/backend/apps/chat/curd/chat.py
+++ b/backend/apps/chat/curd/chat.py
@@ -1,10 +1,9 @@
import datetime
-import sqlparse
from typing import List
import orjson
-from sqlalchemy import and_
-from sqlalchemy.orm import load_only
+import sqlparse
+from sqlalchemy import and_, select
from apps.chat.models.chat_model import Chat, ChatRecord, CreateChat, ChatInfo, RenameChat, ChatQuestion
from apps.datasource.models.datasource import CoreDatasource
@@ -47,26 +46,29 @@ def delete_chat(session, chart_id) -> str:
def get_chat_chart_data(session: SessionDep, chart_record_id: int):
- res = session.query(ChatRecord).options(load_only(ChatRecord.data)).get(chart_record_id)
- if res:
+ stmt = select(ChatRecord.data).where(and_(ChatRecord.id == chart_record_id))
+ res = session.execute(stmt)
+ for row in res:
try:
- return orjson.loads(res.data)
+ return orjson.loads(row.data)
except Exception:
pass
return {}
def get_chat_predict_data(session: SessionDep, chart_record_id: int):
- res = session.query(ChatRecord).options(load_only(ChatRecord.predict_data)).get(chart_record_id)
- if res:
+ stmt = select(ChatRecord.predict_data).where(and_(ChatRecord.id == chart_record_id))
+ res = session.execute(stmt)
+ for row in res:
try:
- return orjson.loads(res.predict_data)
+ return orjson.loads(row.predict_data)
except Exception:
pass
- return ''
+ return {}
-def get_chat_with_records(session: SessionDep, chart_id: int, current_user: CurrentUser, current_assistant: CurrentAssistant) -> ChatInfo:
+def get_chat_with_records(session: SessionDep, chart_id: int, current_user: CurrentUser,
+ current_assistant: CurrentAssistant) -> ChatInfo:
chat = session.get(Chat, chart_id)
if not chat:
raise Exception(f"Chat with id {chart_id} not found")
@@ -78,7 +80,7 @@ def get_chat_with_records(session: SessionDep, chart_id: int, current_user: Curr
ds = out_ds_instance.get_ds(chat.datasource)
else:
ds = session.get(CoreDatasource, chat.datasource) if chat.datasource else None
-
+
if not ds:
chat_info.datasource_exists = False
chat_info.datasource_name = 'Datasource not exist'
@@ -87,14 +89,25 @@ def get_chat_with_records(session: SessionDep, chart_id: int, current_user: Curr
chat_info.datasource_name = ds.name
chat_info.ds_type = ds.type
- record_list = session.query(ChatRecord).options(
- load_only(ChatRecord.id, ChatRecord.chat_id, ChatRecord.create_time, ChatRecord.finish_time,
- ChatRecord.question, ChatRecord.sql_answer, ChatRecord.sql, ChatRecord.data,
+ stmt = select(ChatRecord.id, ChatRecord.chat_id, ChatRecord.create_time, ChatRecord.finish_time,
+ ChatRecord.question, ChatRecord.sql_answer, ChatRecord.sql,
ChatRecord.chart_answer, ChatRecord.chart, ChatRecord.analysis, ChatRecord.predict,
ChatRecord.datasource_select_answer, ChatRecord.analysis_record_id, ChatRecord.predict_record_id,
ChatRecord.recommended_question, ChatRecord.first_chat,
- ChatRecord.predict_data, ChatRecord.finish, ChatRecord.error)).filter(
- and_(Chat.create_by == current_user.id, ChatRecord.chat_id == chart_id)).order_by(ChatRecord.create_time).all()
+ ChatRecord.finish, ChatRecord.error).where(
+ and_(ChatRecord.create_by == current_user.id, ChatRecord.chat_id == chart_id)).order_by(ChatRecord.create_time)
+ result = session.execute(stmt).all()
+ record_list: list[ChatRecord] = []
+ for row in result:
+ record_list.append(
+ ChatRecord(id=row.id, chat_id=row.chat_id, create_time=row.create_time, finish_time=row.finish_time,
+ question=row.question, sql_answer=row.sql_answer, sql=row.sql,
+ chart_answer=row.chart_answer, chart=row.chart,
+ analysis=row.analysis, predict=row.predict,
+ datasource_select_answer=row.datasource_select_answer,
+ analysis_record_id=row.analysis_record_id, predict_record_id=row.predict_record_id,
+ recommended_question=row.recommended_question, first_chat=row.first_chat,
+ finish=row.finish, error=row.error))
result = list(map(format_record, record_list))
diff --git a/frontend/src/views/chat/answer/ChartAnswer.vue b/frontend/src/views/chat/answer/ChartAnswer.vue
index d87569fb..1a0f1c3e 100644
--- a/frontend/src/views/chat/answer/ChartAnswer.vue
+++ b/frontend/src/views/chat/answer/ChartAnswer.vue
@@ -1,7 +1,8 @@
+
diff --git a/frontend/src/views/chat/answer/PredictAnswer.vue b/frontend/src/views/chat/answer/PredictAnswer.vue
index 1bb339f8..8792138f 100644
--- a/frontend/src/views/chat/answer/PredictAnswer.vue
+++ b/frontend/src/views/chat/answer/PredictAnswer.vue
@@ -1,8 +1,9 @@
+
diff --git a/frontend/src/views/chat/chat-block/ChartBlock.vue b/frontend/src/views/chat/chat-block/ChartBlock.vue
index 35c75f83..13a6c8a6 100644
--- a/frontend/src/views/chat/chat-block/ChartBlock.vue
+++ b/frontend/src/views/chat/chat-block/ChartBlock.vue
@@ -81,19 +81,17 @@ const data = computed(() => {
}
}
} else {
- if (props.message?.record?.predict_data.length > 0) {
+ if (props.message?.record?.predict_data?.length > 0) {
_list = props.message?.record?.predict_data
}
}
-
if (_list.length == 0) {
return _list
}
- if (dataObject.value.data && dataObject.value.data.length > 0) {
+ if (dataObject.value.data && dataObject.value.data?.length > 0) {
return concat(dataObject.value.data, _list)
}
-
return _list
} else {
return dataObject.value.data
@@ -180,6 +178,10 @@ function onTypeChange(val: any) {
chartRef.value?.onTypeChange()
}
+function reloadChart() {
+ chartRef.value?.onTypeChange()
+}
+
const dialogVisible = ref(false)
function openFullScreen() {
@@ -274,6 +276,10 @@ function exportToImage() {
exportRef.value?.hide()
}
+defineExpose({
+ reloadChart,
+})
+
watch(
() => chartObject.value?.type,
(val) => {
diff --git a/frontend/src/views/chat/index.vue b/frontend/src/views/chat/index.vue
index 281a7134..8b989aad 100644
--- a/frontend/src/views/chat/index.vue
+++ b/frontend/src/views/chat/index.vue
@@ -160,7 +160,6 @@
@error="onChartAnswerError"
@stop="onChatStop"
>
-
@@ -265,7 +264,6 @@
@error="onPredictAnswerError"
@stop="onChatStop"
>
-
@@ -337,7 +335,6 @@ import ChartAnswer from './answer/ChartAnswer.vue'
import AnalysisAnswer from './answer/AnalysisAnswer.vue'
import PredictAnswer from './answer/PredictAnswer.vue'
import UserChat from './chat-block/UserChat.vue'
-import ChartBlock from './chat-block/ChartBlock.vue'
import RecommendQuestion from './RecommendQuestion.vue'
import ChatListContainer from './ChatListContainer.vue'
import ChatCreator from '@/views/chat/ChatCreator.vue'
@@ -345,7 +342,7 @@ import ErrorInfo from './ErrorInfo.vue'
import ChatToolBar from './ChatToolBar.vue'
import { dsTypeWithImg } from '@/views/ds/js/ds-type'
import { useI18n } from 'vue-i18n'
-import { find } from 'lodash-es'
+import { find, forEach } 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 icon_replace_outlined from '@/assets/svg/icon_replace_outlined.svg'
@@ -490,9 +487,14 @@ function getChatList(callback?: () => void) {
})
}
-function onClickHistory(chat: Chat) {
+function onClickHistory(chat: ChatInfo) {
scrollToBottom()
- console.debug('click history', chat)
+ forEach(chat?.records, (record: ChatRecord) => {
+ // getChatData(record.id)
+ if (record.predict_record_id) {
+ // getChatPredictData(record.id)
+ }
+ })
}
const currentChatEngineType = computed(() => {
@@ -629,16 +631,6 @@ const sendMessage = async ($event: any = {}) => {
})
}
-function getChatPredictData(recordId?: number) {
- chatApi.get_chart_predict_data(recordId).then((response) => {
- currentChat.value.records.forEach((record) => {
- if (record.id === recordId) {
- record.predict_data = response ?? []
- }
- })
- })
-}
-
const analysisAnswerRef = ref()
async function onAnalysisAnswerFinish(id: number) {
@@ -704,7 +696,7 @@ const predictAnswerRef = ref()
async function onPredictAnswerFinish(id: number) {
loading.value = false
isTyping.value = false
- getChatPredictData(id)
+ console.debug('onPredictAnswerFinish: ', id)
//await getRecommendQuestions(id)
}
function onPredictAnswerError() {