You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

settings.py 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 os
  17. from enum import IntEnum, Enum
  18. from api.utils import get_base_config,decrypt_database_config
  19. from api.utils.file_utils import get_project_base_directory
  20. from api.utils.log_utils import LoggerFactory, getLogger
  21. from rag.nlp import search
  22. from rag.utils import ELASTICSEARCH
  23. API_VERSION = "v1"
  24. RAG_FLOW_SERVICE_NAME = "ragflow"
  25. SERVER_MODULE = "rag_flow_server.py"
  26. TEMP_DIRECTORY = os.path.join(get_project_base_directory(), "temp")
  27. RAG_FLOW_CONF_PATH = os.path.join(get_project_base_directory(), "conf")
  28. SUBPROCESS_STD_LOG_NAME = "std.log"
  29. ERROR_REPORT = True
  30. ERROR_REPORT_WITH_PATH = False
  31. MAX_TIMESTAMP_INTERVAL = 60
  32. SESSION_VALID_PERIOD = 7 * 24 * 60 * 60 * 1000
  33. REQUEST_TRY_TIMES = 3
  34. REQUEST_WAIT_SEC = 2
  35. REQUEST_MAX_WAIT_SEC = 300
  36. USE_REGISTRY = get_base_config("use_registry")
  37. LLM = get_base_config("user_default_llm", {})
  38. LLM_FACTORY=LLM.get("factory", "通义千问")
  39. CHAT_MDL = LLM.get("chat_model", "qwen-plus")
  40. EMBEDDING_MDL = LLM.get("embedding_model", "text-embedding-v2")
  41. ASR_MDL = LLM.get("asr_model", "paraformer-realtime-8k-v1")
  42. IMAGE2TEXT_MDL = LLM.get("image2text_model", "qwen-vl-max")
  43. API_KEY = LLM.get("api_key", "infiniflow API Key")
  44. PARSERS = LLM.get("parsers", "general:General,qa:Q&A,resume:Resume,naive:Naive,table:Table,laws:Laws,manual:Manual,book:Book,paper:Paper,presentation:Presentation,picture:Picture")
  45. # distribution
  46. DEPENDENT_DISTRIBUTION = get_base_config("dependent_distribution", False)
  47. RAG_FLOW_UPDATE_CHECK = False
  48. HOST = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("host", "127.0.0.1")
  49. HTTP_PORT = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("http_port")
  50. SECRET_KEY = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("secret_key", "infiniflow")
  51. TOKEN_EXPIRE_IN = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("token_expires_in", 3600)
  52. NGINX_HOST = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("nginx", {}).get("host") or HOST
  53. NGINX_HTTP_PORT = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("nginx", {}).get("http_port") or HTTP_PORT
  54. RANDOM_INSTANCE_ID = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("random_instance_id", False)
  55. PROXY = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("proxy")
  56. PROXY_PROTOCOL = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("protocol")
  57. DATABASE = decrypt_database_config()
  58. # Logger
  59. LoggerFactory.set_directory(os.path.join(get_project_base_directory(), "logs", "api"))
  60. # {CRITICAL: 50, FATAL:50, ERROR:40, WARNING:30, WARN:30, INFO:20, DEBUG:10, NOTSET:0}
  61. LoggerFactory.LEVEL = 10
  62. stat_logger = getLogger("stat")
  63. access_logger = getLogger("access")
  64. database_logger = getLogger("database")
  65. # Switch
  66. # upload
  67. UPLOAD_DATA_FROM_CLIENT = True
  68. # authentication
  69. AUTHENTICATION_CONF = get_base_config("authentication", {})
  70. # client
  71. CLIENT_AUTHENTICATION = AUTHENTICATION_CONF.get("client", {}).get("switch", False)
  72. HTTP_APP_KEY = AUTHENTICATION_CONF.get("client", {}).get("http_app_key")
  73. GITHUB_OAUTH = get_base_config("oauth", {}).get("github")
  74. WECHAT_OAUTH = get_base_config("oauth", {}).get("wechat")
  75. # site
  76. SITE_AUTHENTICATION = AUTHENTICATION_CONF.get("site", {}).get("switch", False)
  77. # permission
  78. PERMISSION_CONF = get_base_config("permission", {})
  79. PERMISSION_SWITCH = PERMISSION_CONF.get("switch")
  80. COMPONENT_PERMISSION = PERMISSION_CONF.get("component")
  81. DATASET_PERMISSION = PERMISSION_CONF.get("dataset")
  82. HOOK_MODULE = get_base_config("hook_module")
  83. HOOK_SERVER_NAME = get_base_config("hook_server_name")
  84. ENABLE_MODEL_STORE = get_base_config('enable_model_store', False)
  85. # authentication
  86. USE_AUTHENTICATION = False
  87. USE_DATA_AUTHENTICATION = False
  88. AUTOMATIC_AUTHORIZATION_OUTPUT_DATA = True
  89. USE_DEFAULT_TIMEOUT = False
  90. AUTHENTICATION_DEFAULT_TIMEOUT = 30 * 24 * 60 * 60 # s
  91. PRIVILEGE_COMMAND_WHITELIST = []
  92. CHECK_NODES_IDENTITY = False
  93. retrievaler = search.Dealer(ELASTICSEARCH)
  94. class CustomEnum(Enum):
  95. @classmethod
  96. def valid(cls, value):
  97. try:
  98. cls(value)
  99. return True
  100. except:
  101. return False
  102. @classmethod
  103. def values(cls):
  104. return [member.value for member in cls.__members__.values()]
  105. @classmethod
  106. def names(cls):
  107. return [member.name for member in cls.__members__.values()]
  108. class PythonDependenceName(CustomEnum):
  109. Rag_Source_Code = "python"
  110. Python_Env = "miniconda"
  111. class ModelStorage(CustomEnum):
  112. REDIS = "redis"
  113. MYSQL = "mysql"
  114. class RetCode(IntEnum, CustomEnum):
  115. SUCCESS = 0
  116. NOT_EFFECTIVE = 10
  117. EXCEPTION_ERROR = 100
  118. ARGUMENT_ERROR = 101
  119. DATA_ERROR = 102
  120. OPERATING_ERROR = 103
  121. CONNECTION_ERROR = 105
  122. RUNNING = 106
  123. PERMISSION_ERROR = 108
  124. AUTHENTICATION_ERROR = 109
  125. SERVER_ERROR = 500