您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

settings.py 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. default_llm = {
  38. "通义千问": {
  39. "chat_model": "qwen-plus",
  40. "embedding_model": "text-embedding-v2",
  41. "image2text_model": "qwen-vl-max",
  42. "asr_model": "paraformer-realtime-8k-v1",
  43. },
  44. "OpenAI": {
  45. "chat_model": "gpt-3.5-turbo",
  46. "embedding_model": "text-embedding-ada-002",
  47. "image2text_model": "gpt-4-vision-preview",
  48. "asr_model": "whisper-1",
  49. },
  50. "智普AI": {
  51. "chat_model": "glm-3-turbo",
  52. "embedding_model": "embedding-2",
  53. "image2text_model": "glm-4v",
  54. "asr_model": "",
  55. },
  56. }
  57. LLM = get_base_config("user_default_llm", {})
  58. LLM_FACTORY = LLM.get("factory", "通义千问")
  59. if LLM_FACTORY not in default_llm:
  60. print("\33[91m【ERROR】\33[0m:", f"LLM factory {LLM_FACTORY} has not supported yet, switch to '通义千问/QWen' automatically, and please check the API_KEY in service_conf.yaml.")
  61. LLM_FACTORY = "通义千问"
  62. CHAT_MDL = default_llm[LLM_FACTORY]["chat_model"]
  63. EMBEDDING_MDL = default_llm[LLM_FACTORY]["embedding_model"]
  64. ASR_MDL = default_llm[LLM_FACTORY]["asr_model"]
  65. IMAGE2TEXT_MDL = default_llm[LLM_FACTORY]["image2text_model"]
  66. API_KEY = LLM.get("api_key", "infiniflow API Key")
  67. PARSERS = LLM.get("parsers", "naive:General,qa:Q&A,resume:Resume,table:Table,laws:Laws,manual:Manual,book:Book,paper:Paper,presentation:Presentation,picture:Picture")
  68. # distribution
  69. DEPENDENT_DISTRIBUTION = get_base_config("dependent_distribution", False)
  70. RAG_FLOW_UPDATE_CHECK = False
  71. HOST = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("host", "127.0.0.1")
  72. HTTP_PORT = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("http_port")
  73. SECRET_KEY = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("secret_key", "infiniflow")
  74. TOKEN_EXPIRE_IN = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("token_expires_in", 3600)
  75. NGINX_HOST = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("nginx", {}).get("host") or HOST
  76. NGINX_HTTP_PORT = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("nginx", {}).get("http_port") or HTTP_PORT
  77. RANDOM_INSTANCE_ID = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("random_instance_id", False)
  78. PROXY = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("proxy")
  79. PROXY_PROTOCOL = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("protocol")
  80. DATABASE = decrypt_database_config(name="mysql")
  81. # Logger
  82. LoggerFactory.set_directory(os.path.join(get_project_base_directory(), "logs", "api"))
  83. # {CRITICAL: 50, FATAL:50, ERROR:40, WARNING:30, WARN:30, INFO:20, DEBUG:10, NOTSET:0}
  84. LoggerFactory.LEVEL = 10
  85. stat_logger = getLogger("stat")
  86. access_logger = getLogger("access")
  87. database_logger = getLogger("database")
  88. # Switch
  89. # upload
  90. UPLOAD_DATA_FROM_CLIENT = True
  91. # authentication
  92. AUTHENTICATION_CONF = get_base_config("authentication", {})
  93. # client
  94. CLIENT_AUTHENTICATION = AUTHENTICATION_CONF.get("client", {}).get("switch", False)
  95. HTTP_APP_KEY = AUTHENTICATION_CONF.get("client", {}).get("http_app_key")
  96. GITHUB_OAUTH = get_base_config("oauth", {}).get("github")
  97. WECHAT_OAUTH = get_base_config("oauth", {}).get("wechat")
  98. # site
  99. SITE_AUTHENTICATION = AUTHENTICATION_CONF.get("site", {}).get("switch", False)
  100. # permission
  101. PERMISSION_CONF = get_base_config("permission", {})
  102. PERMISSION_SWITCH = PERMISSION_CONF.get("switch")
  103. COMPONENT_PERMISSION = PERMISSION_CONF.get("component")
  104. DATASET_PERMISSION = PERMISSION_CONF.get("dataset")
  105. HOOK_MODULE = get_base_config("hook_module")
  106. HOOK_SERVER_NAME = get_base_config("hook_server_name")
  107. ENABLE_MODEL_STORE = get_base_config('enable_model_store', False)
  108. # authentication
  109. USE_AUTHENTICATION = False
  110. USE_DATA_AUTHENTICATION = False
  111. AUTOMATIC_AUTHORIZATION_OUTPUT_DATA = True
  112. USE_DEFAULT_TIMEOUT = False
  113. AUTHENTICATION_DEFAULT_TIMEOUT = 30 * 24 * 60 * 60 # s
  114. PRIVILEGE_COMMAND_WHITELIST = []
  115. CHECK_NODES_IDENTITY = False
  116. retrievaler = search.Dealer(ELASTICSEARCH)
  117. class CustomEnum(Enum):
  118. @classmethod
  119. def valid(cls, value):
  120. try:
  121. cls(value)
  122. return True
  123. except:
  124. return False
  125. @classmethod
  126. def values(cls):
  127. return [member.value for member in cls.__members__.values()]
  128. @classmethod
  129. def names(cls):
  130. return [member.name for member in cls.__members__.values()]
  131. class PythonDependenceName(CustomEnum):
  132. Rag_Source_Code = "python"
  133. Python_Env = "miniconda"
  134. class ModelStorage(CustomEnum):
  135. REDIS = "redis"
  136. MYSQL = "mysql"
  137. class RetCode(IntEnum, CustomEnum):
  138. SUCCESS = 0
  139. NOT_EFFECTIVE = 10
  140. EXCEPTION_ERROR = 100
  141. ARGUMENT_ERROR = 101
  142. DATA_ERROR = 102
  143. OPERATING_ERROR = 103
  144. CONNECTION_ERROR = 105
  145. RUNNING = 106
  146. PERMISSION_ERROR = 108
  147. AUTHENTICATION_ERROR = 109
  148. SERVER_ERROR = 500