Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. stat_logger.info(
  34. f'project base: {utils.file_utils.get_project_base_directory()}'
  35. )
  36. # init db
  37. init_web_db()
  38. init_web_data()
  39. # init runtime config
  40. import argparse
  41. parser = argparse.ArgumentParser()
  42. parser.add_argument('--version', default=False, help="rag flow version", action='store_true')
  43. parser.add_argument('--debug', default=False, help="debug mode", action='store_true')
  44. args = parser.parse_args()
  45. if args.version:
  46. print(get_versions())
  47. sys.exit(0)
  48. RuntimeConfig.DEBUG = args.debug
  49. if RuntimeConfig.DEBUG:
  50. stat_logger.info("run on debug mode")
  51. RuntimeConfig.init_env()
  52. RuntimeConfig.init_config(JOB_SERVER_HOST=HOST, HTTP_PORT=HTTP_PORT)
  53. peewee_logger = logging.getLogger('peewee')
  54. peewee_logger.propagate = False
  55. # rag_arch.common.log.ROpenHandler
  56. peewee_logger.addHandler(database_logger.handlers[0])
  57. peewee_logger.setLevel(database_logger.level)
  58. # start http server
  59. try:
  60. stat_logger.info("RAG Flow http server start...")
  61. werkzeug_logger = logging.getLogger("werkzeug")
  62. for h in access_logger.handlers:
  63. werkzeug_logger.addHandler(h)
  64. run_simple(hostname=HOST, port=HTTP_PORT, application=app, threaded=True, use_reloader=RuntimeConfig.DEBUG, use_debugger=RuntimeConfig.DEBUG)
  65. except Exception:
  66. traceback.print_exc()
  67. os.kill(os.getpid(), signal.SIGKILL)