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.

ragflow_server.py 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #
  2. # Copyright 2024 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. # from beartype import BeartypeConf
  17. # from beartype.claw import beartype_all # <-- you didn't sign up for this
  18. # beartype_all(conf=BeartypeConf(violation_type=UserWarning)) # <-- emit warnings from all code
  19. import logging
  20. from api.utils.log_utils import initRootLogger
  21. initRootLogger("ragflow_server")
  22. for module in ["pdfminer"]:
  23. module_logger = logging.getLogger(module)
  24. module_logger.setLevel(logging.WARNING)
  25. for module in ["peewee"]:
  26. module_logger = logging.getLogger(module)
  27. module_logger.handlers.clear()
  28. module_logger.propagate = True
  29. import os
  30. import signal
  31. import sys
  32. import time
  33. import traceback
  34. from concurrent.futures import ThreadPoolExecutor
  35. from werkzeug.serving import run_simple
  36. from api import settings
  37. from api.apps import app
  38. from api.db.runtime_config import RuntimeConfig
  39. from api.db.services.document_service import DocumentService
  40. from api import utils
  41. from api.db.db_models import init_database_tables as init_web_db
  42. from api.db.init_data import init_web_data
  43. from api.versions import get_ragflow_version
  44. from api.utils import show_configs
  45. from rag.settings import print_rag_settings
  46. def update_progress():
  47. while True:
  48. time.sleep(3)
  49. try:
  50. DocumentService.update_progress()
  51. except Exception:
  52. logging.exception("update_progress exception")
  53. if __name__ == '__main__':
  54. logging.info(r"""
  55. ____ ___ ______ ______ __
  56. / __ \ / | / ____// ____// /____ _ __
  57. / /_/ // /| | / / __ / /_ / // __ \| | /| / /
  58. / _, _// ___ |/ /_/ // __/ / // /_/ /| |/ |/ /
  59. /_/ |_|/_/ |_|\____//_/ /_/ \____/ |__/|__/
  60. """)
  61. logging.info(
  62. f'RAGFlow version: {get_ragflow_version()}'
  63. )
  64. logging.info(
  65. f'project base: {utils.file_utils.get_project_base_directory()}'
  66. )
  67. show_configs()
  68. settings.init_settings()
  69. print_rag_settings()
  70. # init db
  71. init_web_db()
  72. init_web_data()
  73. # init runtime config
  74. import argparse
  75. parser = argparse.ArgumentParser()
  76. parser.add_argument(
  77. "--version", default=False, help="RAGFlow version", action="store_true"
  78. )
  79. parser.add_argument(
  80. "--debug", default=False, help="debug mode", action="store_true"
  81. )
  82. args = parser.parse_args()
  83. if args.version:
  84. print(get_ragflow_version())
  85. sys.exit(0)
  86. RuntimeConfig.DEBUG = args.debug
  87. if RuntimeConfig.DEBUG:
  88. logging.info("run on debug mode")
  89. RuntimeConfig.init_env()
  90. RuntimeConfig.init_config(JOB_SERVER_HOST=settings.HOST_IP, HTTP_PORT=settings.HOST_PORT)
  91. thread = ThreadPoolExecutor(max_workers=1)
  92. thread.submit(update_progress)
  93. # start http server
  94. try:
  95. logging.info("RAGFlow HTTP server start...")
  96. run_simple(
  97. hostname=settings.HOST_IP,
  98. port=settings.HOST_PORT,
  99. application=app,
  100. threaded=True,
  101. use_reloader=RuntimeConfig.DEBUG,
  102. use_debugger=RuntimeConfig.DEBUG,
  103. )
  104. except Exception:
  105. traceback.print_exc()
  106. os.kill(os.getpid(), signal.SIGKILL)