diff --git a/backend/apps/chat/curd/chat.py b/backend/apps/chat/curd/chat.py index 1310b669..c8b4948b 100644 --- a/backend/apps/chat/curd/chat.py +++ b/backend/apps/chat/curd/chat.py @@ -1,4 +1,5 @@ import datetime +import sqlparse from typing import List import orjson @@ -128,6 +129,12 @@ def format_record(record: ChatRecord): _dict['predict_data'] = _obj except Exception: pass + if record.sql and record.sql.strip() != '': + try: + _dict['sql'] = sqlparse.format(record.sql, reindent=True) + except Exception: + pass + return _dict diff --git a/backend/pyproject.toml b/backend/pyproject.toml index 76926eb8..1c69d48e 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -38,6 +38,7 @@ dependencies = [ "tabulate>=0.9.0", "sqlbot-xpack==0.0.3.5", "fastapi-cache2>=0.2.2", + "sqlparse>=0.5.3", ] [[tool.uv.index]] name = "default" diff --git a/frontend/src/utils/markdown.ts b/frontend/src/utils/markdown.ts index 817f431d..f799b425 100644 --- a/frontend/src/utils/markdown.ts +++ b/frontend/src/utils/markdown.ts @@ -11,7 +11,7 @@ const md = new MarkdownIt({ if (lang && hljs.getLanguage(lang)) { try { return `
-                  ${hljs.highlight(str, { language: lang, ignoreIllegals: true }).value}
+                  
${hljs.highlight(str, { language: lang, ignoreIllegals: true }).value}
` } catch (e) { console.error(e) diff --git a/frontend/src/views/chat/chat-block/ChartBlock.vue b/frontend/src/views/chat/chat-block/ChartBlock.vue index 6f9d225d..18f777fc 100644 --- a/frontend/src/views/chat/chat-block/ChartBlock.vue +++ b/frontend/src/views/chat/chat-block/ChartBlock.vue @@ -15,7 +15,7 @@ import icon_into_item_outlined from '@/assets/svg/icon_into-item_outlined.svg' import icon_window_max_outlined from '@/assets/svg/icon_window-max_outlined.svg' import icon_window_mini_outlined from '@/assets/svg/icon_window-mini_outlined.svg' import { useI18n } from 'vue-i18n' -import MdComponent from '@/views/chat/component/MdComponent.vue' +import SQLComponent from '@/views/chat/component/SQLComponent.vue' const props = withDefaults( defineProps<{ @@ -324,8 +324,9 @@ function addToDashboard() { body-class="chart-sql-drawer-body" >
-
diff --git a/frontend/src/views/chat/component/SQLComponent.vue b/frontend/src/views/chat/component/SQLComponent.vue new file mode 100644 index 00000000..02b1c4e1 --- /dev/null +++ b/frontend/src/views/chat/component/SQLComponent.vue @@ -0,0 +1,29 @@ + + + + +