Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ragflow_server.py 2.7KB

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