|
|
|
@ -15,14 +15,10 @@ from Text2Sql.Util.EchartsUtil import generate_chart
|
|
|
|
|
from Text2Sql.Util.MarkdownToDocxUtil import markdown_to_docx
|
|
|
|
|
from Text2Sql.Util.SaveToExcel import save_to_excel
|
|
|
|
|
from Text2Sql.Util.VannaUtil import VannaUtil
|
|
|
|
|
from fastapi.middleware.cors import CORSMiddleware # 导入跨域中间件
|
|
|
|
|
|
|
|
|
|
# 初始化 FastAPI
|
|
|
|
|
app = FastAPI()
|
|
|
|
|
app.mount("/static", StaticFiles(directory="static"), name="static")
|
|
|
|
|
|
|
|
|
|
vn = VannaUtil()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 初始化 FastAPI 应用
|
|
|
|
|
@asynccontextmanager
|
|
|
|
|
async def lifespan(app: FastAPI):
|
|
|
|
@ -40,16 +36,26 @@ async def lifespan(app: FastAPI):
|
|
|
|
|
# 关闭时释放连接池
|
|
|
|
|
await app.state.pool.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 初始化 FastAPI
|
|
|
|
|
app = FastAPI(lifespan=lifespan)
|
|
|
|
|
|
|
|
|
|
# 添加跨域支持
|
|
|
|
|
app.add_middleware(
|
|
|
|
|
CORSMiddleware, # 直接使用 CORSMiddleware 类
|
|
|
|
|
allow_origins=["*"], # 允许所有来源
|
|
|
|
|
allow_credentials=True, # 允许携带凭证(如 cookies)
|
|
|
|
|
allow_methods=["*"], # 允许所有 HTTP 方法
|
|
|
|
|
allow_headers=["*"], # 允许所有 HTTP 头
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# 挂载静态文件目录
|
|
|
|
|
app.mount("/static", StaticFiles(directory="static"), name="static")
|
|
|
|
|
|
|
|
|
|
# 依赖注入连接池
|
|
|
|
|
async def get_db():
|
|
|
|
|
async with app.state.pool.acquire() as connection:
|
|
|
|
|
yield connection
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/questions/get_excel")
|
|
|
|
|
async def get_excel(question_id: str = Form(...), question_str: str = Form(...),
|
|
|
|
|
db: asyncpg.Connection = Depends(get_db)):
|
|
|
|
|