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.

settings.py 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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.file_utils import get_project_base_directory
  19. from api.utils.log_utils import LoggerFactory, getLogger
  20. # Logger
  21. LoggerFactory.set_directory(
  22. os.path.join(
  23. get_project_base_directory(),
  24. "logs",
  25. "api"))
  26. # {CRITICAL: 50, FATAL:50, ERROR:40, WARNING:30, WARN:30, INFO:20, DEBUG:10, NOTSET:0}
  27. LoggerFactory.LEVEL = 30
  28. stat_logger = getLogger("stat")
  29. access_logger = getLogger("access")
  30. database_logger = getLogger("database")
  31. chat_logger = getLogger("chat")
  32. from rag.utils.es_conn import ELASTICSEARCH
  33. from rag.nlp import search
  34. from graphrag import search as kg_search
  35. from api.utils import get_base_config, decrypt_database_config
  36. API_VERSION = "v1"
  37. RAG_FLOW_SERVICE_NAME = "ragflow"
  38. SERVER_MODULE = "rag_flow_server.py"
  39. TEMP_DIRECTORY = os.path.join(get_project_base_directory(), "temp")
  40. RAG_FLOW_CONF_PATH = os.path.join(get_project_base_directory(), "conf")
  41. SUBPROCESS_STD_LOG_NAME = "std.log"
  42. ERROR_REPORT = True
  43. ERROR_REPORT_WITH_PATH = False
  44. MAX_TIMESTAMP_INTERVAL = 60
  45. SESSION_VALID_PERIOD = 7 * 24 * 60 * 60
  46. REQUEST_TRY_TIMES = 3
  47. REQUEST_WAIT_SEC = 2
  48. REQUEST_MAX_WAIT_SEC = 300
  49. USE_REGISTRY = get_base_config("use_registry")
  50. default_llm = {
  51. "Tongyi-Qianwen": {
  52. "chat_model": "qwen-plus",
  53. "embedding_model": "text-embedding-v2",
  54. "image2text_model": "qwen-vl-max",
  55. "asr_model": "paraformer-realtime-8k-v1",
  56. },
  57. "OpenAI": {
  58. "chat_model": "gpt-3.5-turbo",
  59. "embedding_model": "text-embedding-ada-002",
  60. "image2text_model": "gpt-4-vision-preview",
  61. "asr_model": "whisper-1",
  62. },
  63. "Azure-OpenAI": {
  64. "chat_model": "azure-gpt-35-turbo",
  65. "embedding_model": "azure-text-embedding-ada-002",
  66. "image2text_model": "azure-gpt-4-vision-preview",
  67. "asr_model": "azure-whisper-1",
  68. },
  69. "ZHIPU-AI": {
  70. "chat_model": "glm-3-turbo",
  71. "embedding_model": "embedding-2",
  72. "image2text_model": "glm-4v",
  73. "asr_model": "",
  74. },
  75. "Ollama": {
  76. "chat_model": "qwen-14B-chat",
  77. "embedding_model": "flag-embedding",
  78. "image2text_model": "",
  79. "asr_model": "",
  80. },
  81. "Moonshot": {
  82. "chat_model": "moonshot-v1-8k",
  83. "embedding_model": "",
  84. "image2text_model": "",
  85. "asr_model": "",
  86. },
  87. "DeepSeek": {
  88. "chat_model": "deepseek-chat",
  89. "embedding_model": "",
  90. "image2text_model": "",
  91. "asr_model": "",
  92. },
  93. "VolcEngine": {
  94. "chat_model": "",
  95. "embedding_model": "",
  96. "image2text_model": "",
  97. "asr_model": "",
  98. },
  99. "BAAI": {
  100. "chat_model": "",
  101. "embedding_model": "BAAI/bge-large-zh-v1.5",
  102. "image2text_model": "",
  103. "asr_model": "",
  104. "rerank_model": "BAAI/bge-reranker-v2-m3",
  105. }
  106. }
  107. LLM = get_base_config("user_default_llm", {})
  108. LLM_FACTORY = LLM.get("factory", "Tongyi-Qianwen")
  109. LLM_BASE_URL = LLM.get("base_url")
  110. if LLM_FACTORY not in default_llm:
  111. print(
  112. "\33[91m【ERROR】\33[0m:",
  113. f"LLM factory {LLM_FACTORY} has not supported yet, switch to 'Tongyi-Qianwen/QWen' automatically, and please check the API_KEY in service_conf.yaml.")
  114. LLM_FACTORY = "Tongyi-Qianwen"
  115. CHAT_MDL = default_llm[LLM_FACTORY]["chat_model"]
  116. EMBEDDING_MDL = default_llm["BAAI"]["embedding_model"]
  117. RERANK_MDL = default_llm["BAAI"]["rerank_model"]
  118. ASR_MDL = default_llm[LLM_FACTORY]["asr_model"]
  119. IMAGE2TEXT_MDL = default_llm[LLM_FACTORY]["image2text_model"]
  120. API_KEY = LLM.get("api_key", "")
  121. PARSERS = LLM.get(
  122. "parsers",
  123. "naive:General,qa:Q&A,resume:Resume,manual:Manual,table:Table,paper:Paper,book:Book,laws:Laws,presentation:Presentation,picture:Picture,one:One,audio:Audio,knowledge_graph:Knowledge Graph,email:Email")
  124. # distribution
  125. DEPENDENT_DISTRIBUTION = get_base_config("dependent_distribution", False)
  126. RAG_FLOW_UPDATE_CHECK = False
  127. HOST = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("host", "127.0.0.1")
  128. HTTP_PORT = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("http_port")
  129. SECRET_KEY = get_base_config(
  130. RAG_FLOW_SERVICE_NAME,
  131. {}).get(
  132. "secret_key",
  133. "infiniflow")
  134. TOKEN_EXPIRE_IN = get_base_config(
  135. RAG_FLOW_SERVICE_NAME, {}).get(
  136. "token_expires_in", 3600)
  137. NGINX_HOST = get_base_config(
  138. RAG_FLOW_SERVICE_NAME, {}).get(
  139. "nginx", {}).get("host") or HOST
  140. NGINX_HTTP_PORT = get_base_config(
  141. RAG_FLOW_SERVICE_NAME, {}).get(
  142. "nginx", {}).get("http_port") or HTTP_PORT
  143. RANDOM_INSTANCE_ID = get_base_config(
  144. RAG_FLOW_SERVICE_NAME, {}).get(
  145. "random_instance_id", False)
  146. PROXY = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("proxy")
  147. PROXY_PROTOCOL = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("protocol")
  148. DATABASE_TYPE = os.getenv("DB_TYPE", 'mysql')
  149. DATABASE = decrypt_database_config(name=DATABASE_TYPE)
  150. # Switch
  151. # upload
  152. UPLOAD_DATA_FROM_CLIENT = True
  153. # authentication
  154. AUTHENTICATION_CONF = get_base_config("authentication", {})
  155. # client
  156. CLIENT_AUTHENTICATION = AUTHENTICATION_CONF.get(
  157. "client", {}).get(
  158. "switch", False)
  159. HTTP_APP_KEY = AUTHENTICATION_CONF.get("client", {}).get("http_app_key")
  160. GITHUB_OAUTH = get_base_config("oauth", {}).get("github")
  161. FEISHU_OAUTH = get_base_config("oauth", {}).get("feishu")
  162. WECHAT_OAUTH = get_base_config("oauth", {}).get("wechat")
  163. # site
  164. SITE_AUTHENTICATION = AUTHENTICATION_CONF.get("site", {}).get("switch", False)
  165. # permission
  166. PERMISSION_CONF = get_base_config("permission", {})
  167. PERMISSION_SWITCH = PERMISSION_CONF.get("switch")
  168. COMPONENT_PERMISSION = PERMISSION_CONF.get("component")
  169. DATASET_PERMISSION = PERMISSION_CONF.get("dataset")
  170. HOOK_MODULE = get_base_config("hook_module")
  171. HOOK_SERVER_NAME = get_base_config("hook_server_name")
  172. ENABLE_MODEL_STORE = get_base_config('enable_model_store', False)
  173. # authentication
  174. USE_AUTHENTICATION = False
  175. USE_DATA_AUTHENTICATION = False
  176. AUTOMATIC_AUTHORIZATION_OUTPUT_DATA = True
  177. USE_DEFAULT_TIMEOUT = False
  178. AUTHENTICATION_DEFAULT_TIMEOUT = 7 * 24 * 60 * 60 # s
  179. PRIVILEGE_COMMAND_WHITELIST = []
  180. CHECK_NODES_IDENTITY = False
  181. retrievaler = search.Dealer(ELASTICSEARCH)
  182. kg_retrievaler = kg_search.KGSearch(ELASTICSEARCH)
  183. class CustomEnum(Enum):
  184. @classmethod
  185. def valid(cls, value):
  186. try:
  187. cls(value)
  188. return True
  189. except BaseException:
  190. return False
  191. @classmethod
  192. def values(cls):
  193. return [member.value for member in cls.__members__.values()]
  194. @classmethod
  195. def names(cls):
  196. return [member.name for member in cls.__members__.values()]
  197. class PythonDependenceName(CustomEnum):
  198. Rag_Source_Code = "python"
  199. Python_Env = "miniconda"
  200. class ModelStorage(CustomEnum):
  201. REDIS = "redis"
  202. MYSQL = "mysql"
  203. class RetCode(IntEnum, CustomEnum):
  204. SUCCESS = 0
  205. NOT_EFFECTIVE = 10
  206. EXCEPTION_ERROR = 100
  207. ARGUMENT_ERROR = 101
  208. DATA_ERROR = 102
  209. OPERATING_ERROR = 103
  210. CONNECTION_ERROR = 105
  211. RUNNING = 106
  212. PERMISSION_ERROR = 108
  213. AUTHENTICATION_ERROR = 109
  214. UNAUTHORIZED = 401
  215. SERVER_ERROR = 500