您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ragflow_server.py 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 os
  18. import signal
  19. import sys
  20. import time
  21. import traceback
  22. from concurrent.futures import ThreadPoolExecutor
  23. from werkzeug.serving import run_simple
  24. from api.apps import app
  25. from api.db.runtime_config import RuntimeConfig
  26. from api.db.services.document_service import DocumentService
  27. from api.settings import (
  28. HOST, HTTP_PORT, access_logger, database_logger, stat_logger,
  29. )
  30. from api import utils
  31. from api.db.db_models import init_database_tables as init_web_db
  32. from api.db.init_data import init_web_data
  33. from api.versions import get_versions
  34. def update_progress():
  35. while True:
  36. time.sleep(1)
  37. try:
  38. DocumentService.update_progress()
  39. except Exception as e:
  40. stat_logger.error("update_progress exception:" + str(e))
  41. if __name__ == '__main__':
  42. print(r"""
  43. ____ ______ __
  44. / __ \ ____ _ ____ _ / ____// /____ _ __
  45. / /_/ // __ `// __ `// /_ / // __ \| | /| / /
  46. / _, _// /_/ // /_/ // __/ / // /_/ /| |/ |/ /
  47. /_/ |_| \__,_/ \__, //_/ /_/ \____/ |__/|__/
  48. /____/
  49. """, flush=True)
  50. stat_logger.info(
  51. f'project base: {utils.file_utils.get_project_base_directory()}'
  52. )
  53. # init db
  54. init_web_db()
  55. init_web_data()
  56. # init runtime config
  57. import argparse
  58. parser = argparse.ArgumentParser()
  59. parser.add_argument('--version', default=False, help="rag flow version", action='store_true')
  60. parser.add_argument('--debug', default=False, help="debug mode", action='store_true')
  61. args = parser.parse_args()
  62. if args.version:
  63. print(get_versions())
  64. sys.exit(0)
  65. RuntimeConfig.DEBUG = args.debug
  66. if RuntimeConfig.DEBUG:
  67. stat_logger.info("run on debug mode")
  68. RuntimeConfig.init_env()
  69. RuntimeConfig.init_config(JOB_SERVER_HOST=HOST, HTTP_PORT=HTTP_PORT)
  70. peewee_logger = logging.getLogger('peewee')
  71. peewee_logger.propagate = False
  72. # rag_arch.common.log.ROpenHandler
  73. peewee_logger.addHandler(database_logger.handlers[0])
  74. peewee_logger.setLevel(database_logger.level)
  75. thr = ThreadPoolExecutor(max_workers=1)
  76. thr.submit(update_progress)
  77. # start http server
  78. try:
  79. stat_logger.info("RAG Flow http server start...")
  80. werkzeug_logger = logging.getLogger("werkzeug")
  81. for h in access_logger.handlers:
  82. werkzeug_logger.addHandler(h)
  83. run_simple(hostname=HOST, port=HTTP_PORT, application=app, threaded=True, use_reloader=RuntimeConfig.DEBUG, use_debugger=RuntimeConfig.DEBUG)
  84. except Exception:
  85. traceback.print_exc()
  86. os.kill(os.getpid(), signal.SIGKILL)