Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ragflow_server.py 2.9KB

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