Refactor SettingsServiceFactory to use SettingsService.initialize()
This commit is contained in:
parent
cbff3f8366
commit
e4f85edb62
2 changed files with 4 additions and 24 deletions
|
|
@ -1,5 +1,3 @@
|
|||
from pathlib import Path
|
||||
|
||||
from langflow.services.factory import ServiceFactory
|
||||
from langflow.services.settings.service import SettingsService
|
||||
|
||||
|
|
@ -10,5 +8,5 @@ class SettingsServiceFactory(ServiceFactory):
|
|||
|
||||
def create(self):
|
||||
# Here you would have logic to create and configure a SettingsService
|
||||
langflow_dir = Path(__file__).parent.parent.parent
|
||||
return SettingsService.load_settings_from_yaml(str(langflow_dir / "config.yaml"))
|
||||
|
||||
return SettingsService.initialize()
|
||||
|
|
|
|||
|
|
@ -1,8 +1,3 @@
|
|||
import os
|
||||
|
||||
import yaml
|
||||
from loguru import logger
|
||||
|
||||
from langflow.services.base import Service
|
||||
from langflow.services.settings.auth import AuthSettings
|
||||
from langflow.services.settings.base import Settings
|
||||
|
|
@ -17,23 +12,10 @@ class SettingsService(Service):
|
|||
self.auth_settings: AuthSettings = auth_settings
|
||||
|
||||
@classmethod
|
||||
def load_settings_from_yaml(cls, file_path: str) -> "SettingsService":
|
||||
def initialize(cls) -> "SettingsService":
|
||||
# Check if a string is a valid path or a file name
|
||||
if "/" not in file_path:
|
||||
# Get current path
|
||||
current_path = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
file_path = os.path.join(current_path, file_path)
|
||||
|
||||
with open(file_path, "r") as f:
|
||||
settings_dict = yaml.safe_load(f)
|
||||
|
||||
for key in settings_dict:
|
||||
if key not in Settings.model_fields.keys():
|
||||
logger.warning(f"Key {key} not found in settings")
|
||||
logger.debug(f"Loading {len(settings_dict[key])} {key} from {file_path}")
|
||||
|
||||
settings = Settings(**settings_dict)
|
||||
settings = Settings()
|
||||
if not settings.config_dir:
|
||||
raise ValueError("CONFIG_DIR must be set in settings")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue