Skip to content

Commit 3217546

Browse files
committed
Merge remote-tracking branch 'origin/main'
# Conflicts: # frontend/src/views/dashboard/utils/canvasUtils.ts
2 parents 8fd76c4 + 367e4af commit 3217546

File tree

22 files changed

+484
-70
lines changed

22 files changed

+484
-70
lines changed

backend/apps/ai_model/model_factory.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def _init_llm(self) -> LangchainBaseLLM:
4141
model=self.config.model_name,
4242
api_key=self.config.api_key,
4343
base_url=self.config.api_base_url,
44+
stream_usage=True,
4445
**self.config.additional_params
4546
)
4647

backend/apps/chat/api/chat.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ async def stream_sql(session: SessionDep, current_user: CurrentUser, request_que
118118

119119
def run_task():
120120
try:
121+
# return id
122+
yield json.dumps({'type': 'id', 'id': llm_service.get_record().id}) + '\n\n'
123+
121124
# generate sql
122125
sql_res = llm_service.generate_sql(session=session)
123126
full_sql_text = ''

backend/apps/chat/task/llm.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ def init_record(self, session: SessionDep, current_user: CurrentUser) -> ChatRec
105105
self.record = save_question(session=session, current_user=current_user, question=self.chat_question)
106106
return self.record
107107

108+
def get_record(self):
109+
return self.record
110+
108111
def generate_sql(self, session: SessionDep):
109112
# append current question
110113
self.sql_message.append(HumanMessage(self.chat_question.sql_user_question()))

backend/template.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ template:
3434
{question}
3535
3636
### 其他规则:
37-
请使用英语(English)回答
37+
请使用英语(English)输出
3838
{rule}
3939
chart:
4040
system: |
@@ -51,7 +51,7 @@ template:
5151
{{"type":"line", "title": "标题", "axis": {{"x": {{"name":"x轴的中文名称","value": "x轴的SQL查询列(有别名用别名)"}}, "y": {{"name":"y轴的中文名称","value": "y轴的SQL查询列(有别名用别名)"}}}}
5252
其中“x”和“y”必须从SQL查询列中提取。
5353
- 如果需要饼图,则生成的 JSON 格式应为:
54-
{{"type":"pie", "title": "标题", "column": [{{"name":"中文字段名1","value":"SQL查询列1(有别名用别名)"}},{{"name":"中文字段名2","value":"SQL查询列2(有别名用别名)"}}]}}
54+
{{"type":"pie", "title": "标题", "columns": [{{"name":"中文字段名1","value":"SQL查询列1(有别名用别名)"}},{{"name":"中文字段名2","value":"SQL查询列2(有别名用别名)"}}]}}
5555
其中“column”必须从SQL查询列中提取。
5656
- 如果答案未知或者与生成JSON无关,则生成的 JSON 格式应为:
5757
{{"type":"error", "reason": "抱歉,我无法回答您的问题。"}}
@@ -80,5 +80,5 @@ template:
8080
{question}
8181
8282
### 其他规则:
83-
请使用英语(English)回答
83+
请使用英语(English)输出
8484
{rule}

frontend/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
"preview": "vite preview"
1010
},
1111
"dependencies": {
12+
"@antv/g2": "^5.3.3",
1213
"@npkg/tinymce-plugins": "^0.0.7",
1314
"@tinymce/tinymce-vue": "^5.1.0",
1415
"dayjs": "^1.11.13",
15-
"element-plus": "^2.9.11",
16+
"element-plus-secondary": "^1.0.0",
1617
"lodash": "^4.17.21",
1718
"snowflake-id": "^1.1.0",
1819
"tinymce": "^5.8.2",
1920
"vue": "^3.5.13",
21+
"vue-i18n": "^9.14.4",
2022
"vue-router": "^4.5.0",
2123
"web-storage-cache": "^1.1.1"
2224
},
@@ -28,7 +30,6 @@
2830
"@vue/tsconfig": "^0.7.0",
2931
"axios": "^1.8.4",
3032
"crypto-js": "^4.2.0",
31-
"element-plus-secondary": "^1.0.0",
3233
"less": "^4.3.0",
3334
"pinia": "^3.0.2",
3435
"typescript": "~5.7.2",

frontend/src/App.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
<script setup lang="ts">
2+
import { computed } from 'vue'
3+
import { ElConfigProvider } from 'element-plus-secondary'
4+
import { getElementLocale } from '@/i18n'
5+
const elLanguage = computed(() => {
6+
return getElementLocale()
7+
})
28
</script>
39

410
<template>
5-
<router-view />
11+
<el-config-provider :locale="elLanguage">
12+
<router-view />
13+
</el-config-provider>
614
</template>
715

816
<style scoped>

frontend/src/components/layout/index.vue

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343

4444
<div v-else class="top-bar-title">
4545
<span class="split"/>
46-
<span>System manage</span>
46+
<!-- <span>System manage</span> -->
47+
<span>{{ t('common.system_manage') }}</span>
4748
</div>
4849

4950

@@ -76,6 +77,21 @@
7677
<el-dropdown-menu>
7778
<el-dropdown-item @click="switchLayout">Switch Layout</el-dropdown-item>
7879
<el-dropdown-item @click="logout">Logout</el-dropdown-item>
80+
81+
<el-dropdown @command="changeLanguage">
82+
<div class="lang-switch">
83+
Language
84+
<el-icon>
85+
<i class="el-icon-arrow-down"/>
86+
</el-icon>
87+
</div>
88+
<template #dropdown>
89+
<el-dropdown-menu>
90+
<el-dropdown-item command="en">English</el-dropdown-item>
91+
<el-dropdown-item command="zh-CN">中文</el-dropdown-item>
92+
</el-dropdown-menu>
93+
</template>
94+
</el-dropdown>
7995
</el-dropdown-menu>
8096
</template>
8197
</el-dropdown>
@@ -153,7 +169,9 @@ import icon_user from '@/assets/svg/icon_user.svg'
153169
import icon_ai from '@/assets/svg/icon_ai.svg'
154170
import {ArrowLeftBold} from '@element-plus/icons-vue'
155171
import {useCache} from '@/utils/useCache'
172+
import { useI18n } from 'vue-i18n'
156173
174+
const { locale, t } = useI18n()
157175
const {wsCache} = useCache()
158176
const topLayout = ref(false)
159177
const router = useRouter()
@@ -215,6 +233,10 @@ const switchLayout = () => {
215233
topLayout.value = !topLayout.value
216234
wsCache.set('sqlbot-topbar-layout', topLayout.value)
217235
}
236+
237+
const changeLanguage = (lang: string) => {
238+
locale.value = lang
239+
}
218240
onMounted(() => {
219241
topLayout.value = wsCache.get('sqlbot-topbar-layout') || true
220242
})
@@ -536,4 +558,12 @@ onMounted(() => {
536558
}
537559
}
538560
}
561+
.lang-switch {
562+
cursor: pointer;
563+
padding: 0 12px;
564+
565+
&:hover {
566+
color: var(--el-color-primary);
567+
}
568+
}
539569
</style>

frontend/src/i18n/en.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"menu": {
3+
"dashboard": "Dashboard",
4+
"chat": "Chat",
5+
"datasource": "Data Source",
6+
"system": "System"
7+
},
8+
"common": {
9+
"back": "Back",
10+
"confirm": "Confirm",
11+
"cancel": "Cancel",
12+
"system_manage": "System Management"
13+
}
14+
}

