config.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. """配置管理模块,从.env文件加载环境变量"""
  2. import os
  3. from dotenv import load_dotenv
  4. # 加载.env文件中的环境变量
  5. load_dotenv()
  6. class ModelConfig:
  7. """模型配置类"""
  8. @staticmethod
  9. def get_model_provider() -> str:
  10. """获取模型提供商"""
  11. return os.getenv("MODEL_PROVIDER", "openai")
  12. @staticmethod
  13. def get_model_name() -> str:
  14. """获取模型名称"""
  15. return os.getenv("MODEL_NAME", "Qwen/Qwen3-VL-8B-Instruct")
  16. @staticmethod
  17. def get_embedding_model_name() -> str:
  18. """获取模型名称"""
  19. return os.getenv("EMBEDDING_MODEL_NAME", "Qwen/Qwen3-Embedding-0.6B")
  20. @staticmethod
  21. def get_base_url() -> str:
  22. """获取模型API基础URL"""
  23. return os.getenv("BASE_URL", "https://api.openai.com/v1")
  24. @staticmethod
  25. def get_api_key() -> str:
  26. """获取模型API密钥"""
  27. return os.getenv("API_KEY", "")
  28. @staticmethod
  29. def get_rank_model_name() -> str:
  30. """获取模型名称"""
  31. return os.getenv("RANK_MODEL_NAME", "Qwen/Qwen3-Reranker-0.6B")
  32. @staticmethod
  33. def get_model_config() -> dict:
  34. """获取完整的模型配置"""
  35. return {
  36. "model_provider": ModelConfig.get_model_provider(),
  37. "model": ModelConfig.get_model_name(),
  38. "base_url": ModelConfig.get_base_url(),
  39. "api_key": ModelConfig.get_api_key()
  40. }
  41. @staticmethod
  42. def get_embedding_model_config() -> dict:
  43. """获取完整的模型配置"""
  44. return {
  45. "model_provider": ModelConfig.get_model_provider(),
  46. "model": ModelConfig.get_embedding_model_name(),
  47. "base_url": ModelConfig.get_base_url(),
  48. "api_key": ModelConfig.get_api_key()
  49. }
  50. @staticmethod
  51. def get_multimodal_embedding_model_name() -> str:
  52. """获取多模态嵌入模型名称"""
  53. return os.getenv("MULTIMODAL_EMBEDDING_MODEL_NAME", "qwen2.5-vl-embedding")
  54. @staticmethod
  55. def get_dashscope_api_key() -> str:
  56. """获取DASHSCOPE API密钥"""
  57. return os.getenv("DASHSCOPE", "")
  58. class RagflowConfig:
  59. """RAGFLOW配置类"""
  60. # RAGFLOW配置
  61. @staticmethod
  62. def get_ragflow_api_url() -> str:
  63. """获取RAGFLOW API基础URL"""
  64. return os.getenv("RAGFLOW_API_URL", "http://192.168.16.134/")
  65. @staticmethod
  66. def get_ragflow_api_key() -> str:
  67. """获取RAGFLOW API密钥"""
  68. return os.getenv("RAGFLOW_API_KEY", "")
  69. @staticmethod
  70. def get_dataset_id() -> str:
  71. """获取数据集ID"""
  72. return os.getenv("DATASET_ID", "")
  73. @staticmethod
  74. def get_ragflow_user_name() -> str:
  75. """获取RAGFLOW用户名"""
  76. return os.getenv("RAGFLOW_USER_NAME", "")
  77. @staticmethod
  78. def get_ragflow_passwd() -> str:
  79. """获取RAGFLOW密码"""
  80. return os.getenv("RAGFLOW_PASSWD", "")
  81. class AppConfig:
  82. """应用配置类"""
  83. @staticmethod
  84. def get_log_level() -> str:
  85. """获取日志级别"""
  86. return os.getenv("LOG_LEVEL", "INFO")
  87. class MinioConfig:
  88. """MinIO配置类"""
  89. @staticmethod
  90. def get_minio_endpoint() -> str:
  91. """获取MinIO端点"""
  92. return os.getenv("MINIO_ENDPOINT", "http://localhost:9000")
  93. @staticmethod
  94. def get_minio_access_key() -> str:
  95. """获取MinIO访问密钥"""
  96. return os.getenv("MINIO_ACCESS_KEY", "minioadmin")
  97. @staticmethod
  98. def get_minio_secret_key() -> str:
  99. """获取MinIO密钥"""
  100. return os.getenv("MINIO_SECRET_KEY", "minioadmin")
  101. @staticmethod
  102. def get_minio_bucket_name() -> str:
  103. """获取MinIO存储桶名称"""
  104. return os.getenv("MINIO_BUCKET_NAME", "ragflow")
  105. @staticmethod
  106. def get_minio_secure() -> bool:
  107. """获取MinIO是否使用HTTPS"""
  108. return os.getenv("MINIO_SECURE", "False")
  109. class VectorDBConfig:
  110. """向量数据库配置类"""
  111. @staticmethod
  112. def get_vector_db_type() -> str:
  113. """获取向量数据库类型"""
  114. return os.getenv("VECTOR_DB_TYPE", "es")
  115. @staticmethod
  116. def get_infinity_host() -> str:
  117. """获取Infinity向量数据库主机"""
  118. return os.getenv("INFINITY_HOST", "localhost")
  119. @staticmethod
  120. def get_infinity_port() -> int:
  121. """获取Infinity向量数据库端口"""
  122. return int(os.getenv("INFINITY_PORT", "23820"))
  123. @staticmethod
  124. def get_infinity_sdk_port() -> int:
  125. """获取Infinity向量数据库SDK端口"""
  126. return int(os.getenv("INFINITY_SDK_PORT", "23817"))
  127. @staticmethod
  128. def get_infinity_user() -> str:
  129. """获取Infinity向量数据库用户名"""
  130. return os.getenv("INFINITY_USER", "admin")
  131. @staticmethod
  132. def get_infinity_password() -> str:
  133. """获取Infinity向量数据库密码"""
  134. return os.getenv("INFINITY_PASSWORD", "admin")
  135. @staticmethod
  136. def get_infinity_database() -> str:
  137. """获取Infinity向量数据库名称"""
  138. return os.getenv("INFINITY_DATABASE", "test")
  139. @staticmethod
  140. def get_infinity_table_name() -> str:
  141. """获取Infinity向量数据库表名"""
  142. return os.getenv("INFINITY_TABLE_NAME", "test")
  143. class TagSearchConfig:
  144. """标签搜索配置类"""
  145. @staticmethod
  146. def get_tag_db_name() -> str:
  147. """获取标签数据库名称"""
  148. return os.getenv("TAG_DB_NAME", "tag_db")
  149. @staticmethod
  150. def get_tag_table_name() -> str:
  151. """获取标签数据库表名"""
  152. return os.getenv("TAG_TABLE_NAME", "tag_table")
  153. # 导出配置实例
  154. model_config = ModelConfig.get_model_config()
  155. app_config = {
  156. "log_level": AppConfig.get_log_level()
  157. }
  158. vector_db_config = {
  159. "type": VectorDBConfig.get_vector_db_type(),
  160. "infinity": {
  161. "host": VectorDBConfig.get_infinity_host(),
  162. "port": VectorDBConfig.get_infinity_port(),
  163. "database": VectorDBConfig.get_infinity_database(),
  164. "user": VectorDBConfig.get_infinity_user(),
  165. "password": VectorDBConfig.get_infinity_password()
  166. }
  167. }