vector_app.py 820 B

123456789101112131415161718192021222324252627282930
  1. import jieba
  2. from quart import Quart
  3. from applications.config import LOCAL_MODEL_CONFIG, DEFAULT_MODEL
  4. from applications.utils.milvus import milvus_collection
  5. from applications.utils.mysql import mysql_manager
  6. from routes import server_routes
  7. app = Quart(__name__)
  8. MODEL_PATH = LOCAL_MODEL_CONFIG[DEFAULT_MODEL]
  9. # 注册路由
  10. app_route = server_routes(mysql_manager, milvus_collection)
  11. app.register_blueprint(app_route)
  12. @app.before_serving
  13. async def startup():
  14. print("Starting application...")
  15. await mysql_manager.init_pools()
  16. print("Mysql pools init successfully")
  17. print("Loading jieba dictionary...")
  18. jieba.initialize()
  19. print("Jieba dictionary loaded successfully")
  20. @app.after_serving
  21. async def shutdown():
  22. print("Shutting down application...")
  23. await mysql_manager.close_pools()