feat: flag to disable transaction and vertex_builds writes (#3031)

* feat: flag to disable transaction and vertex_builds writes

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Nicolò Boschi 2024-08-07 21:44:21 +02:00 committed by GitHub
commit 56523a7f2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 2 deletions

View file

@ -14,7 +14,7 @@ from langflow.services.database.models.transactions.crud import log_transaction
from langflow.services.database.models.vertex_builds.crud import log_vertex_build as crud_log_vertex_build
from langflow.services.database.models.vertex_builds.model import VertexBuildBase
from langflow.services.database.utils import session_getter
from langflow.services.deps import get_db_service
from langflow.services.deps import get_db_service, get_settings_service
from loguru import logger
if TYPE_CHECKING:
@ -132,6 +132,8 @@ async def log_transaction(
flow_id: Union[str, UUID], source: "Vertex", status, target: Optional["Vertex"] = None, error=None
) -> None:
try:
if not get_settings_service().settings.transactions_storage_enabled:
return
inputs = _vertex_to_primitive_dict(source)
transaction = TransactionBase(
vertex_id=source.id,
@ -159,6 +161,8 @@ def log_vertex_build(
artifacts: Optional[dict] = None,
):
try:
if not get_settings_service().settings.vertex_builds_storage_enabled:
return
vertex_build = VertexBuildBase(
flow_id=flow_id,
id=vertex_id,
@ -166,7 +170,8 @@ def log_vertex_build(
params=str(params) if params else None,
# ugly hack to get the model dump with weird datatypes
data=json.loads(data.model_dump_json()),
artifacts=artifacts,
# ugly hack to get the model dump with weird datatypes
artifacts=json.loads(json.dumps(artifacts, default=str)),
)
with session_getter(get_db_service()) as session:
inserted = crud_log_vertex_build(session, vertex_build)

View file

@ -146,6 +146,10 @@ class Settings(BaseSettings):
do_not_track: bool = False
"""If set to True, Langflow will not track telemetry."""
telemetry_base_url: str = "https://langflow.gateway.scarf.sh"
transactions_storage_enabled: bool = True
"""If set to True, Langflow will track transactions between flows."""
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."""
@field_validator("user_agent", mode="after")
@classmethod