feat: add auto_save option to Settings and CLI (#3386)

* feat: Add auto save feature in Langflow run function.

* feat: Add auto_save field to ConfigResponse model.

* refactor: Move logger import to the top in __main__.py and update auto save option help message.

* refactor: Update variable names for auto save to auto saving.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-08-16 15:39:19 -03:00 committed by GitHub
commit c00e687ec1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 17 additions and 2 deletions

View file

@ -20,13 +20,13 @@ from rich.panel import Panel
from rich.table import Table
from sqlmodel import select
from langflow.logging.logger import configure, logger
from langflow.main import setup_app
from langflow.services.database.models.folder.utils import create_default_folder_if_it_doesnt_exist
from langflow.services.database.utils import session_getter
from langflow.services.deps import get_db_service, get_settings_service, session_scope
from langflow.services.settings.constants import DEFAULT_SUPERUSER
from langflow.services.utils import initialize_services
from langflow.logging.logger import configure, logger
from langflow.utils.util import update_settings
console = Console()
@ -120,6 +120,11 @@ def run(
help="Enables the store features.",
envvar="LANGFLOW_STORE",
),
auto_saving: bool = typer.Option(
True,
help="Defines if the auto save is enabled.",
envvar="LANGFLOW_AUTO_SAVING",
),
):
"""
Run Langflow.
@ -137,6 +142,7 @@ def run(
cache=cache,
components_path=components_path,
store=store,
auto_saving=auto_saving,
)
# create path object if path is provided
static_files_dir: Optional[Path] = Path(path) if path else None

View file

@ -330,3 +330,4 @@ class FlowDataRequest(BaseModel):
class ConfigResponse(BaseModel):
frontend_timeout: int
auto_saving: bool

View file

@ -152,6 +152,10 @@ class Settings(BaseSettings):
vertex_builds_storage_enabled: bool = True
"""If set to True, Langflow will keep track of each vertex builds (outputs) in the UI for any flow."""
# Config
auto_saving: bool = True
"""If set to True, Langflow will auto save flows."""
@field_validator("dev")
@classmethod
def set_dev(cls, value):

View file

@ -8,11 +8,11 @@ from typing import Any, Dict, List, Optional, Union
from docstring_parser import parse
from langflow.logging.logger import logger
from langflow.schema import Data
from langflow.services.deps import get_settings_service
from langflow.template.frontend_node.constants import FORCE_SHOW_FIELDS
from langflow.utils import constants
from langflow.logging.logger import logger
def unescape_string(s: str):
@ -427,6 +427,7 @@ def update_settings(
remove_api_keys: bool = False,
components_path: Optional[Path] = None,
store: bool = True,
auto_saving: bool = True,
):
"""Update the settings from a config file."""
from langflow.services.utils import initialize_settings_service
@ -450,6 +451,9 @@ def update_settings(
if not store:
logger.debug("Setting store to False")
settings_service.settings.update_settings(store=False)
if not auto_saving:
logger.debug("Setting auto_saving to False")
settings_service.settings.update_settings(auto_saving=False)
def is_class_method(func, cls):