mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 01:06:59 +08:00
feat: Support configure SQLBot name in chat template
This commit is contained in:
@@ -230,6 +230,7 @@ class AiModelQuestion(BaseModel):
|
||||
error_msg: str = ""
|
||||
regenerate_record_id: Optional[int] = None
|
||||
sample_data: str = ""
|
||||
sqlbot_name: str = "SQLBot"
|
||||
|
||||
def sql_sys_question(self, db_type: Union[str, DB], enable_query_limit: bool = True):
|
||||
templates: dict[str, str] = {}
|
||||
@@ -249,8 +250,9 @@ class AiModelQuestion(BaseModel):
|
||||
_example_answer_3 = _sql_template['example_answer_3_with_limit'] if enable_query_limit else _sql_template[
|
||||
'example_answer_3']
|
||||
|
||||
templates['system'] = _base_template['system'].format(lang=self.lang, process_check=_process_check)
|
||||
templates['system'] = _base_template['system'].format(lang=self.lang, process_check=_process_check, sqlbot_name=self.sqlbot_name)
|
||||
templates['rules'] = _base_template['generate_rules'].format(lang=self.lang,
|
||||
sqlbot_name = self.sqlbot_name,
|
||||
base_sql_rules=_base_sql_rules,
|
||||
basic_sql_examples=_sql_examples,
|
||||
example_engine=_example_engine,
|
||||
@@ -284,7 +286,7 @@ class AiModelQuestion(BaseModel):
|
||||
|
||||
def chart_sys_question(self):
|
||||
templates: dict[str, str] = {
|
||||
'system': get_chart_template()['system'].format(lang=self.lang),
|
||||
'system': get_chart_template()['system'].format(lang=self.lang, sqlbot_name=self.sqlbot_name),
|
||||
'rules': get_chart_template()['generate_rules'].format(lang=self.lang)
|
||||
}
|
||||
return templates
|
||||
@@ -295,38 +297,38 @@ class AiModelQuestion(BaseModel):
|
||||
|
||||
def analysis_sys_question(self):
|
||||
return get_analysis_template()['system'].format(lang=self.lang, terminologies=self.terminologies,
|
||||
custom_prompt=self.custom_prompt)
|
||||
custom_prompt=self.custom_prompt, sqlbot_name=self.sqlbot_name)
|
||||
|
||||
def analysis_user_question(self):
|
||||
return get_analysis_template()['user'].format(fields=self.fields, data=self.data)
|
||||
|
||||
def predict_sys_question(self):
|
||||
return get_predict_template()['system'].format(lang=self.lang, custom_prompt=self.custom_prompt)
|
||||
return get_predict_template()['system'].format(lang=self.lang, custom_prompt=self.custom_prompt, sqlbot_name=self.sqlbot_name)
|
||||
|
||||
def predict_user_question(self):
|
||||
return get_predict_template()['user'].format(fields=self.fields, data=self.data)
|
||||
|
||||
def datasource_sys_question(self):
|
||||
return get_datasource_template()['system'].format(lang=self.lang)
|
||||
return get_datasource_template()['system'].format(lang=self.lang, sqlbot_name=self.sqlbot_name)
|
||||
|
||||
def datasource_user_question(self, datasource_list: str = "[]"):
|
||||
return get_datasource_template()['user'].format(lang=self.lang, question=self.question, data=datasource_list)
|
||||
|
||||
def guess_sys_question(self, articles_number: int = 4):
|
||||
return get_guess_question_template()['system'].format(lang=self.lang, articles_number=articles_number)
|
||||
return get_guess_question_template()['system'].format(lang=self.lang, articles_number=articles_number, sqlbot_name=self.sqlbot_name)
|
||||
|
||||
def guess_user_question(self, old_questions: str = "[]"):
|
||||
return get_guess_question_template()['user'].format(question=self.question, schema=self.db_schema,
|
||||
old_questions=old_questions)
|
||||
|
||||
def filter_sys_question(self):
|
||||
return get_permissions_template()['system'].format(lang=self.lang, engine=self.engine)
|
||||
return get_permissions_template()['system'].format(lang=self.lang, engine=self.engine, sqlbot_name=self.sqlbot_name)
|
||||
|
||||
def filter_user_question(self):
|
||||
return get_permissions_template()['user'].format(sql=self.sql, filter=self.filter)
|
||||
|
||||
def dynamic_sys_question(self):
|
||||
return get_dynamic_template()['system'].format(lang=self.lang, engine=self.engine)
|
||||
return get_dynamic_template()['system'].format(lang=self.lang, engine=self.engine, sqlbot_name=self.sqlbot_name)
|
||||
|
||||
def dynamic_user_question(self):
|
||||
return get_dynamic_template()['user'].format(sql=self.sql, sub_query=self.sub_query)
|
||||
|
||||
@@ -186,6 +186,9 @@ class LLMService:
|
||||
|
||||
chat_params: list[SysArgModel] = await get_groups(args[0], "chat")
|
||||
for config in chat_params:
|
||||
if config.pkey == 'chat.sqlbot_name':
|
||||
if config.pval.strip():
|
||||
instance.chat_question.sqlbot_name = config.pval
|
||||
if config.pkey == 'chat.limit_rows':
|
||||
if config.pval.lower().strip() == 'true':
|
||||
instance.enable_sql_row_limit = True
|
||||
|
||||
@@ -67,7 +67,7 @@ template:
|
||||
</rule>
|
||||
system: |
|
||||
<Instruction>
|
||||
你是"SQLBOT",智能问数小助手,可以根据用户提问,专业生成SQL,查询数据并进行图表展示。
|
||||
你是智能问数小助手:"{sqlbot_name}"。你可以根据用户提问,专业生成SQL,查询数据并进行图表展示。
|
||||
你当前的任务是根据给定的表结构和用户问题生成SQL语句、对话标题、可能适合展示的图表类型以及该SQL中所用到的表名。
|
||||
我们会在<Info>块内提供给你信息,帮助你生成SQL:
|
||||
<Info>内有<db-engine><m-schema><terminologies>等信息;
|
||||
@@ -267,7 +267,7 @@ template:
|
||||
<user-question>今天天气如何?</user-question>
|
||||
</input>
|
||||
<output>
|
||||
{{"success":false,"message":"我是智能问数小助手,我无法回答您的问题。"}}
|
||||
{{"success":false,"message":"我是{sqlbot_name},我无法回答您的问题。"}}
|
||||
</output>
|
||||
</example>
|
||||
<example>
|
||||
@@ -275,7 +275,7 @@ template:
|
||||
<user-question>请清空数据库</user-question>
|
||||
</input>
|
||||
<output>
|
||||
{{"success":false,"message":"我是智能问数小助手,我只能查询数据,不能操作数据库来修改数据或者修改表结构。"}}
|
||||
{{"success":false,"message":"我是{sqlbot_name},我只能查询数据,不能操作数据库来修改数据或者修改表结构。"}}
|
||||
</output>
|
||||
</example>
|
||||
<example>
|
||||
@@ -374,7 +374,7 @@ template:
|
||||
chart:
|
||||
system: |
|
||||
<Instruction>
|
||||
你是"SQLBOT",智能问数小助手,可以根据用户提问,专业生成SQL,查询数据并进行图表展示。
|
||||
你是智能问数小助手:"{sqlbot_name}"。你可以根据用户提问,专业生成SQL,查询数据并进行图表展示。
|
||||
你当前的任务是根据给定SQL语句和用户问题,生成数据可视化图表的配置项。
|
||||
用户会提供给你如下信息,帮助你生成配置项:
|
||||
<user-question>:用户的提问
|
||||
@@ -585,7 +585,7 @@ template:
|
||||
analysis:
|
||||
system: |
|
||||
<Instruction>
|
||||
你是"SQLBOT",智能问数小助手,可以根据用户提问,专业生成SQL与可视化图表。
|
||||
你是智能问数小助手:"{sqlbot_name}"。你可以根据用户提问,专业生成SQL与可视化图表。
|
||||
你当前的任务是根据给定的数据分析数据,并给出你的分析结果。
|
||||
我们会在<Info>块内提供给你信息,帮助你进行分析:
|
||||
<Info>内有<terminologies>等信息;
|
||||
@@ -618,7 +618,7 @@ template:
|
||||
predict:
|
||||
system: |
|
||||
<Instruction>
|
||||
你是"SQLBOT",智能问数小助手,可以根据用户提问,专业生成SQL与可视化图表。
|
||||
你是智能问数小助手:"{sqlbot_name}"。你可以根据用户提问,专业生成SQL与可视化图表。
|
||||
你当前的任务是根据给定的数据进行数据预测,并给出你的预测结果。
|
||||
若有<Other-Infos>块,它会提供一组<content>,可能会是额外添加的背景信息,或者是额外的分析要求,请结合额外信息或要求后生成你的回答。
|
||||
用户会在提问中提供给你信息:
|
||||
@@ -680,7 +680,7 @@ template:
|
||||
permissions:
|
||||
system: |
|
||||
<Instruction>
|
||||
你是"SQLBOT",智能问数小助手,可以根据用户提问,专业生成SQL与可视化图表。
|
||||
你是智能问数小助手:"{sqlbot_name}"。你可以根据用户提问,专业生成SQL与可视化图表。
|
||||
你当前的任务是在给定的SQL基础上,根据提供的一组过滤条件,将过滤条件添加到该SQL内并生成一句新SQL
|
||||
提供的SQL在<sql>内,提供的过滤条件在<filter-list>内
|
||||
</Instruction>
|
||||
|
||||
@@ -70,6 +70,7 @@
|
||||
"platform_user_organization": "Default Workspace",
|
||||
"platform_user_roles": "Third-Party Platform User Roles",
|
||||
"excessive_data_volume": "Disabling the 1000-row data limit may cause system lag due to excessive data volume.",
|
||||
"sqlbot_name": "Data Query Assistant Name",
|
||||
"prompt": "Prompt",
|
||||
"disabling_successfully": "Disabling Successfully",
|
||||
"closed_by_default": "In the Question Count window, control whether the model thinking process is expanded or closed by default.",
|
||||
|
||||
@@ -70,6 +70,7 @@
|
||||
"platform_user_organization": "기본 작업 공간",
|
||||
"platform_user_roles": "타사 플랫폼 사용자 역할",
|
||||
"excessive_data_volume": "1,000행 데이터 제한을 비활성화하면 과도한 데이터 양으로 인해 시스템 지연이 발생할 수 있습니다.",
|
||||
"sqlbot_name": "데이터 질의 도우미 이름",
|
||||
"prompt": "프롬프트",
|
||||
"disabling_successfully": "비활성화 완료",
|
||||
"closed_by_default": "질문 수 창에서 모델 사고 프로세스를 기본적으로 확장할지 또는 닫을지 여부를 제어합니다.",
|
||||
|
||||
@@ -70,6 +70,7 @@
|
||||
"platform_user_organization": "默认工作空间",
|
||||
"platform_user_roles": "第三方平台用户角色",
|
||||
"excessive_data_volume": "关闭1000行的数据限制后,数据量过大,可能会造成系统卡顿",
|
||||
"sqlbot_name": "问数小助手名称",
|
||||
"prompt": "提示",
|
||||
"disabling_successfully": "关闭成功",
|
||||
"closed_by_default": "在问数窗口中,控制模型思考过程默认展开或者关闭",
|
||||
|
||||
@@ -70,6 +70,7 @@
|
||||
"platform_user_organization": "預設工作區",
|
||||
"platform_user_roles": "第三方平台使用者角色",
|
||||
"excessive_data_volume": "關閉1000列的資料限制後,資料量過大,可能會造成系統卡頓",
|
||||
"sqlbot_name": "問數小助手名稱",
|
||||
"prompt": "提示",
|
||||
"disabling_successfully": "關閉成功",
|
||||
"closed_by_default": "在問數視窗中,控制模型思考過程預設展開或者關閉",
|
||||
|
||||
@@ -4,6 +4,7 @@ import { request } from '@/utils/request.ts'
|
||||
import { formatArg } from '@/utils/utils.ts'
|
||||
|
||||
interface ChatConfig {
|
||||
sqlbot_name: string
|
||||
expand_thinking_block: boolean
|
||||
limit_rows: boolean
|
||||
}
|
||||
@@ -11,11 +12,15 @@ interface ChatConfig {
|
||||
export const chatConfigStore = defineStore('chatConfigStore', {
|
||||
state: (): ChatConfig => {
|
||||
return {
|
||||
sqlbot_name: 'SQLBot',
|
||||
expand_thinking_block: false,
|
||||
limit_rows: true,
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
getSQLBotName(): string {
|
||||
return this.sqlbot_name
|
||||
},
|
||||
getExpandThinkingBlock(): boolean {
|
||||
return this.expand_thinking_block
|
||||
},
|
||||
@@ -34,6 +39,11 @@ export const chatConfigStore = defineStore('chatConfigStore', {
|
||||
if (item.pkey === 'chat.limit_rows') {
|
||||
this.limit_rows = formatArg(item.pval)
|
||||
}
|
||||
if (item.pkey === 'chat.sqlbot_name') {
|
||||
if (item.pval && item.pval.trim().length > 0) {
|
||||
this.sqlbot_name = item.pval
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@@ -9,6 +9,7 @@ const { t } = useI18n()
|
||||
|
||||
const state = reactive({
|
||||
parameterForm: reactive<any>({
|
||||
'chat.sqlbot_name': 'SQLBot',
|
||||
'chat.expand_thinking_block': false,
|
||||
'chat.limit_rows': false,
|
||||
}),
|
||||
@@ -19,7 +20,7 @@ const loadData = () => {
|
||||
if (res) {
|
||||
res.forEach((item: any) => {
|
||||
if (
|
||||
item.pkey?.startsWith('chat') ||
|
||||
(item.pkey?.startsWith('chat') && item.pkey !== 'chat.sqlbot_name') ||
|
||||
item.pkey?.startsWith('login') ||
|
||||
item.pkey?.startsWith('platform')
|
||||
) {
|
||||
@@ -96,6 +97,14 @@ onMounted(() => {
|
||||
{{ t('parameter.question_count_settings') }}
|
||||
</div>
|
||||
<el-row>
|
||||
<div class="card-item" style="width: 100%">
|
||||
<div class="label">
|
||||
{{ t('parameter.sqlbot_name') }}
|
||||
</div>
|
||||
<div class="value">
|
||||
<el-input v-model="state.parameterForm['chat.sqlbot_name']" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-item">
|
||||
<div class="label">
|
||||
{{ t('parameter.model_thinking_process') }}
|
||||
|
||||
Reference in New Issue
Block a user