Skip to content

Commit

Permalink
Global variables implementation (#1548)
Browse files Browse the repository at this point in the history
This PR is related to the Global Variables functionality.


![image](https://github.com/logspace-ai/langflow/assets/62335616/0829db58-c26c-499f-9d59-c11fa0a1cf5b)
When clicking the Globe, it's possible to use global variables in any
InputComponent.
When hovering an item, it's possible to delete it.
When clicking on Add New Variable, it's possible to add a new global
variable.
  • Loading branch information
lucaseduoli committed Mar 27, 2024
2 parents 043ec91 + 75d1c83 commit 54fb1ba
Show file tree
Hide file tree
Showing 90 changed files with 1,626 additions and 1,385 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/lint.yml
Expand Up @@ -14,15 +14,14 @@ on:
- "src/backend/**"

env:
POETRY_VERSION: "1.7.0"
POETRY_VERSION: "1.8.2"

jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- "3.9"
- "3.10"
- "3.11"
steps:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -46,7 +46,7 @@ format:

lint:
make install_backend
poetry run mypy src/backend
poetry run mypy --namespace-packages -p "langflow"
poetry run ruff . --fix

install_frontend:
Expand Down
2 changes: 1 addition & 1 deletion base.Dockerfile
Expand Up @@ -23,7 +23,7 @@ ENV PYTHONUNBUFFERED=1 \
\
# poetry
# https://python-poetry.org/docs/configuration/#using-environment-variables
POETRY_VERSION=1.7.1 \
POETRY_VERSION=1.8.2 \
# make poetry install to this location
POETRY_HOME="/opt/poetry" \
# make poetry create the virtual environment in the project's root
Expand Down
2 changes: 1 addition & 1 deletion build_and_push.Dockerfile
Expand Up @@ -23,7 +23,7 @@ ENV PYTHONUNBUFFERED=1 \
\
# poetry
# https://python-poetry.org/docs/configuration/#using-environment-variables
POETRY_VERSION=1.7.1 \
POETRY_VERSION=1.8.2 \
# make poetry install to this location
POETRY_HOME="/opt/poetry" \
# make poetry create the virtual environment in the project's root
Expand Down
2 changes: 1 addition & 1 deletion deploy/base.Dockerfile
Expand Up @@ -23,7 +23,7 @@ ENV PYTHONUNBUFFERED=1 \
\
# poetry
# https://python-poetry.org/docs/configuration/#using-environment-variables
POETRY_VERSION=1.5.1 \
POETRY_VERSION=1.8.2 \
# make poetry install to this location
POETRY_HOME="/opt/poetry" \
# make poetry create the virtual environment in the project's root
Expand Down
7 changes: 6 additions & 1 deletion src/backend/base/langflow/__main__.py
Expand Up @@ -285,7 +285,12 @@ def run_langflow(host, port, log_level, options, app):
# MacOS requires an env variable to be set to use gunicorn
import uvicorn

uvicorn.run(app, host=host, port=port, log_level=log_level)
uvicorn.run(
app,
host=host,
port=port,
log_level=log_level.lower(),
)
else:
from langflow.server import LangflowApplication

Expand Down
199 changes: 0 additions & 199 deletions src/backend/base/langflow/alembic/helpers/flow.py

This file was deleted.

34 changes: 0 additions & 34 deletions src/backend/base/langflow/alembic/helpers/record.py

This file was deleted.

@@ -0,0 +1,65 @@
"""Replace Credential table with Variable
Revision ID: 1a110b568907
Revises: 63b9c451fd30
Create Date: 2024-03-25 09:40:02.743453
"""
from typing import Sequence, Union

import sqlalchemy as sa
import sqlmodel
from alembic import op
from sqlalchemy.engine.reflection import Inspector

# revision identifiers, used by Alembic.
revision: str = "1a110b568907"
down_revision: Union[str, None] = "63b9c451fd30"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
conn = op.get_bind()
inspector = Inspector.from_engine(conn) # type: ignore
table_names = inspector.get_table_names()
# ### commands auto generated by Alembic - please adjust! ###
if "variable" not in table_names:
op.create_table(
"variable",
sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("value", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("type", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("updated_at", sa.DateTime(), nullable=True),
sa.Column("user_id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
sa.ForeignKeyConstraint(["user_id"], ["user.id"], name="fk_variable_user_id"),
sa.PrimaryKeyConstraint("id"),
)
if "credential" in table_names:
op.drop_table("credential")
# ### end Alembic commands ###


def downgrade() -> None:
conn = op.get_bind()
inspector = Inspector.from_engine(conn) # type: ignore
table_names = inspector.get_table_names()
# ### commands auto generated by Alembic - please adjust! ###
if "credential" not in table_names:
op.create_table(
"credential",
sa.Column("name", sa.VARCHAR(), nullable=True),
sa.Column("value", sa.VARCHAR(), nullable=True),
sa.Column("provider", sa.VARCHAR(), nullable=True),
sa.Column("user_id", sa.CHAR(length=32), nullable=False),
sa.Column("id", sa.CHAR(length=32), nullable=False),
sa.Column("created_at", sa.DATETIME(), nullable=False),
sa.Column("updated_at", sa.DATETIME(), nullable=True),
sa.ForeignKeyConstraint(["user_id"], ["user.id"], name="fk_credential_user_id"),
sa.PrimaryKeyConstraint("id"),
)
if "variable" in table_names:
op.drop_table("variable")
# ### end Alembic commands ###
4 changes: 2 additions & 2 deletions src/backend/base/langflow/api/router.py
Expand Up @@ -4,7 +4,6 @@
from langflow.api.v1 import (
api_key_router,
chat_router,
credentials_router,
endpoints_router,
files_router,
flows_router,
Expand All @@ -13,6 +12,7 @@
store_router,
users_router,
validate_router,
variables_router,
)

router = APIRouter(
Expand All @@ -26,6 +26,6 @@
router.include_router(users_router)
router.include_router(api_key_router)
router.include_router(login_router)
router.include_router(credentials_router)
router.include_router(variables_router)
router.include_router(files_router)
router.include_router(monitor_router)

0 comments on commit 54fb1ba

Please sign in to comment.