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.

преди 1 година
преди 1 година
преди 1 година
преди 1 година
преди 1 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. # Logger
  22. LoggerFactory.set_directory(os.path.join(get_project_base_directory(), "logs", "api"))
  23. # {CRITICAL: 50, FATAL:50, ERROR:40, WARNING:30, WARN:30, INFO:20, DEBUG:10, NOTSET:0}
  24. LoggerFactory.LEVEL = 10
  25. stat_logger = getLogger("stat")
  26. access_logger = getLogger("access")
  27. database_logger = getLogger("database")
  28. API_VERSION = "v1"
  29. RAG_FLOW_SERVICE_NAME = "ragflow"
  30. SERVER_MODULE = "rag_flow_server.py"
  31. TEMP_DIRECTORY = os.path.join(get_project_base_directory(), "temp")
  32. RAG_FLOW_CONF_PATH = os.path.join(get_project_base_directory(), "conf")
  33. SUBPROCESS_STD_LOG_NAME = "std.log"
  34. ERROR_REPORT = True
  35. ERROR_REPORT_WITH_PATH = False
  36. MAX_TIMESTAMP_INTERVAL = 60
  37. SESSION_VALID_PERIOD = 7 * 24 * 60 * 60 * 1000
  38. REQUEST_TRY_TIMES = 3
  39. REQUEST_WAIT_SEC = 2
  40. REQUEST_MAX_WAIT_SEC = 300
  41. USE_REGISTRY = get_base_config("use_registry")
  42. default_llm = {
  43. "通义千问": {
  44. "chat_model": "qwen-plus",
  45. "embedding_model": "text-embedding-v2",
  46. "image2text_model": "qwen-vl-max",
  47. "asr_model": "paraformer-realtime-8k-v1",
  48. },
  49. "OpenAI": {
  50. "chat_model": "gpt-3.5-turbo",
  51. "embedding_model": "text-embedding-ada-002",
  52. "image2text_model": "gpt-4-vision-preview",
  53. "asr_model": "whisper-1",
  54. },
  55. "智谱AI": {
  56. "chat_model": "glm-3-turbo",
  57. "embedding_model": "embedding-2",
  58. "image2text_model": "glm-4v",
  59. "asr_model": "",
  60. },
  61. }
  62. LLM = get_base_config("user_default_llm", {})
  63. LLM_FACTORY = LLM.get("factory", "通义千问")
  64. if LLM_FACTORY not in default_llm:
  65. 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.")
  66. LLM_FACTORY = "通义千问"
  67. CHAT_MDL = default_llm[LLM_FACTORY]["chat_model"]
  68. EMBEDDING_MDL = default_llm[LLM_FACTORY]["embedding_model"]
  69. ASR_MDL = default_llm[LLM_FACTORY]["asr_model"]
  70. IMAGE2TEXT_MDL = default_llm[LLM_FACTORY]["image2text_model"]
  71. API_KEY = LLM.get("api_key", "infiniflow API Key")
  72. 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")
  73. # distribution
  74. DEPENDENT_DISTRIBUTION = get_base_config("dependent_distribution", False)
  75. RAG_FLOW_UPDATE_CHECK = False
  76. HOST = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("host", "127.0.0.1")
  77. HTTP_PORT = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("http_port")
  78. SECRET_KEY = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("secret_key", "infiniflow")
  79. TOKEN_EXPIRE_IN = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("token_expires_in", 3600)
  80. NGINX_HOST = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("nginx", {}).get("host") or HOST
  81. NGINX_HTTP_PORT = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("nginx", {}).get("http_port") or HTTP_PORT
  82. RANDOM_INSTANCE_ID = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("random_instance_id", False)
  83. PROXY = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("proxy")
  84. PROXY_PROTOCOL = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("protocol")
  85. DATABASE = decrypt_database_config(name="mysql")
  86. # Switch
  87. # upload
  88. UPLOAD_DATA_FROM_CLIENT = True
  89. # authentication
  90. AUTHENTICATION_CONF = get_base_config("authentication", {})
  91. # client
  92. CLIENT_AUTHENTICATION = AUTHENTICATION_CONF.get("client", {}).get("switch", False)
  93. HTTP_APP_KEY = AUTHENTICATION_CONF.get("client", {}).get("http_app_key")
  94. GITHUB_OAUTH = get_base_config("oauth", {}).get("github")
  95. WECHAT_OAUTH = get_base_config("oauth", {}).get("wechat")
  96. # site
  97. SITE_AUTHENTICATION = AUTHENTICATION_CONF.get("site", {}).get("switch", False)
  98. # permission
  99. PERMISSION_CONF = get_base_config("permission", {})
  100. PERMISSION_SWITCH = PERMISSION_CONF.get("switch")
  101. COMPONENT_PERMISSION = PERMISSION_CONF.get("component")
  102. DATASET_PERMISSION = PERMISSION_CONF.get("dataset")
  103. HOOK_MODULE = get_base_config("hook_module")
  104. HOOK_SERVER_NAME = get_base_config("hook_server_name")
  105. ENABLE_MODEL_STORE = get_base_config('enable_model_store', False)
  106. # authentication
  107. USE_AUTHENTICATION = False
  108. USE_DATA_AUTHENTICATION = False
  109. AUTOMATIC_AUTHORIZATION_OUTPUT_DATA = True
  110. USE_DEFAULT_TIMEOUT = False
  111. AUTHENTICATION_DEFAULT_TIMEOUT = 30 * 24 * 60 * 60 # s
  112. PRIVILEGE_COMMAND_WHITELIST = []
  113. CHECK_NODES_IDENTITY = False
  114. from rag.nlp import search
  115. from rag.utils import ELASTICSEARCH
  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