You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.5 KiB

5 months ago
import os
5 months ago
5 months ago
from Text2Sql.Util.PostgreSQLUtil import PostgreSQLUtil
from Text2Sql.Util.SaveToExcel import save_to_excel
5 months ago
from Text2Sql.Util.Text2SqlUtil import *
'''
经验
1尽量使用宽表少用关联越少越好
2应该有一些固定的组合用法预置出来给出范例让用户可以简单修改后就能使用
3应该有类似于 保存为用例查询历史等功能让用户方便利旧
'''
5 months ago
if __name__ == "__main__":
vn = DeepSeekVanna()
# 开始训练
print("开始训练...")
# 打开CreateTable.sql文件内容
with open("Sql/CreateTable.sql", "r", encoding="utf-8") as file:
ddl = file.read()
# 训练数据
vn.train(
ddl=ddl
)
# 自然语言提问
# '''
question = '''
5 months ago
查询发布时间是2024年度每个行政区划每个学校都上传了多少课程数量,
5 months ago
返回: 行政区划名,学段排名,学校名称,课程数量
5 months ago
'''
common_prompt = '''
要求
1行政区划为NULL 或者是空字符的不参加统计工作
5 months ago
'''
5 months ago
question = question + common_prompt
# 开始查询
print("开始查询...")
# 获取完整 SQL
sql = vn.generate_sql(question)
print("生成的查询 SQL:\n", sql)
# 执行SQL查询
with PostgreSQLUtil() as db:
sample_data = db.execute_query(sql)
filename = "d:/导出信息.xlsx"
save_to_excel(sample_data, filename)
os.startfile(filename)