Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ragflow_server.py 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. from api.utils.log_utils import initRootLogger
  20. initRootLogger("ragflow_server")
  21. import logging
  22. import os
  23. import signal
  24. import sys
  25. import time
  26. import traceback
  27. from concurrent.futures import ThreadPoolExecutor
  28. import threading
  29. from werkzeug.serving import run_simple
  30. from api import settings
  31. from api.apps import app
  32. from api.db.runtime_config import RuntimeConfig
  33. from api.db.services.document_service import DocumentService
  34. from api import utils
  35. from api.db.db_models import init_database_tables as init_web_db
  36. from api.db.init_data import init_web_data
  37. from api.versions import get_ragflow_version
  38. from api.utils import show_configs
  39. from rag.settings import print_rag_settings
  40. stop_event = threading.Event()
  41. def update_progress():
  42. while not stop_event.is_set():
  43. try:
  44. DocumentService.update_progress()
  45. stop_event.wait(6)
  46. except Exception:
  47. logging.exception("update_progress exception")
  48. def signal_handler(sig, frame):
  49. logging.info("Received interrupt signal, shutting down...")
  50. stop_event.set()
  51. time.sleep(1)
  52. sys.exit(0)
  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. signal.signal(signal.SIGINT, signal_handler)
  92. signal.signal(signal.SIGTERM, signal_handler)
  93. thread = ThreadPoolExecutor(max_workers=1)
  94. thread.submit(update_progress)
  95. # start http server
  96. try:
  97. logging.info("RAGFlow HTTP server start...")
  98. run_simple(
  99. hostname=settings.HOST_IP,
  100. port=settings.HOST_PORT,
  101. application=app,
  102. threaded=True,
  103. use_reloader=RuntimeConfig.DEBUG,
  104. use_debugger=RuntimeConfig.DEBUG,
  105. )
  106. except Exception:
  107. traceback.print_exc()
  108. stop_event.set()
  109. time.sleep(1)
  110. os.kill(os.getpid(), signal.SIGKILL)