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

settings.py 5.7KB

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 datetime import date
  18. from enum import IntEnum, Enum
  19. import rag.utils.es_conn
  20. import rag.utils.infinity_conn
  21. import rag.utils
  22. from rag.nlp import search
  23. from graphrag import search as kg_search
  24. from api.utils import get_base_config, decrypt_database_config
  25. API_VERSION = "v1"
  26. RAG_FLOW_SERVICE_NAME = "ragflow"
  27. LIGHTEN = int(os.environ.get('LIGHTEN', "0"))
  28. REQUEST_WAIT_SEC = 2
  29. REQUEST_MAX_WAIT_SEC = 300
  30. LLM = get_base_config("user_default_llm", {})
  31. LLM_FACTORY = LLM.get("factory", "Tongyi-Qianwen")
  32. LLM_BASE_URL = LLM.get("base_url")
  33. CHAT_MDL = EMBEDDING_MDL = RERANK_MDL = ASR_MDL = IMAGE2TEXT_MDL = ""
  34. if not LIGHTEN:
  35. default_llm = {
  36. "Tongyi-Qianwen": {
  37. "chat_model": "qwen-plus",
  38. "embedding_model": "text-embedding-v2",
  39. "image2text_model": "qwen-vl-max",
  40. "asr_model": "paraformer-realtime-8k-v1",
  41. },
  42. "OpenAI": {
  43. "chat_model": "gpt-3.5-turbo",
  44. "embedding_model": "text-embedding-ada-002",
  45. "image2text_model": "gpt-4-vision-preview",
  46. "asr_model": "whisper-1",
  47. },
  48. "Azure-OpenAI": {
  49. "chat_model": "gpt-35-turbo",
  50. "embedding_model": "text-embedding-ada-002",
  51. "image2text_model": "gpt-4-vision-preview",
  52. "asr_model": "whisper-1",
  53. },
  54. "ZHIPU-AI": {
  55. "chat_model": "glm-3-turbo",
  56. "embedding_model": "embedding-2",
  57. "image2text_model": "glm-4v",
  58. "asr_model": "",
  59. },
  60. "Ollama": {
  61. "chat_model": "qwen-14B-chat",
  62. "embedding_model": "flag-embedding",
  63. "image2text_model": "",
  64. "asr_model": "",
  65. },
  66. "Moonshot": {
  67. "chat_model": "moonshot-v1-8k",
  68. "embedding_model": "",
  69. "image2text_model": "",
  70. "asr_model": "",
  71. },
  72. "DeepSeek": {
  73. "chat_model": "deepseek-chat",
  74. "embedding_model": "",
  75. "image2text_model": "",
  76. "asr_model": "",
  77. },
  78. "VolcEngine": {
  79. "chat_model": "",
  80. "embedding_model": "",
  81. "image2text_model": "",
  82. "asr_model": "",
  83. },
  84. "BAAI": {
  85. "chat_model": "",
  86. "embedding_model": "BAAI/bge-large-zh-v1.5",
  87. "image2text_model": "",
  88. "asr_model": "",
  89. "rerank_model": "BAAI/bge-reranker-v2-m3",
  90. }
  91. }
  92. if LLM_FACTORY:
  93. CHAT_MDL = default_llm[LLM_FACTORY]["chat_model"] + f"@{LLM_FACTORY}"
  94. ASR_MDL = default_llm[LLM_FACTORY]["asr_model"] + f"@{LLM_FACTORY}"
  95. IMAGE2TEXT_MDL = default_llm[LLM_FACTORY]["image2text_model"] + f"@{LLM_FACTORY}"
  96. EMBEDDING_MDL = default_llm["BAAI"]["embedding_model"] + "@BAAI"
  97. RERANK_MDL = default_llm["BAAI"]["rerank_model"] + "@BAAI"
  98. API_KEY = LLM.get("api_key", "")
  99. PARSERS = LLM.get(
  100. "parsers",
  101. "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")
  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("secret_key", str(date.today()))
  107. DATABASE_TYPE = os.getenv("DB_TYPE", 'mysql')
  108. DATABASE = decrypt_database_config(name=DATABASE_TYPE)
  109. # authentication
  110. AUTHENTICATION_CONF = get_base_config("authentication", {})
  111. # client
  112. CLIENT_AUTHENTICATION = AUTHENTICATION_CONF.get(
  113. "client", {}).get(
  114. "switch", False)
  115. HTTP_APP_KEY = AUTHENTICATION_CONF.get("client", {}).get("http_app_key")
  116. GITHUB_OAUTH = get_base_config("oauth", {}).get("github")
  117. FEISHU_OAUTH = get_base_config("oauth", {}).get("feishu")
  118. DOC_ENGINE = os.environ.get('DOC_ENGINE', "elasticsearch")
  119. if DOC_ENGINE == "elasticsearch":
  120. docStoreConn = rag.utils.es_conn.ESConnection()
  121. elif DOC_ENGINE == "infinity":
  122. docStoreConn = rag.utils.infinity_conn.InfinityConnection()
  123. else:
  124. raise Exception(f"Not supported doc engine: {DOC_ENGINE}")
  125. retrievaler = search.Dealer(docStoreConn)
  126. kg_retrievaler = kg_search.KGSearch(docStoreConn)
  127. class CustomEnum(Enum):
  128. @classmethod
  129. def valid(cls, value):
  130. try:
  131. cls(value)
  132. return True
  133. except BaseException:
  134. return False
  135. @classmethod
  136. def values(cls):
  137. return [member.value for member in cls.__members__.values()]
  138. @classmethod
  139. def names(cls):
  140. return [member.name for member in cls.__members__.values()]
  141. class PythonDependenceName(CustomEnum):
  142. Rag_Source_Code = "python"
  143. Python_Env = "miniconda"
  144. class ModelStorage(CustomEnum):
  145. REDIS = "redis"
  146. MYSQL = "mysql"
  147. class RetCode(IntEnum, CustomEnum):
  148. SUCCESS = 0
  149. NOT_EFFECTIVE = 10
  150. EXCEPTION_ERROR = 100
  151. ARGUMENT_ERROR = 101
  152. DATA_ERROR = 102
  153. OPERATING_ERROR = 103
  154. CONNECTION_ERROR = 105
  155. RUNNING = 106
  156. PERMISSION_ERROR = 108
  157. AUTHENTICATION_ERROR = 109
  158. UNAUTHORIZED = 401
  159. SERVER_ERROR = 500
  160. FORBIDDEN = 403
  161. NOT_FOUND = 404