main.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import uvicorn
  2. from fastapi import FastAPI
  3. from pydantic import BaseModel
  4. from tool.pdf2md import pdf2ai
  5. from utils import dmQuery
  6. from utils.shellUtil import execute_command_on_linux
  7. app = FastAPI() # 创建API实例
  8. @app.get("/")
  9. async def root():
  10. return {"message": "Hello World"}
  11. # 将数据模型定义为继承BaseModel的类
  12. class Item(BaseModel):
  13. sql: str
  14. class Pdf2md(BaseModel):
  15. pdfUrl: str
  16. prompt: str
  17. pageNum: int
  18. @app.put("/exsql")
  19. async def create_item( item: Item, q: str = None):
  20. result = {**item.dict()}
  21. results = dmQuery.execute_query(item.sql)
  22. return results
  23. @app.put("/exshell")
  24. async def create_item( item: Item, q: str = None):
  25. # 配置 Linux 服务器信息
  26. host = '119.29.146.254'
  27. port = 22
  28. username = 'root'
  29. password = 'zrd1236987!'
  30. # 要执行的命令
  31. result = execute_command_on_linux(host, port, username, password, item.sql)
  32. return result
  33. @app.put("/pdf2md")
  34. async def pdf2md(item: Pdf2md, q: str = None):
  35. pdf_url = 'http://42.194.163.46:9007/ywd/%E6%89%AB%E6%8F%8F%E5%85%A8%E8%83%BD%E7%8E%8B%202025-03-20%2021.38.pdf'
  36. prompt = "提取有效信息,只输出图片有效信息无效信息不用。"
  37. result = pdf2ai(item.pdfUrl, item.prompt, item.pageNum)
  38. return result
  39. if __name__ == "__main__":
  40. uvicorn.run(app, host="0.0.0.0", port=29015, timeout_keep_alive=600)