Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ragflow_server.py 3.4KB

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