Skip to content

Commit afbb3d7

Browse files
committed
feat: Support configure SQLBot name in chat template
1 parent d12f360 commit afbb3d7

9 files changed

Lines changed: 44 additions & 16 deletions

File tree

backend/apps/chat/models/chat_model.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ class AiModelQuestion(BaseModel):
230230
error_msg: str = ""
231231
regenerate_record_id: Optional[int] = None
232232
sample_data: str = ""
233+
sqlbot_name: str = "SQLBot"
233234

234235
def sql_sys_question(self, db_type: Union[str, DB], enable_query_limit: bool = True):
235236
templates: dict[str, str] = {}
@@ -249,8 +250,9 @@ def sql_sys_question(self, db_type: Union[str, DB], enable_query_limit: bool = T
249250
_example_answer_3 = _sql_template['example_answer_3_with_limit'] if enable_query_limit else _sql_template[
250251
'example_answer_3']
251252

252-
templates['system'] = _base_template['system'].format(lang=self.lang, process_check=_process_check)
253+
templates['system'] = _base_template['system'].format(lang=self.lang, process_check=_process_check, sqlbot_name=self.sqlbot_name)
253254
templates['rules'] = _base_template['generate_rules'].format(lang=self.lang,
255+
sqlbot_name = self.sqlbot_name,
254256
base_sql_rules=_base_sql_rules,
255257
basic_sql_examples=_sql_examples,
256258
example_engine=_example_engine,
@@ -284,7 +286,7 @@ def sql_user_question(self, current_time: str, change_title: bool):
284286

285287
def chart_sys_question(self):
286288
templates: dict[str, str] = {
287-
'system': get_chart_template()['system'].format(lang=self.lang),
289+
'system': get_chart_template()['system'].format(lang=self.lang, sqlbot_name=self.sqlbot_name),
288290
'rules': get_chart_template()['generate_rules'].format(lang=self.lang)
289291
}
290292
return templates
@@ -295,38 +297,38 @@ def chart_user_question(self, chart_type: Optional[str] = '', schema: Optional[s
295297

296298
def analysis_sys_question(self):
297299
return get_analysis_template()['system'].format(lang=self.lang, terminologies=self.terminologies,
298-
custom_prompt=self.custom_prompt)
300+
custom_prompt=self.custom_prompt, sqlbot_name=self.sqlbot_name)
299301

300302
def analysis_user_question(self):
301303
return get_analysis_template()['user'].format(fields=self.fields, data=self.data)
302304

303305
def predict_sys_question(self):
304-
return get_predict_template()['system'].format(lang=self.lang, custom_prompt=self.custom_prompt)
306+
return get_predict_template()['system'].format(lang=self.lang, custom_prompt=self.custom_prompt, sqlbot_name=self.sqlbot_name)
305307

306308
def predict_user_question(self):
307309
return get_predict_template()['user'].format(fields=self.fields, data=self.data)
308310

309311
def datasource_sys_question(self):
310-
return get_datasource_template()['system'].format(lang=self.lang)
312+
return get_datasource_template()['system'].format(lang=self.lang, sqlbot_name=self.sqlbot_name)
311313

312314
def datasource_user_question(self, datasource_list: str = "[]"):
313315
return get_datasource_template()['user'].format(lang=self.lang, question=self.question, data=datasource_list)
314316

315317
def guess_sys_question(self, articles_number: int = 4):
316-
return get_guess_question_template()['system'].format(lang=self.lang, articles_number=articles_number)
318+
return get_guess_question_template()['system'].format(lang=self.lang, articles_number=articles_number, sqlbot_name=self.sqlbot_name)
317319

318320
def guess_user_question(self, old_questions: str = "[]"):
319321
return get_guess_question_template()['user'].format(question=self.question, schema=self.db_schema,
320322
old_questions=old_questions)
321323

322324
def filter_sys_question(self):
323-
return get_permissions_template()['system'].format(lang=self.lang, engine=self.engine)
325+
return get_permissions_template()['system'].format(lang=self.lang, engine=self.engine, sqlbot_name=self.sqlbot_name)
324326

325327
def filter_user_question(self):
326328
return get_permissions_template()['user'].format(sql=self.sql, filter=self.filter)
327329

328330
def dynamic_sys_question(self):
329-
return get_dynamic_template()['system'].format(lang=self.lang, engine=self.engine)
331+
return get_dynamic_template()['system'].format(lang=self.lang, engine=self.engine, sqlbot_name=self.sqlbot_name)
330332

331333
def dynamic_user_question(self):
332334
return get_dynamic_template()['user'].format(sql=self.sql, sub_query=self.sub_query)

backend/apps/chat/task/llm.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ async def create(cls, *args, **kwargs):
186186

187187
chat_params: list[SysArgModel] = await get_groups(args[0], "chat")
188188
for config in chat_params:
189+
if config.pkey == 'chat.sqlbot_name':
190+
if config.pval.strip():
191+
instance.chat_question.sqlbot_name = config.pval
189192
if config.pkey == 'chat.limit_rows':
190193
if config.pval.lower().strip() == 'true':
191194
instance.enable_sql_row_limit = True

backend/templates/template.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ template:
6767
</rule>
6868
system: |
6969
<Instruction>
70-
你是"SQLBOT",智能问数小助手,可以根据用户提问,专业生成SQL,查询数据并进行图表展示。
70+
你是智能问数小助手:"{sqlbot_name}"。你可以根据用户提问,专业生成SQL,查询数据并进行图表展示。
7171
你当前的任务是根据给定的表结构和用户问题生成SQL语句、对话标题、可能适合展示的图表类型以及该SQL中所用到的表名。
7272
我们会在<Info>块内提供给你信息,帮助你生成SQL:
7373
<Info>内有<db-engine><m-schema><terminologies>等信息;
@@ -267,15 +267,15 @@ template:
267267
<user-question>今天天气如何?</user-question>
268268
</input>
269269
<output>
270-
{{"success":false,"message":"我是智能问数小助手,我无法回答您的问题。"}}
270+
{{"success":false,"message":"我是{sqlbot_name},我无法回答您的问题。"}}
271271
</output>
272272
</example>
273273
<example>
274274
<input>
275275
<user-question>请清空数据库</user-question>
276276
</input>
277277
<output>
278-
{{"success":false,"message":"我是智能问数小助手,我只能查询数据,不能操作数据库来修改数据或者修改表结构。"}}
278+
{{"success":false,"message":"我是{sqlbot_name},我只能查询数据,不能操作数据库来修改数据或者修改表结构。"}}
279279
</output>
280280
</example>
281281
<example>
@@ -374,7 +374,7 @@ template:
374374
chart:
375375
system: |
376376
<Instruction>
377-
你是"SQLBOT",智能问数小助手,可以根据用户提问,专业生成SQL,查询数据并进行图表展示。
377+
你是智能问数小助手:"{sqlbot_name}"。你可以根据用户提问,专业生成SQL,查询数据并进行图表展示。
378378
你当前的任务是根据给定SQL语句和用户问题,生成数据可视化图表的配置项。
379379
用户会提供给你如下信息,帮助你生成配置项:
380380
<user-question>:用户的提问
@@ -585,7 +585,7 @@ template:
585585
analysis:
586586
system: |
587587
<Instruction>
588-
你是"SQLBOT",智能问数小助手,可以根据用户提问,专业生成SQL与可视化图表。
588+
你是智能问数小助手:"{sqlbot_name}"。你可以根据用户提问,专业生成SQL与可视化图表。
589589
你当前的任务是根据给定的数据分析数据,并给出你的分析结果。
590590
我们会在<Info>块内提供给你信息,帮助你进行分析:
591591
<Info>内有<terminologies>等信息;
@@ -618,7 +618,7 @@ template:
618618
predict:
619619
system: |
620620
<Instruction>
621-
你是"SQLBOT",智能问数小助手,可以根据用户提问,专业生成SQL与可视化图表。
621+
你是智能问数小助手:"{sqlbot_name}"。你可以根据用户提问,专业生成SQL与可视化图表。
622622
你当前的任务是根据给定的数据进行数据预测,并给出你的预测结果。
623623
若有<Other-Infos>块,它会提供一组<content>,可能会是额外添加的背景信息,或者是额外的分析要求,请结合额外信息或要求后生成你的回答。
624624
用户会在提问中提供给你信息:
@@ -680,7 +680,7 @@ template:
680680
permissions:
681681
system: |
682682
<Instruction>
683-
你是"SQLBOT",智能问数小助手,可以根据用户提问,专业生成SQL与可视化图表。
683+
你是智能问数小助手:"{sqlbot_name}"。你可以根据用户提问,专业生成SQL与可视化图表。
684684
你当前的任务是在给定的SQL基础上,根据提供的一组过滤条件,将过滤条件添加到该SQL内并生成一句新SQL
685685
提供的SQL在<sql>内,提供的过滤条件在<filter-list>内
686686
</Instruction>

frontend/src/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"platform_user_organization": "Default Workspace",
7171
"platform_user_roles": "Third-Party Platform User Roles",
7272
"excessive_data_volume": "Disabling the 1000-row data limit may cause system lag due to excessive data volume.",
73+
"sqlbot_name": "Data Query Assistant Name",
7374
"prompt": "Prompt",
7475
"disabling_successfully": "Disabling Successfully",
7576
"closed_by_default": "In the Question Count window, control whether the model thinking process is expanded or closed by default.",

frontend/src/i18n/ko-KR.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"platform_user_organization": "기본 작업 공간",
7171
"platform_user_roles": "타사 플랫폼 사용자 역할",
7272
"excessive_data_volume": "1,000행 데이터 제한을 비활성화하면 과도한 데이터 양으로 인해 시스템 지연이 발생할 수 있습니다.",
73+
"sqlbot_name": "데이터 질의 도우미 이름",
7374
"prompt": "프롬프트",
7475
"disabling_successfully": "비활성화 완료",
7576
"closed_by_default": "질문 수 창에서 모델 사고 프로세스를 기본적으로 확장할지 또는 닫을지 여부를 제어합니다.",

frontend/src/i18n/zh-CN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"platform_user_organization": "默认工作空间",
7171
"platform_user_roles": "第三方平台用户角色",
7272
"excessive_data_volume": "关闭1000行的数据限制后,数据量过大,可能会造成系统卡顿",
73+
"sqlbot_name": "问数小助手名称",
7374
"prompt": "提示",
7475
"disabling_successfully": "关闭成功",
7576
"closed_by_default": "在问数窗口中,控制模型思考过程默认展开或者关闭",

frontend/src/i18n/zh-TW.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"platform_user_organization": "預設工作區",
7171
"platform_user_roles": "第三方平台使用者角色",
7272
"excessive_data_volume": "關閉1000列的資料限制後,資料量過大,可能會造成系統卡頓",
73+
"sqlbot_name": "問數小助手名稱",
7374
"prompt": "提示",
7475
"disabling_successfully": "關閉成功",
7576
"closed_by_default": "在問數視窗中,控制模型思考過程預設展開或者關閉",

frontend/src/stores/chatConfig.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,23 @@ import { request } from '@/utils/request.ts'
44
import { formatArg } from '@/utils/utils.ts'
55

66
interface ChatConfig {
7+
sqlbot_name: string
78
expand_thinking_block: boolean
89
limit_rows: boolean
910
}
1011

1112
export const chatConfigStore = defineStore('chatConfigStore', {
1213
state: (): ChatConfig => {
1314
return {
15+
sqlbot_name: 'SQLBot',
1416
expand_thinking_block: false,
1517
limit_rows: true,
1618
}
1719
},
1820
getters: {
21+
getSQLBotName(): string {
22+
return this.sqlbot_name
23+
},
1924
getExpandThinkingBlock(): boolean {
2025
return this.expand_thinking_block
2126
},
@@ -34,6 +39,11 @@ export const chatConfigStore = defineStore('chatConfigStore', {
3439
if (item.pkey === 'chat.limit_rows') {
3540
this.limit_rows = formatArg(item.pval)
3641
}
42+
if (item.pkey === 'chat.sqlbot_name') {
43+
if (item.pval && item.pval.trim().length > 0) {
44+
this.sqlbot_name = item.pval
45+
}
46+
}
3747
})
3848
}
3949
})

frontend/src/views/system/parameter/index.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const { t } = useI18n()
99
1010
const state = reactive({
1111
parameterForm: reactive<any>({
12+
'chat.sqlbot_name': 'SQLBot',
1213
'chat.expand_thinking_block': false,
1314
'chat.limit_rows': false,
1415
}),
@@ -19,7 +20,7 @@ const loadData = () => {
1920
if (res) {
2021
res.forEach((item: any) => {
2122
if (
22-
item.pkey?.startsWith('chat') ||
23+
(item.pkey?.startsWith('chat') && item.pkey !== 'chat.sqlbot_name') ||
2324
item.pkey?.startsWith('login') ||
2425
item.pkey?.startsWith('platform')
2526
) {
@@ -96,6 +97,14 @@ onMounted(() => {
9697
{{ t('parameter.question_count_settings') }}
9798
</div>
9899
<el-row>
100+
<div class="card-item" style="width: 100%">
101+
<div class="label">
102+
{{ t('parameter.sqlbot_name') }}
103+
</div>
104+
<div class="value">
105+
<el-input v-model="state.parameterForm['chat.sqlbot_name']" />
106+
</div>
107+
</div>
99108
<div class="card-item">
100109
<div class="label">
101110
{{ t('parameter.model_thinking_process') }}

0 commit comments

Comments
 (0)