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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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(3)
  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. """, flush=True)
  49. stat_logger.info(
  50. f'project base: {utils.file_utils.get_project_base_directory()}'
  51. )
  52. # init db
  53. init_web_db()
  54. init_web_data()
  55. # init runtime config
  56. import argparse
  57. parser = argparse.ArgumentParser()
  58. parser.add_argument('--version', default=False, help="rag flow version", action='store_true')
  59. parser.add_argument('--debug', default=False, help="debug mode", action='store_true')
  60. args = parser.parse_args()
  61. if args.version:
  62. print(get_versions())
  63. sys.exit(0)
  64. RuntimeConfig.DEBUG = args.debug
  65. if RuntimeConfig.DEBUG:
  66. stat_logger.info("run on debug mode")
  67. RuntimeConfig.init_env()
  68. RuntimeConfig.init_config(JOB_SERVER_HOST=HOST, HTTP_PORT=HTTP_PORT)
  69. peewee_logger = logging.getLogger('peewee')
  70. peewee_logger.propagate = False
  71. # rag_arch.common.log.ROpenHandler
  72. peewee_logger.addHandler(database_logger.handlers[0])
  73. peewee_logger.setLevel(database_logger.level)
  74. thr = ThreadPoolExecutor(max_workers=1)
  75. thr.submit(update_progress)
  76. # start http server
  77. try:
  78. stat_logger.info("RAG Flow http server start...")
  79. werkzeug_logger = logging.getLogger("werkzeug")
  80. for h in access_logger.handlers:
  81. werkzeug_logger.addHandler(h)
  82. run_simple(hostname=HOST, port=HTTP_PORT, application=app, threaded=True, use_reloader=RuntimeConfig.DEBUG, use_debugger=RuntimeConfig.DEBUG)
  83. except Exception:
  84. traceback.print_exc()
  85. os.kill(os.getpid(), signal.SIGKILL)