Skip to content

Commit 2be094a

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 1c8e768 + 707bde7 commit 2be094a

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed

backend/apps/chat/curd/chat.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
import sqlparse
23
from typing import List
34

45
import orjson
@@ -128,6 +129,12 @@ def format_record(record: ChatRecord):
128129
_dict['predict_data'] = _obj
129130
except Exception:
130131
pass
132+
if record.sql and record.sql.strip() != '':
133+
try:
134+
_dict['sql'] = sqlparse.format(record.sql, reindent=True)
135+
except Exception:
136+
pass
137+
131138
return _dict
132139

133140

backend/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ dependencies = [
3838
"tabulate>=0.9.0",
3939
"sqlbot-xpack==0.0.3.5",
4040
"fastapi-cache2>=0.2.2",
41+
"sqlparse>=0.5.3",
4142
]
4243
[[tool.uv.index]]
4344
name = "default"

frontend/src/utils/markdown.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const md = new MarkdownIt({
1111
if (lang && hljs.getLanguage(lang)) {
1212
try {
1313
return `<pre class="hljs">
14-
<code>${hljs.highlight(str, { language: lang, ignoreIllegals: true }).value}</code>
14+
<div>${hljs.highlight(str, { language: lang, ignoreIllegals: true }).value}</div>
1515
</pre>`
1616
} catch (e) {
1717
console.error(e)

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import icon_into_item_outlined from '@/assets/svg/icon_into-item_outlined.svg'
1515
import icon_window_max_outlined from '@/assets/svg/icon_window-max_outlined.svg'
1616
import icon_window_mini_outlined from '@/assets/svg/icon_window-mini_outlined.svg'
1717
import { useI18n } from 'vue-i18n'
18-
import MdComponent from '@/views/chat/component/MdComponent.vue'
18+
import SQLComponent from '@/views/chat/component/SQLComponent.vue'
1919
2020
const props = withDefaults(
2121
defineProps<{
@@ -324,8 +324,9 @@ function addToDashboard() {
324324
body-class="chart-sql-drawer-body"
325325
>
326326
<div>
327-
<MdComponent
328-
:message="'```sql\n' + message.record?.sql + '\n```'"
327+
<SQLComponent
328+
v-if="message.record?.sql"
329+
:sql="message.record?.sql"
329330
style="margin-top: 12px"
330331
/>
331332
</div>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<script setup lang="ts">
2+
import 'highlight.js/styles/github.min.css'
3+
import 'github-markdown-css/github-markdown-light.css'
4+
import hljs from 'highlight.js'
5+
6+
defineProps<{
7+
sql: string
8+
}>()
9+
</script>
10+
11+
<template>
12+
<pre class="hljs">
13+
<div
14+
v-dompurify-html="hljs.highlight(sql, { language: 'sql', ignoreIllegals: true }).value"
15+
></div>
16+
</pre>
17+
</template>
18+
19+
<style lang="less">
20+
.hljs {
21+
overflow: auto;
22+
padding: 1rem;
23+
display: block;
24+
25+
background: rgba(245, 246, 247, 1);
26+
border: 1px solid rgba(222, 224, 227, 1);
27+
border-radius: 6px;
28+
}
29+
</style>

0 commit comments

Comments
 (0)