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

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