Skip to content

Commit

Permalink
feat: add auto_save option to Settings and CLI (#3386)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
ogabrielluiz authored Aug 16, 2024
1 parent 93e0ffb commit c00e687
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/backend/base/langflow/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
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()
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/backend/base/langflow/api/v1/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,4 @@ class FlowDataRequest(BaseModel):

class ConfigResponse(BaseModel):
frontend_timeout: int
auto_saving: bool
4 changes: 4 additions & 0 deletions src/backend/base/langflow/services/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 5 additions & 1 deletion src/backend/base/langflow/utils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

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):
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down

0 comments on commit c00e687

Please sign in to comment.