Skip to content

Commit 06a869f

Browse files
committed
feat: import Sample SQL / Terminologies
1 parent 69447ef commit 06a869f

File tree

14 files changed

+614
-371
lines changed

14 files changed

+614
-371
lines changed

backend/apps/data_training/api/data_training.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ def inner():
7474
data_list.append(_data)
7575

7676
fields = []
77-
fields.append(AxisObj(name=trans('i18n_data_training.data_training'), value='question'))
78-
fields.append(AxisObj(name=trans('i18n_data_training.problem_description'), value='description'))
77+
fields.append(AxisObj(name=trans('i18n_data_training.problem_description'), value='question'))
78+
fields.append(AxisObj(name=trans('i18n_data_training.sample_sql'), value='description'))
7979
fields.append(AxisObj(name=trans('i18n_data_training.effective_data_sources'), value='datasource_name'))
8080
if current_user.oid == 1:
8181
fields.append(
@@ -98,6 +98,43 @@ def inner():
9898
return StreamingResponse(result, media_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
9999

100100

101+
@router.get("/template")
102+
async def excel_template(trans: Trans, current_user: CurrentUser):
103+
def inner():
104+
data_list = []
105+
_data1 = {
106+
"question": '查询TEST表内所有ID',
107+
"description": 'SELECT id FROM TEST',
108+
"datasource_name": '生效数据源1',
109+
"advanced_application_name": '生效高级应用名称',
110+
}
111+
data_list.append(_data1)
112+
113+
fields = []
114+
fields.append(AxisObj(name=trans('i18n_data_training.problem_description_template'), value='question'))
115+
fields.append(AxisObj(name=trans('i18n_data_training.sample_sql_template'), value='description'))
116+
fields.append(AxisObj(name=trans('i18n_data_training.effective_data_sources_template'), value='datasource_name'))
117+
if current_user.oid == 1:
118+
fields.append(
119+
AxisObj(name=trans('i18n_data_training.advanced_application_template'), value='advanced_application_name'))
120+
121+
md_data, _fields_list = DataFormat.convert_object_array_for_pandas(fields, data_list)
122+
123+
df = pd.DataFrame(md_data, columns=_fields_list)
124+
125+
buffer = io.BytesIO()
126+
127+
with pd.ExcelWriter(buffer, engine='xlsxwriter',
128+
engine_kwargs={'options': {'strings_to_numbers': False}}) as writer:
129+
df.to_excel(writer, sheet_name='Sheet1', index=False)
130+
131+
buffer.seek(0)
132+
return io.BytesIO(buffer.getvalue())
133+
134+
result = await asyncio.to_thread(inner)
135+
return StreamingResponse(result, media_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
136+
137+
101138
path = settings.EXCEL_PATH
102139

103140
from sqlalchemy.orm import sessionmaker, scoped_session

backend/apps/terminology/api/terminology.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,51 @@ def inner():
9898
return StreamingResponse(result, media_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
9999

100100

101+
@router.get("/template")
102+
async def excel_template(trans: Trans):
103+
def inner():
104+
data_list = []
105+
_data1 = {
106+
"word": trans('i18n_terminology.term_name_template_example_1'),
107+
"other_words": trans('i18n_terminology.synonyms_template_example_1'),
108+
"description": trans('i18n_terminology.term_description_template_example_1'),
109+
"all_data_sources": 'N',
110+
"datasource": trans('i18n_terminology.effective_data_sources_template_example_1'),
111+
}
112+
data_list.append(_data1)
113+
_data2 = {
114+
"word": trans('i18n_terminology.term_name_template_example_2'),
115+
"other_words": trans('i18n_terminology.synonyms_template_example_2'),
116+
"description": trans('i18n_terminology.term_description_template_example_2'),
117+
"all_data_sources": 'Y',
118+
"datasource": '',
119+
}
120+
data_list.append(_data2)
121+
122+
fields = []
123+
fields.append(AxisObj(name=trans('i18n_terminology.term_name_template'), value='word'))
124+
fields.append(AxisObj(name=trans('i18n_terminology.synonyms_template'), value='other_words'))
125+
fields.append(AxisObj(name=trans('i18n_terminology.term_description_template'), value='description'))
126+
fields.append(AxisObj(name=trans('i18n_terminology.effective_data_sources_template'), value='datasource'))
127+
fields.append(AxisObj(name=trans('i18n_terminology.all_data_sources_template'), value='all_data_sources'))
128+
129+
md_data, _fields_list = DataFormat.convert_object_array_for_pandas(fields, data_list)
130+
131+
df = pd.DataFrame(md_data, columns=_fields_list)
132+
133+
buffer = io.BytesIO()
134+
135+
with pd.ExcelWriter(buffer, engine='xlsxwriter',
136+
engine_kwargs={'options': {'strings_to_numbers': False}}) as writer:
137+
df.to_excel(writer, sheet_name='Sheet1', index=False)
138+
139+
buffer.seek(0)
140+
return io.BytesIO(buffer.getvalue())
141+
142+
result = await asyncio.to_thread(inner)
143+
return StreamingResponse(result, media_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
144+
145+
101146
path = settings.EXCEL_PATH
102147

103148
from sqlalchemy.orm import sessionmaker, scoped_session

backend/locales/en.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@
4848
"effective_data_sources": "Effective Data Sources",
4949
"all_data_sources": "All Data Sources",
5050
"synonyms": "Synonyms",
51+
"term_name_template": "Terminology Name (Required)",
52+
"term_description_template": "Terminology Description (Required)",
53+
"effective_data_sources_template": "Effective Data Sources (Multiple supported, separated by \",\")",
54+
"all_data_sources_template": "All Data Sources (Y: Apply to all data sources, N: Apply to specified data sources)",
55+
"synonyms_template": "Synonyms (Multiple supported, separated by \",\")",
56+
"term_name_template_example_1": "Term1",
57+
"term_description_template_example_1": "Term1 Description",
58+
"effective_data_sources_template_example_1": "Datasource1, Datasource2",
59+
"synonyms_template_example_1": "Synonym1, Synonym2",
60+
"term_name_template_example_2": "Term2",
61+
"term_description_template_example_2": "Term2 Description",
62+
"synonyms_template_example_2": "Synonym3",
5163
"word_cannot_be_empty": "Term cannot be empty",
5264
"description_cannot_be_empty": "Term description cannot be empty",
5365
"datasource_not_found": "Datasource not found"
@@ -62,6 +74,13 @@
6274
"sample_sql": "Sample SQL",
6375
"effective_data_sources": "Effective Data Sources",
6476
"advanced_application": "Advanced Application",
77+
"problem_description_template": "Problem Description (Required)",
78+
"sample_sql_template": "Sample SQL (Required)",
79+
"effective_data_sources_template": "Effective Data Sources",
80+
"advanced_application_template": "Advanced Application",
81+
"problem_description_template_example": "Query all IDs in the TEST table",
82+
"effective_data_sources_template_example": "Effective Datasource 1",
83+
"advanced_application_template_example": "Effective Advanced Application Name",
6584
"error_info": "Error Information",
6685
"question_cannot_be_empty": "Question cannot be empty",
6786
"description_cannot_be_empty": "Sample SQL cannot be empty",
@@ -75,6 +94,15 @@
7594
"prompt_word_content": "Prompt word content",
7695
"effective_data_sources": "Effective Data Sources",
7796
"all_data_sources": "All Data Sources",
97+
"prompt_word_name_template": "Prompt Name (Required)",
98+
"prompt_word_content_template": "Prompt Content (Required)",
99+
"effective_data_sources_template": "Effective Data Sources (Multiple supported, separated by \",\")",
100+
"all_data_sources_template": "All Data Sources (Y: Apply to all data sources, N: Apply to specified data sources)",
101+
"prompt_word_name_template_example1": "Prompt1",
102+
"prompt_word_content_template_example1": "Describe your prompt in detail",
103+
"effective_data_sources_template_example1": "Datasource1, Datasource2",
104+
"prompt_word_name_template_example2": "Prompt2",
105+
"prompt_word_content_template_example2": "Describe your prompt in detail",
78106
"name_cannot_be_empty": "Name cannot be empty",
79107
"prompt_cannot_be_empty": "Prompt content cannot be empty",
80108
"type_cannot_be_empty": "Type cannot be empty",

backend/locales/ko-KR.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@
4848
"effective_data_sources": "유효 데이터 소스",
4949
"all_data_sources": "모든 데이터 소스",
5050
"synonyms": "동의어",
51+
"term_name_template": "용어 이름 (필수)",
52+
"term_description_template": "용어 설명 (필수)",
53+
"effective_data_sources_template": "유효 데이터 소스 (여러 개 지원, \",\"로 구분)",
54+
"all_data_sources_template": "모든 데이터 소스 (Y: 모든 데이터 소스에 적용, N: 지정된 데이터 소스에 적용)",
55+
"synonyms_template": "동의어 (여러 개 지원, \",\"로 구분)",
56+
"term_name_template_example_1": "용어1",
57+
"term_description_template_example_1": "용어1 설명",
58+
"effective_data_sources_template_example_1": "데이터소스1, 데이터소스2",
59+
"synonyms_template_example_1": "동의어1, 동의어2",
60+
"term_name_template_example_2": "용어2",
61+
"term_description_template_example_2": "용어2 설명",
62+
"synonyms_template_example_2": "동의어3",
5163
"word_cannot_be_empty": "용어는 비울 수 없습니다",
5264
"description_cannot_be_empty": "용어 설명은 비울 수 없습니다",
5365
"datasource_not_found": "데이터 소스를 찾을 수 없음"
@@ -62,6 +74,13 @@
6274
"sample_sql": "예시 SQL",
6375
"effective_data_sources": "유효 데이터 소스",
6476
"advanced_application": "고급 애플리케이션",
77+
"problem_description_template": "문제 설명 (필수)",
78+
"sample_sql_template": "예시 SQL (필수)",
79+
"effective_data_sources_template": "유효 데이터 소스",
80+
"advanced_application_template": "고급 애플리케이션",
81+
"problem_description_template_example": "TEST 테이블 내 모든 ID 조회",
82+
"effective_data_sources_template_example": "유효 데이터소스1",
83+
"advanced_application_template_example": "유효 고급 애플리케이션 이름",
6584
"error_info": "오류 정보",
6685
"question_cannot_be_empty": "질문은 비울 수 없습니다",
6786
"description_cannot_be_empty": "예시 SQL은 비울 수 없습니다",
@@ -75,6 +94,15 @@
7594
"prompt_word_content": "프롬프트 내용",
7695
"effective_data_sources": "유효 데이터 소스",
7796
"all_data_sources": "모든 데이터 소스",
97+
"prompt_word_name_template": "프롬프트 이름 (필수)",
98+
"prompt_word_content_template": "프롬프트 내용 (필수)",
99+
"effective_data_sources_template": "유효 데이터 소스 (여러 개 지원, \",\"로 구분)",
100+
"all_data_sources_template": "모든 데이터 소스 (Y: 모든 데이터 소스에 적용, N: 지정된 데이터 소스에 적용)",
101+
"prompt_word_name_template_example1": "프롬프트1",
102+
"prompt_word_content_template_example1": "프롬프트를 상세히 설명해 주세요",
103+
"effective_data_sources_template_example1": "데이터소스1, 데이터소스2",
104+
"prompt_word_name_template_example2": "프롬프트2",
105+
"prompt_word_content_template_example2": "프롬프트를 상세히 설명해 주세요",
78106
"name_cannot_be_empty": "이름은 비울 수 없습니다",
79107
"prompt_cannot_be_empty": "프롬프트 내용은 비울 수 없습니다",
80108
"type_cannot_be_empty": "유형은 비울 수 없습니다",

backend/locales/zh-CN.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@
4848
"effective_data_sources": "生效数据源",
4949
"all_data_sources": "所有数据源",
5050
"synonyms": "同义词",
51+
"term_name_template": "术语名称(必填)",
52+
"term_description_template": "术语描述(必填)",
53+
"effective_data_sources_template": "生效数据源(支持多个,用\",\"分割)",
54+
"all_data_sources_template": "所有数据源(Y:应用到全部数据源,N:应用到指定数据源)",
55+
"synonyms_template": "同义词(支持多个,用\",\"分割)",
56+
"term_name_template_example_1": "术语1",
57+
"term_description_template_example_1": "术语1描述",
58+
"effective_data_sources_template_example_1": "生效数据源1, 生效数据源2",
59+
"synonyms_template_example_1": "同义词1, 同义词2",
60+
"term_name_template_example_2": "术语2",
61+
"term_description_template_example_2": "术语2描述",
62+
"synonyms_template_example_2": "同义词3",
5163
"word_cannot_be_empty": "术语不能为空",
5264
"description_cannot_be_empty": "术语描述不能为空",
5365
"datasource_not_found": "找不到数据源"
@@ -62,6 +74,13 @@
6274
"sample_sql": "示例 SQL",
6375
"effective_data_sources": "生效数据源",
6476
"advanced_application": "高级应用",
77+
"problem_description_template": "问题描述(必填)",
78+
"sample_sql_template": "示例 SQL(必填)",
79+
"effective_data_sources_template": "生效数据源",
80+
"advanced_application_template": "高级应用",
81+
"problem_description_template_example": "查询TEST表内所有ID",
82+
"effective_data_sources_template_example": "生效数据源1",
83+
"advanced_application_template_example": "生效高级应用名称",
6584
"error_info": "错误信息",
6685
"question_cannot_be_empty": "问题不能为空",
6786
"description_cannot_be_empty": "示例 SQL 不能为空",
@@ -75,6 +94,15 @@
7594
"prompt_word_content": "提示词内容",
7695
"effective_data_sources": "生效数据源",
7796
"all_data_sources": "所有数据源",
97+
"prompt_word_name_template": "提示词名称(必填)",
98+
"prompt_word_content_template": "提示词内容(必填)",
99+
"effective_data_sources_template": "生效数据源(支持多个,用\",\"分割)",
100+
"all_data_sources_template": "所有数据源(Y:应用到全部数据源,N:应用到指定数据源)",
101+
"prompt_word_name_template_example1": "提示词1",
102+
"prompt_word_content_template_example1": "详细描述你的提示词",
103+
"effective_data_sources_template_example1": "生效数据源1, 生效数据源2",
104+
"prompt_word_name_template_example2": "提示词2",
105+
"prompt_word_content_template_example2": "详细描述你的提示词",
78106
"name_cannot_be_empty": "名称不能为空",
79107
"prompt_cannot_be_empty": "提示词内容不能为空",
80108
"type_cannot_be_empty": "类型不能为空",

backend/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ dependencies = [
3939
"pyyaml (>=6.0.2,<7.0.0)",
4040
"fastapi-mcp (>=0.3.4,<0.4.0)",
4141
"tabulate>=0.9.0",
42-
"sqlbot-xpack>=0.0.3.47,<1.0.0",
42+
"sqlbot-xpack>=0.0.3.53,<1.0.0",
4343
"fastapi-cache2>=0.2.2",
4444
"sqlparse>=0.5.3",
4545
"redis>=6.2.0",

frontend/src/api/setting.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,10 @@ export const settingsApi = {
1717
requestOptions: { customError: true },
1818
}
1919
),
20+
21+
downloadTemplate: (url: any) =>
22+
request.get(url, {
23+
responseType: 'blob',
24+
requestOptions: { customError: true },
25+
}),
2026
}

frontend/src/i18n/en.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@
117117
"english": "English",
118118
"re_upload": "Re-upload",
119119
"not_exceed_50mb": "Supports XLS, XLSX, CSV formats, file size does not exceed 50MB",
120+
"excel_file_type_limit": "Only XLS and XLSX formats are supported",
121+
"click_to_select_file": "Click to select file",
122+
"upload_hint_first": "Please ",
123+
"upload_hint_download_template": "download the template",
124+
"upload_hint_end": " first, then upload after filling it out as required",
125+
"continue_to_upload": "Continue to import",
120126
"reset_password": "Reset password",
121127
"password_reset_successful": "Password reset successful",
122128
"or": "Or",

frontend/src/i18n/ko-KR.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@
117117
"english": "English",
118118
"re_upload": "다시 업로드",
119119
"not_exceed_50mb": "XLS, XLSX, CSV 형식을 지원하며, 파일 크기는 50MB를 초과할 수 없습니다",
120+
"excel_file_type_limit": "XLS 및 XLSX 형식만 지원됩니다",
121+
"click_to_select_file": "파일 선택을 클릭하세요",
122+
"upload_hint_first": "먼저 ",
123+
"upload_hint_download_template": "템플릿을 다운로드",
124+
"upload_hint_end": ", 한 후 요구사항에 따라 작성하여 업로드하세요",
125+
"continue_to_upload": "계속 가져오기",
120126
"reset_password": "비밀번호 재설정",
121127
"password_reset_successful": "비밀번호 재설정 성공",
122128
"or": "또는",

frontend/src/i18n/zh-CN.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@
117117
"english": "English",
118118
"re_upload": "重新上传",
119119
"not_exceed_50mb": "支持 XLS、XLSX、CSV 格式,文件大小不超过 50MB",
120+
"excel_file_type_limit": "仅支持 XLS、XLSX 格式",
121+
"click_to_select_file": "点击选择文件",
122+
"upload_hint_first": "",
123+
"upload_hint_download_template": "下载模板",
124+
"upload_hint_end": ",按要求填写后上传",
125+
"continue_to_upload": "继续导入",
120126
"reset_password": "重置密码",
121127
"password_reset_successful": "重置密码成功",
122128
"or": "或者",

0 commit comments

Comments
 (0)