frontend/src/i18n/index.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { createI18n } from 'vue-i18n'
2+
import en from './en.json'
3+
import zhCN from './zh-CN.json'
4+
import elementEnLocale from 'element-plus/es/locale/lang/en'
5+
import elementZhLocale from 'element-plus/es/locale/lang/zh-cn'
6+
7+
const getDefaultLocale = () => {
8+
/* const savedLang = localStorage.getItem('lang')
9+
return savedLang || 'zh-CN' */
10+
return 'zh-CN'
11+
}
12+
13+
const messages = {
14+
en: {
15+
...en,
16+
el: elementEnLocale
17+
},
18+
'zh-CN': {
19+
...zhCN,
20+
el: elementZhLocale
21+
}
22+
}
23+
24+
export const i18n = createI18n({
25+
legacy: false,
26+
locale: getDefaultLocale(),
27+
fallbackLocale: 'en',
28+
globalInjection: true,
29+
messages
30+
})
31+
32+
export const getElementLocale = () => {
33+
return i18n.global.locale.value === 'en' ? elementEnLocale : elementZhLocale
34+
}

frontend/src/i18n/zh-CN.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"menu": {
3+
"dashboard": "仪表盘",
4+
"chat": "聊天",
5+
"datasource": "数据源",
6+
"system": "系统"
7+
},
8+
"common": {
9+
"back": "返回",
10+
"confirm": "确认",
11+
"cancel": "取消",
12+
"system_manage": "系统管理"
13+
}
14+
}

0 commit comments

Comments
 (0)