Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ragflow_server.py 3.3KB

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