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

ragflow_server.py 2.9KB

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