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

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