Skip to content

Commit 1b34bb8

Browse files
committed
feat: add query data limit in chat
1 parent f73388f commit 1b34bb8

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

backend/apps/chat/task/llm.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,9 +744,14 @@ def save_error(self, message: str):
744744
def save_sql_data(self, data_obj: Dict[str, Any]):
745745
try:
746746
data_result = data_obj.get('data')
747+
limit = 1000
747748
if data_result:
748749
data_result = prepare_for_orjson(data_result)
749-
data_obj['data'] = data_result
750+
if data_result and len(data_result) > limit:
751+
data_obj['data'] = data_result[:limit]
752+
data_obj['limit'] = limit
753+
else:
754+
data_obj['data'] = data_result
750755
return save_sql_exec_data(session=self.session, record_id=self.record.id,
751756
data=orjson.dumps(data_obj).decode())
752757
except Exception as e:

frontend/src/i18n/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@
541541
"thinking": "Thinking",
542542
"data_analysis": "Data Analysis",
543543
"data_predict": "Data Prediction",
544+
"data_over_limit": "The data is too large, only the first {0} entries are displayed.",
544545
"ds_is_invalid": "Datasource is invalid",
545546
"error": "Error",
546547
"no_data": "No Data",
@@ -602,4 +603,4 @@
602603
"setting_successfully": "Setting Successfully",
603604
"customize_theme_color": "Customize theme color"
604605
}
605-
}
606+
}

frontend/src/i18n/zh-CN.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@
541541
"thinking": "思考中",
542542
"data_analysis": "数据分析",
543543
"data_predict": "数据预测",
544+
"data_over_limit": "数据量过大,仅展示前{0}条数据",
544545
"ds_is_invalid": "数据源无效",
545546
"error": "错误",
546547
"no_data": "暂无数据",
@@ -602,4 +603,4 @@
602603
"setting_successfully": "设置成功",
603604
"customize_theme_color": "自定义主题色"
604605
}
605-
}
606+
}

frontend/src/views/chat/chat-block/ChartBlock.vue

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const emits = defineEmits(['exitFullScreen'])
4949
const dataObject = computed<{
5050
fields: Array<string>
5151
data: Array<{ [key: string]: any }>
52+
limit: number | undefined
5253
}>(() => {
5354
if (props.message?.record?.data) {
5455
if (typeof props.message?.record?.data === 'string') {
@@ -423,15 +424,20 @@ watch(
423424
</div>
424425
</div>
425426

426-
<div v-if="message?.record?.chart" class="chart-block">
427-
<DisplayChartBlock
428-
:id="chartId"
429-
ref="chartRef"
430-
:chart-type="chartType"
431-
:message="message"
432-
:data="data"
433-
/>
434-
</div>
427+
<template v-if="message?.record?.chart">
428+
<div class="chart-block">
429+
<DisplayChartBlock
430+
:id="chartId"
431+
ref="chartRef"
432+
:chart-type="chartType"
433+
:message="message"
434+
:data="data"
435+
/>
436+
</div>
437+
<div v-if="dataObject.limit" class="over-limit-hint">
438+
{{ t('chat.data_over_limit', [dataObject.limit]) }}
439+
</div>
440+
</template>
435441

436442
<AddViewDashboard ref="addViewRef"></AddViewDashboard>
437443
<el-dialog
@@ -712,6 +718,11 @@ watch(
712718
713719
margin-top: 16px;
714720
}
721+
.over-limit-hint {
722+
min-height: 24px;
723+
line-height: 24px;
724+
font-size: 14px;
725+
}
715726
}
716727
717728
.sql-block {

0 commit comments

Comments
 (0)