🔧 fix(settings.py): convert BASE_COMPONENTS_PATH to string to ensure compatibility with other parts of the codebase

🔧 fix(settings.py): update COMPONENTS_PATH to accept a list of strings instead of a list of Paths to improve flexibility and compatibility
🔧 fix(settings.py): update set_components_path method to handle LANGFLOW_COMPONENTS_PATH as a list of paths or a single path string
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-08-04 08:34:25 -03:00
commit 2efa7022f0

View file

@ -6,7 +6,7 @@ import yaml
from pydantic import BaseSettings, root_validator, validator from pydantic import BaseSettings, root_validator, validator
from langflow.utils.logger import logger from langflow.utils.logger import logger
BASE_COMPONENTS_PATH = Path(__file__).parent / "components" BASE_COMPONENTS_PATH = str(Path(__file__).parent / "components")
class Settings(BaseSettings): class Settings(BaseSettings):
@ -31,7 +31,7 @@ class Settings(BaseSettings):
DATABASE_URL: Optional[str] = None DATABASE_URL: Optional[str] = None
CACHE: str = "InMemoryCache" CACHE: str = "InMemoryCache"
REMOVE_API_KEYS: bool = False REMOVE_API_KEYS: bool = False
COMPONENTS_PATH: List[Path] = [] COMPONENTS_PATH: List[str] = []
@validator("DATABASE_URL", pre=True) @validator("DATABASE_URL", pre=True)
def set_database_url(cls, value): def set_database_url(cls, value):
@ -52,12 +52,15 @@ class Settings(BaseSettings):
def set_components_path(cls, value): def set_components_path(cls, value):
if os.getenv("LANGFLOW_COMPONENTS_PATH"): if os.getenv("LANGFLOW_COMPONENTS_PATH"):
logger.debug("Adding LANGFLOW_COMPONENTS_PATH to components_path") logger.debug("Adding LANGFLOW_COMPONENTS_PATH to components_path")
langflow_component_path = Path(os.getenv("LANGFLOW_COMPONENTS_PATH")) langflow_component_path = os.getenv("LANGFLOW_COMPONENTS_PATH")
if ( if (
langflow_component_path.exists() Path(langflow_component_path).exists()
and langflow_component_path not in value and langflow_component_path not in value
): ):
value.append(langflow_component_path) if isinstance(langflow_component_path, list):
value.extend(langflow_component_path)
else:
value.append(langflow_component_path)
logger.debug(f"Adding {langflow_component_path} to components_path") logger.debug(f"Adding {langflow_component_path} to components_path")
if not value: if not value: