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 6.8KB

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