Blame view

config/env_config.py 3.2 KB
be52af70   tangwang   first commit
1
  """
86d8358b   tangwang   config optimize
2
  Compatibility accessors for infrastructure/runtime environment settings.
be52af70   tangwang   first commit
3
  
86d8358b   tangwang   config optimize
4
5
  All values are derived from the unified application config. This module no
  longer owns any independent loading or precedence rules.
be52af70   tangwang   first commit
6
7
  """
  
86d8358b   tangwang   config optimize
8
9
10
11
12
13
14
15
16
17
18
19
20
  from __future__ import annotations
  
  from typing import Any, Dict
  
  from config.loader import get_app_config
  
  
  def _app():
      return get_app_config()
  
  
  def _runtime():
      return _app().runtime
be52af70   tangwang   first commit
21
  
be52af70   tangwang   first commit
22
  
86d8358b   tangwang   config optimize
23
24
  def _infra():
      return _app().infrastructure
be52af70   tangwang   first commit
25
  
1852e3e3   tangwang   添加Base配置演示流程和数据库配置
26
  
86d8358b   tangwang   config optimize
27
28
29
30
31
32
33
  def _elasticsearch_dict() -> Dict[str, Any]:
      cfg = _infra().elasticsearch
      return {
          "host": cfg.host,
          "username": cfg.username,
          "password": cfg.password,
      }
be52af70   tangwang   first commit
34
  
be52af70   tangwang   first commit
35
  
86d8358b   tangwang   config optimize
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  def _redis_dict() -> Dict[str, Any]:
      cfg = _infra().redis
      return {
          "host": cfg.host,
          "port": cfg.port,
          "snapshot_db": cfg.snapshot_db,
          "password": cfg.password,
          "socket_timeout": cfg.socket_timeout,
          "socket_connect_timeout": cfg.socket_connect_timeout,
          "retry_on_timeout": cfg.retry_on_timeout,
          "cache_expire_days": cfg.cache_expire_days,
          "embedding_cache_prefix": cfg.embedding_cache_prefix,
          "anchor_cache_prefix": cfg.anchor_cache_prefix,
          "anchor_cache_expire_days": cfg.anchor_cache_expire_days,
      }
be52af70   tangwang   first commit
51
  
be52af70   tangwang   first commit
52
  
86d8358b   tangwang   config optimize
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
  def _db_dict() -> Dict[str, Any]:
      cfg = _infra().database
      return {
          "host": cfg.host,
          "port": cfg.port,
          "database": cfg.database,
          "username": cfg.username,
          "password": cfg.password,
      }
  
  
  ES_CONFIG = _elasticsearch_dict()
  REDIS_CONFIG = _redis_dict()
  DB_CONFIG = _db_dict()
  
  RUNTIME_ENV = _runtime().environment
  ES_INDEX_NAMESPACE = _runtime().index_namespace
  
  DEEPL_AUTH_KEY = _infra().secrets.deepl_auth_key
  DASHSCOPE_API_KEY = _infra().secrets.dashscope_api_key
  
  API_HOST = _runtime().api_host
  API_PORT = _runtime().api_port
  INDEXER_HOST = _runtime().indexer_host
  INDEXER_PORT = _runtime().indexer_port
  EMBEDDING_HOST = _runtime().embedding_host
  EMBEDDING_PORT = _runtime().embedding_port
  EMBEDDING_TEXT_HOST = _runtime().embedding_host
  EMBEDDING_TEXT_PORT = _runtime().embedding_text_port
  EMBEDDING_IMAGE_HOST = _runtime().embedding_host
  EMBEDDING_IMAGE_PORT = _runtime().embedding_image_port
  TRANSLATION_HOST = _runtime().translator_host
  TRANSLATION_PORT = _runtime().translator_port
  RERANKER_HOST = _runtime().reranker_host
  RERANKER_PORT = _runtime().reranker_port
  
  API_BASE_URL = f"http://localhost:{API_PORT}" if API_HOST == "0.0.0.0" else f"http://{API_HOST}:{API_PORT}"
  INDEXER_BASE_URL = (
      f"http://localhost:{INDEXER_PORT}" if INDEXER_HOST == "0.0.0.0" else f"http://{INDEXER_HOST}:{INDEXER_PORT}"
  )
  EMBEDDING_TEXT_SERVICE_URL = _app().services.embedding.get_provider_config().get("text_base_url")
  EMBEDDING_IMAGE_SERVICE_URL = _app().services.embedding.get_provider_config().get("image_base_url")
  RERANKER_SERVICE_URL = (
      _app().services.rerank.get_provider_config().get("service_url")
      or _app().services.rerank.get_provider_config().get("base_url")
  )
  
be52af70   tangwang   first commit
100
  
86d8358b   tangwang   config optimize
101
102
  def get_es_config() -> Dict[str, Any]:
      return dict(ES_CONFIG)
be52af70   tangwang   first commit
103
  
be52af70   tangwang   first commit
104
  
86d8358b   tangwang   config optimize
105
106
  def get_db_config() -> Dict[str, Any]:
      return dict(DB_CONFIG)
be52af70   tangwang   first commit
107
  
1852e3e3   tangwang   添加Base配置演示流程和数据库配置
108
  
86d8358b   tangwang   config optimize
109
110
  def get_redis_config() -> Dict[str, Any]:
      return dict(REDIS_CONFIG)
be52af70   tangwang   first commit
111
112
  
  
86d8358b   tangwang   config optimize
113
114
115
  def print_config() -> None:
      config = _app().sanitized_dict()
      print(config)