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

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. import logging
  17. import inspect
  18. from api.utils.log_utils import initRootLogger
  19. initRootLogger(inspect.getfile(inspect.currentframe()))
  20. for module in ["pdfminer"]:
  21. module_logger = logging.getLogger(module)
  22. module_logger.setLevel(logging.WARNING)
  23. for module in ["peewee"]:
  24. module_logger = logging.getLogger(module)
  25. module_logger.handlers.clear()
  26. module_logger.propagate = True
  27. import os
  28. import signal
  29. import sys
  30. import time
  31. import traceback
  32. from concurrent.futures import ThreadPoolExecutor
  33. from werkzeug.serving import run_simple
  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.settings import (
  38. HOST, HTTP_PORT
  39. )
  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. def update_progress():
  45. while True:
  46. time.sleep(3)
  47. try:
  48. DocumentService.update_progress()
  49. except Exception:
  50. logging.exception("update_progress exception")
  51. if __name__ == '__main__':
  52. logging.info(r"""
  53. ____ ___ ______ ______ __
  54. / __ \ / | / ____// ____// /____ _ __
  55. / /_/ // /| | / / __ / /_ / // __ \| | /| / /
  56. / _, _// ___ |/ /_/ // __/ / // /_/ /| |/ |/ /
  57. /_/ |_|/_/ |_|\____//_/ /_/ \____/ |__/|__/
  58. """)
  59. logging.info(
  60. f'RAGFlow version: {get_ragflow_version()}'
  61. )
  62. logging.info(
  63. f'project base: {utils.file_utils.get_project_base_directory()}'
  64. )
  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="rag flow 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=HOST, HTTP_PORT=HTTP_PORT)
  86. thr = ThreadPoolExecutor(max_workers=1)
  87. thr.submit(update_progress)
  88. # start http server
  89. try:
  90. logging.info("RAGFlow HTTP server start...")
  91. run_simple(
  92. hostname=HOST,
  93. port=HTTP_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)