ciyidogan commited on
Commit
61608e4
·
verified ·
1 Parent(s): 4b72ada

Update config_provider.py

Browse files
Files changed (1) hide show
  1. config_provider.py +27 -20
config_provider.py CHANGED
@@ -78,18 +78,6 @@ class GlobalConfig(BaseModel):
78
 
79
  users: List["UserConfig"] = []
80
 
81
- def is_gpt_mode(self) -> bool:
82
- """Check if running in GPT mode (any variant)"""
83
- return self.work_mode in ("gpt4o", "gpt4o-mini")
84
-
85
- def get_gpt_model(self) -> str:
86
- """Get the GPT model name for OpenAI API"""
87
- if self.work_mode == "gpt4o":
88
- return "gpt-4o"
89
- elif self.work_mode == "gpt4o-mini":
90
- return "gpt-4o-mini"
91
- return None
92
-
93
  def get_plain_token(self) -> Optional[str]:
94
  if self.cloud_token:
95
  # Lazy import to avoid circular dependency
@@ -143,13 +131,25 @@ class GlobalConfig(BaseModel):
143
  }
144
 
145
  def is_cloud_mode(self) -> bool:
146
- """Check if running in cloud mode (hfcloud or cloud)"""
147
- return self.work_mode in ("hfcloud", "cloud")
148
 
149
  def is_on_premise(self) -> bool:
150
  """Check if running in on-premise mode"""
151
  return self.work_mode == "on-premise"
152
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  # ---------------- Global -----------------
154
  class UserConfig(BaseModel):
155
  username: str
@@ -337,20 +337,27 @@ class ServiceConfig(BaseModel):
337
  class ConfigProvider:
338
  _instance: Optional[ServiceConfig] = None
339
  _CONFIG_PATH = Path(__file__).parent / "service_config.jsonc"
 
340
 
341
  @classmethod
342
  def get(cls) -> ServiceConfig:
 
343
  if cls._instance is None:
344
- cls._instance = cls._load()
345
- cls._instance.build_index()
346
- cls._check_environment_setup()
 
 
 
347
  return cls._instance
348
 
349
  @classmethod
350
  def reload(cls) -> ServiceConfig:
351
- """Force reload configuration from file"""
352
- cls._instance = None
353
- return cls.get()
 
 
354
 
355
  @classmethod
356
  def update_config(cls, config_dict: dict):
 
78
 
79
  users: List["UserConfig"] = []
80
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  def get_plain_token(self) -> Optional[str]:
82
  if self.cloud_token:
83
  # Lazy import to avoid circular dependency
 
131
  }
132
 
133
  def is_cloud_mode(self) -> bool:
134
+ """Check if running in cloud mode (anything except on-premise)"""
135
+ return self.work_mode != "on-premise"
136
 
137
  def is_on_premise(self) -> bool:
138
  """Check if running in on-premise mode"""
139
  return self.work_mode == "on-premise"
140
 
141
+ def is_gpt_mode(self) -> bool:
142
+ """Check if running in GPT mode (any variant)"""
143
+ return self.work_mode in ("gpt4o", "gpt4o-mini")
144
+
145
+ def get_gpt_model(self) -> str:
146
+ """Get the GPT model name for OpenAI API"""
147
+ if self.work_mode == "gpt4o":
148
+ return "gpt-4o"
149
+ elif self.work_mode == "gpt4o-mini":
150
+ return "gpt-4o-mini"
151
+ return None
152
+
153
  # ---------------- Global -----------------
154
  class UserConfig(BaseModel):
155
  username: str
 
337
  class ConfigProvider:
338
  _instance: Optional[ServiceConfig] = None
339
  _CONFIG_PATH = Path(__file__).parent / "service_config.jsonc"
340
+ _lock = threading.Lock() # Thread-safe access için lock
341
 
342
  @classmethod
343
  def get(cls) -> ServiceConfig:
344
+ """Get cached config - thread-safe"""
345
  if cls._instance is None:
346
+ with cls._lock:
347
+ # Double-checked locking pattern
348
+ if cls._instance is None:
349
+ cls._instance = cls._load()
350
+ cls._instance.build_index()
351
+ cls._check_environment_setup()
352
  return cls._instance
353
 
354
  @classmethod
355
  def reload(cls) -> ServiceConfig:
356
+ """Force reload configuration from file - used after UI saves"""
357
+ with cls._lock:
358
+ log("🔄 Reloading configuration...")
359
+ cls._instance = None
360
+ return cls.get()
361
 
362
  @classmethod
363
  def update_config(cls, config_dict: dict):