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

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