Blame view

config/env_config.py 3.31 KB
be52af70   tangwang   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  """
  Centralized configuration management for SearchEngine.
  
  Loads configuration from environment variables and .env file.
  """
  
  import os
  from pathlib import Path
  from typing import Dict, Any
  from dotenv import load_dotenv
  
  # Load .env file from project root
  PROJECT_ROOT = Path(__file__).parent.parent
  load_dotenv(PROJECT_ROOT / '.env')
  
  
  # Elasticsearch Configuration
  ES_CONFIG = {
      'host': os.getenv('ES_HOST', 'http://localhost:9200'),
      'username': os.getenv('ES_USERNAME'),
      'password': os.getenv('ES_PASSWORD'),
  }
  
  # Redis Configuration
  REDIS_CONFIG = {
      'host': os.getenv('REDIS_HOST', 'localhost'),
      'port': int(os.getenv('REDIS_PORT', 6479)),
      'password': os.getenv('REDIS_PASSWORD'),
  }
  
  # DeepL API Key
  DEEPL_AUTH_KEY = os.getenv('DEEPL_AUTH_KEY')
  
  # Customer Configuration
  CUSTOMER_ID = os.getenv('CUSTOMER_ID', 'customer1')
  
  # API Service Configuration
  API_HOST = os.getenv('API_HOST', '0.0.0.0')
2a76641e   tangwang   config
39
  API_PORT = int(os.getenv('API_PORT', 6002))
be52af70   tangwang   first commit
40
41
42
43
44
45
46
47
  
  # Model Directories
  TEXT_MODEL_DIR = os.getenv('TEXT_MODEL_DIR', '/data/tw/models/bge-m3')
  IMAGE_MODEL_DIR = os.getenv('IMAGE_MODEL_DIR', '/data/tw/models/cn-clip')
  
  # Cache Directory
  CACHE_DIR = os.getenv('CACHE_DIR', '.cache')
  
1852e3e3   tangwang   添加Base配置演示流程和数据库配置
48
49
  # MySQL Database Configuration (Shoplazza)
  DB_CONFIG = {
fb68a0ef   tangwang   配置优化
50
51
52
53
54
      'host': os.getenv('DB_HOST'),
      'port': int(os.getenv('DB_PORT', 3306)) if os.getenv('DB_PORT') else 3306,
      'database': os.getenv('DB_DATABASE'),
      'username': os.getenv('DB_USERNAME'),
      'password': os.getenv('DB_PASSWORD'),
1852e3e3   tangwang   添加Base配置演示流程和数据库配置
55
56
  }
  
be52af70   tangwang   first commit
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  
  def get_es_config() -> Dict[str, Any]:
      """Get Elasticsearch configuration."""
      return ES_CONFIG.copy()
  
  
  def get_redis_config() -> Dict[str, Any]:
      """Get Redis configuration."""
      return REDIS_CONFIG.copy()
  
  
  def get_deepl_key() -> str:
      """Get DeepL API key."""
      return DEEPL_AUTH_KEY
  
  
  def get_customer_id() -> str:
      """Get default customer ID."""
      return CUSTOMER_ID
  
  
1852e3e3   tangwang   添加Base配置演示流程和数据库配置
78
79
80
81
82
  def get_db_config() -> Dict[str, Any]:
      """Get MySQL database configuration."""
      return DB_CONFIG.copy()
  
  
be52af70   tangwang   first commit
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
  def print_config():
      """Print current configuration (with sensitive data masked)."""
      print("=" * 60)
      print("SearchEngine Configuration")
      print("=" * 60)
  
      print("\nElasticsearch:")
      print(f"  Host: {ES_CONFIG['host']}")
      print(f"  Username: {ES_CONFIG['username']}")
      print(f"  Password: {'*' * 10 if ES_CONFIG['password'] else 'None'}")
  
      print("\nRedis:")
      print(f"  Host: {REDIS_CONFIG['host']}")
      print(f"  Port: {REDIS_CONFIG['port']}")
      print(f"  Password: {'*' * 10 if REDIS_CONFIG['password'] else 'None'}")
  
      print("\nDeepL:")
      print(f"  API Key: {'*' * 10 if DEEPL_AUTH_KEY else 'None (translation disabled)'}")
  
      print("\nCustomer:")
      print(f"  Customer ID: {CUSTOMER_ID}")
  
      print("\nAPI Service:")
      print(f"  Host: {API_HOST}")
      print(f"  Port: {API_PORT}")
  
      print("\nModels:")
      print(f"  Text Model: {TEXT_MODEL_DIR}")
      print(f"  Image Model: {IMAGE_MODEL_DIR}")
  
      print("\nCache:")
      print(f"  Cache Directory: {CACHE_DIR}")
  
1852e3e3   tangwang   添加Base配置演示流程和数据库配置
116
117
118
119
120
121
122
      print("\nMySQL Database:")
      print(f"  Host: {DB_CONFIG['host']}")
      print(f"  Port: {DB_CONFIG['port']}")
      print(f"  Database: {DB_CONFIG['database']}")
      print(f"  Username: {DB_CONFIG['username']}")
      print(f"  Password: {'*' * 10 if DB_CONFIG['password'] else 'None'}")
  
be52af70   tangwang   first commit
123
124
125
126
127
      print("=" * 60)
  
  
  if __name__ == "__main__":
      print_config()