be52af70
tangwang
first commit
|
1
|
"""
|
a7920e17
tangwang
项目名称和部署路径修改
|
2
|
Centralized configuration management for saas-search.
|
be52af70
tangwang
first commit
|
3
4
|
Loads configuration from environment variables and .env file.
|
325eec03
tangwang
1. 日志、配置基础设施,使用优化
|
5
6
|
This module provides a single point for loading .env and setting defaults.
All configuration variables are exported directly - no need for getter functions.
|
be52af70
tangwang
first commit
|
7
8
9
10
|
"""
import os
from pathlib import Path
|
be52af70
tangwang
first commit
|
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
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'),
}
|
648cb4c2
tangwang
ES docs
|
25
26
27
28
29
30
31
32
33
34
|
# Runtime environment & index namespace
# RUNTIME_ENV: 当前运行环境,建议使用 prod / uat / test / dev 等枚举值
RUNTIME_ENV = os.getenv('RUNTIME_ENV', 'prod')
# ES_INDEX_NAMESPACE: 用于按环境隔离索引的命名空间前缀,例如 "uat_" / "test_"
# 为空字符串时表示不加前缀(通常是 prod 环境)
ES_INDEX_NAMESPACE = os.getenv('ES_INDEX_NAMESPACE')
if ES_INDEX_NAMESPACE is None:
# 未显式配置时,非 prod 环境默认加 "<env>_" 前缀,prod 环境默认不加前缀
ES_INDEX_NAMESPACE = '' if RUNTIME_ENV == 'prod' else f'{RUNTIME_ENV}_'
|
be52af70
tangwang
first commit
|
35
36
37
38
|
# Redis Configuration
REDIS_CONFIG = {
'host': os.getenv('REDIS_HOST', 'localhost'),
'port': int(os.getenv('REDIS_PORT', 6479)),
|
453992a8
tangwang
需求:
|
39
40
41
42
43
|
'snapshot_db': int(os.getenv('REDIS_SNAPSHOT_DB', 0)),
'password': os.getenv('REDIS_PASSWORD', 'BMfv5aI31kgHWtlx'),
'socket_timeout': int(os.getenv('REDIS_SOCKET_TIMEOUT', 1)),
'socket_connect_timeout': int(os.getenv('REDIS_SOCKET_CONNECT_TIMEOUT', 1)),
'retry_on_timeout': os.getenv('REDIS_RETRY_ON_TIMEOUT', 'False').lower() == 'true',
|
5ac64fc7
tangwang
多语言查询
|
44
45
|
'cache_expire_days': int(os.getenv('REDIS_CACHE_EXPIRE_DAYS', 360*2)), # 6 months
'translation_cache_expire_days': int(os.getenv('REDIS_TRANSLATION_CACHE_EXPIRE_DAYS', 360*2)),
|
453992a8
tangwang
需求:
|
46
|
'translation_cache_prefix': os.getenv('REDIS_TRANSLATION_CACHE_PREFIX', 'trans'),
|
be52af70
tangwang
first commit
|
47
48
49
50
51
|
}
# DeepL API Key
DEEPL_AUTH_KEY = os.getenv('DEEPL_AUTH_KEY')
|
3cd09b3b
tangwang
翻译接口改为调用qwen-mt-f...
|
52
53
54
|
# DashScope API Key (for Qwen models)
DASHSCOPE_API_KEY = os.getenv('DASHSCOPE_API_KEY')
|
be52af70
tangwang
first commit
|
55
56
|
# API Service Configuration
API_HOST = os.getenv('API_HOST', '0.0.0.0')
|
2a76641e
tangwang
config
|
57
|
API_PORT = int(os.getenv('API_PORT', 6002))
|
d1d356f8
tangwang
脚本优化
|
58
59
60
61
62
63
64
65
|
# Indexer service
INDEXER_HOST = os.getenv('INDEXER_HOST', '0.0.0.0')
INDEXER_PORT = int(os.getenv('INDEXER_PORT', 6004))
# Optional dependent services
EMBEDDING_HOST = os.getenv('EMBEDDING_HOST', '127.0.0.1')
EMBEDDING_PORT = int(os.getenv('EMBEDDING_PORT', 6005))
TRANSLATION_HOST = os.getenv('TRANSLATION_HOST', '127.0.0.1')
TRANSLATION_PORT = int(os.getenv('TRANSLATION_PORT', os.getenv('TRANSLATOR_PORT', 6006)))
|
42e3aea6
tangwang
tidy
|
66
67
|
TRANSLATION_PROVIDER = os.getenv('TRANSLATION_PROVIDER', 'direct')
TRANSLATION_MODEL = os.getenv('TRANSLATION_MODEL', 'qwen')
|
d1d356f8
tangwang
脚本优化
|
68
69
|
RERANKER_HOST = os.getenv('RERANKER_HOST', '127.0.0.1')
RERANKER_PORT = int(os.getenv('RERANKER_PORT', 6007))
|
42e3aea6
tangwang
tidy
|
70
|
RERANK_PROVIDER = os.getenv('RERANK_PROVIDER', 'http')
|
362d43b6
tangwang
店匠体系数据的搜索
|
71
72
73
74
|
# API_BASE_URL: 如果未设置,根据API_HOST构建(0.0.0.0使用localhost)
API_BASE_URL = os.getenv('API_BASE_URL')
if not API_BASE_URL:
API_BASE_URL = f'http://localhost:{API_PORT}' if API_HOST == '0.0.0.0' else f'http://{API_HOST}:{API_PORT}'
|
d1d356f8
tangwang
脚本优化
|
75
76
77
78
79
80
|
INDEXER_BASE_URL = os.getenv('INDEXER_BASE_URL') or (
f'http://localhost:{INDEXER_PORT}' if INDEXER_HOST == '0.0.0.0' else f'http://{INDEXER_HOST}:{INDEXER_PORT}'
)
EMBEDDING_SERVICE_URL = os.getenv('EMBEDDING_SERVICE_URL') or f'http://{EMBEDDING_HOST}:{EMBEDDING_PORT}'
TRANSLATION_SERVICE_URL = os.getenv('TRANSLATION_SERVICE_URL') or f'http://{TRANSLATION_HOST}:{TRANSLATION_PORT}'
RERANKER_SERVICE_URL = os.getenv('RERANKER_SERVICE_URL') or f'http://{RERANKER_HOST}:{RERANKER_PORT}/rerank'
|
be52af70
tangwang
first commit
|
81
82
83
84
85
86
87
88
|
# 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配置演示流程和数据库配置
|
89
90
|
# MySQL Database Configuration (Shoplazza)
DB_CONFIG = {
|
fb68a0ef
tangwang
配置优化
|
91
92
93
94
95
|
'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配置演示流程和数据库配置
|
96
97
|
}
|
be52af70
tangwang
first commit
|
98
|
|
be52af70
tangwang
first commit
|
99
100
101
|
def print_config():
"""Print current configuration (with sensitive data masked)."""
print("=" * 60)
|
a7920e17
tangwang
项目名称和部署路径修改
|
102
|
print("saas-search Configuration")
|
be52af70
tangwang
first commit
|
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
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)'}")
|
be52af70
tangwang
first commit
|
118
119
120
121
122
123
124
125
126
127
128
|
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配置演示流程和数据库配置
|
129
130
131
132
133
134
135
|
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
|
136
137
138
139
140
|
print("=" * 60)
if __name__ == "__main__":
print_config()
|