diff --git a/AI/Text2Sql/__pycache__/app.cpython-310.pyc b/AI/Text2Sql/__pycache__/app.cpython-310.pyc index 49de5cb8..840a68c3 100644 Binary files a/AI/Text2Sql/__pycache__/app.cpython-310.pyc and b/AI/Text2Sql/__pycache__/app.cpython-310.pyc differ diff --git a/AI/Text2Sql/app.py b/AI/Text2Sql/app.py index 63d82c3e..854f1581 100644 --- a/AI/Text2Sql/app.py +++ b/AI/Text2Sql/app.py @@ -112,7 +112,7 @@ async def get_docx_stream( return {"success": False, "message": "缺少问题ID参数"} # 根据问题ID获取查询sql - sql = (await db.fetch("SELECT * FROM t_bi_question WHERE id = $1", question_id))[0]['sql'] + sql = (await get_question_by_id(db, question_id))[0]['sql'] # 生成word报告 prompt = ''' @@ -154,7 +154,7 @@ async def get_docx_stream( chunk_content = chunk.choices[0].delta.content # 逐字拆分并返回 for char in chunk_content: - #print(char, end="", flush=True) # 逐字输出到控制台 + # print(char, end="", flush=True) # 逐字输出到控制台 yield char.encode("utf-8") # 将字符编码为 UTF-8 字节 summary += char # 将内容拼接到 summary 中 @@ -162,7 +162,8 @@ async def get_docx_stream( markdown_to_docx(summary, output_file=filename) # 记录到数据库 - await db.execute("UPDATE t_bi_question SET docx_file_name = $1 WHERE id = $2", filename, question_id) + await update_question_by_id(db, question_id, docx_file_name=filename) + #await db.execute("UPDATE t_bi_question SET docx_file_name = $1 WHERE id = $2", filename, question_id) except asyncio.CancelledError: # 客户端提前断开连接,无需处理 print("客户端断开连接") @@ -172,7 +173,7 @@ async def get_docx_stream( "success": False, "message": f"生成Word文件失败: {str(e)}" }) - #print(error_response) # 输出错误信息到控制台 + # print(error_response) # 输出错误信息到控制台 yield error_response.encode("utf-8") # 将错误信息编码为 UTF-8 字节 finally: @@ -228,6 +229,7 @@ async def set_system_recommend( # 提示保存成功 return {"success": True, "message": "保存成功"} + @app.post("/questions/set_user_collect") async def set_user_collect( question_id: str = Form(...), @@ -238,6 +240,7 @@ async def set_user_collect( # 提示保存成功 return {"success": True, "message": "保存成功"} + @app.get("/questions/get_system_recommend") async def get_system_recommend(db: asyncpg.Connection = Depends(get_db)): # 添加 db 参数 # 查询所有系统推荐问题 @@ -245,6 +248,7 @@ async def get_system_recommend(db: asyncpg.Connection = Depends(get_db)): # 添 # 返回查询结果 return {"success": True, "data": system_recommend_questions} + @app.get("/questions/get_user_collect") async def get_user_collect(db: asyncpg.Connection = Depends(get_db)): # 添加 db 参数 # 查询所有用户收藏问题 @@ -252,6 +256,7 @@ async def get_user_collect(db: asyncpg.Connection = Depends(get_db)): # 添加 # 返回查询结果 return {"success": True, "data": user_collect_questions} + # 启动 FastAPI if __name__ == "__main__": uvicorn.run("app:app", host="0.0.0.0", port=8000, reload=True, workers=4)