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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. import logging
  17. from api.utils.log_utils import initRootLogger
  18. initRootLogger("ragflow_server")
  19. for module in ["pdfminer"]:
  20. module_logger = logging.getLogger(module)
  21. module_logger.setLevel(logging.WARNING)
  22. for module in ["peewee"]:
  23. module_logger = logging.getLogger(module)
  24. module_logger.handlers.clear()
  25. module_logger.propagate = True
  26. import os
  27. import signal
  28. import sys
  29. import time
  30. import traceback
  31. from concurrent.futures import ThreadPoolExecutor
  32. from werkzeug.serving import run_simple
  33. from api import settings
  34. from api.apps import app
  35. from api.db.runtime_config import RuntimeConfig
  36. from api.db.services.document_service import DocumentService
  37. from api import utils
  38. from api.db.db_models import init_database_tables as init_web_db
  39. from api.db.init_data import init_web_data
  40. from api.versions import get_ragflow_version
  41. from api.utils import show_configs
  42. def update_progress():
  43. while True:
  44. time.sleep(3)
  45. try:
  46. DocumentService.update_progress()
  47. except Exception:
  48. logging.exception("update_progress exception")
  49. if __name__ == '__main__':
  50. logging.info(r"""
  51. ____ ___ ______ ______ __
  52. / __ \ / | / ____// ____// /____ _ __
  53. / /_/ // /| | / / __ / /_ / // __ \| | /| / /
  54. / _, _// ___ |/ /_/ // __/ / // /_/ /| |/ |/ /
  55. /_/ |_|/_/ |_|\____//_/ /_/ \____/ |__/|__/
  56. """)
  57. logging.info(
  58. f'RAGFlow version: {get_ragflow_version()}'
  59. )
  60. logging.info(
  61. f'project base: {utils.file_utils.get_project_base_directory()}'
  62. )
  63. show_configs()
  64. settings.init_settings()
  65. # init db
  66. init_web_db()
  67. init_web_data()
  68. # init runtime config
  69. import argparse
  70. parser = argparse.ArgumentParser()
  71. parser.add_argument(
  72. "--version", default=False, help="RAGFlow version", action="store_true"
  73. )
  74. parser.add_argument(
  75. "--debug", default=False, help="debug mode", action="store_true"
  76. )
  77. args = parser.parse_args()
  78. if args.version:
  79. print(get_ragflow_version())
  80. sys.exit(0)
  81. RuntimeConfig.DEBUG = args.debug
  82. if RuntimeConfig.DEBUG:
  83. logging.info("run on debug mode")
  84. RuntimeConfig.init_env()
  85. RuntimeConfig.init_config(JOB_SERVER_HOST=settings.HOST_IP, HTTP_PORT=settings.HOST_PORT)
  86. thread = ThreadPoolExecutor(max_workers=1)
  87. thread.submit(update_progress)
  88. # start http server
  89. try:
  90. logging.info("RAGFlow HTTP server start...")
  91. run_simple(
  92. hostname=settings.HOST_IP,
  93. port=settings.HOST_PORT,
  94. application=app,
  95. threaded=True,
  96. use_reloader=RuntimeConfig.DEBUG,
  97. use_debugger=RuntimeConfig.DEBUG,
  98. )
  99. except Exception:
  100. traceback.print_exc()
  101. os.kill(os.getpid(), signal.SIGKILL)