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.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
import os
import platform
from Text2SqlUtil import *
from Text2Sql . PostgreSQLUtil import PostgreSQLUtil
from Text2Sql . SaveToExcel import save_to_excel
if __name__ == " __main__ " :
vn = DeepSeekVanna ( )
# 打开CreateTable.sql文件内容
with open ( " CreateTable.sql " , " r " , encoding = " utf-8 " ) as file :
ddl = file . read ( )
# 训练数据
vn . train (
ddl = ddl
)
# 流式生成演示
question = " 查询小学语文有哪些册,返回册信息的所有相关属性。 "
# 获取完整 SQL
sql = vn . generate_sql ( question )
print ( " 最终 SQL: \n " , sql )
# 执行SQL查询
with PostgreSQLUtil ( ) as db :
sample_data = db . execute_query ( sql )
filename = " 导出信息.xlsx "
save_to_excel ( sample_data , filename )
# 在代码最后添加自动打开逻辑
if platform . system ( ) == " Windows " :
try :
full_path = os . path . abspath ( filename )
print ( f " \n ✅ 文件已保存到: { full_path } " )
os . startfile ( full_path ) # 关键代码
except Exception as e :
print ( f " \n ⚠️ 自动打开失败: { str ( e ) } ,请手动打开文件 " )
else :
print ( " \n ⚠️ 非Windows系统, 请手动打开文件 " )