Merge remote-tracking branch 'origin/dev' into celery
This commit is contained in:
commit
017b24f744
138 changed files with 2334 additions and 1106 deletions
10
.vscode/launch.json
vendored
10
.vscode/launch.json
vendored
|
|
@ -1,4 +1,5 @@
|
||||||
{
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "Debug Backend",
|
"name": "Debug Backend",
|
||||||
|
|
@ -38,6 +39,15 @@
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"url": "http://localhost:3000/",
|
"url": "http://localhost:3000/",
|
||||||
"webRoot": "${workspaceRoot}/src/frontend"
|
"webRoot": "${workspaceRoot}/src/frontend"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Python: Debug Tests",
|
||||||
|
"type": "python",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${file}",
|
||||||
|
"purpose": ["debug-test"],
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"justMyCode": false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,11 @@ to contributions, whether it be in the form of a new feature, improved infra, or
|
||||||
To contribute to this project, please follow a ["fork and pull request"](https://docs.github.com/en/get-started/quickstart/contributing-to-projects) workflow.
|
To contribute to this project, please follow a ["fork and pull request"](https://docs.github.com/en/get-started/quickstart/contributing-to-projects) workflow.
|
||||||
Please do not try to push directly to this repo unless you are a maintainer.
|
Please do not try to push directly to this repo unless you are a maintainer.
|
||||||
|
|
||||||
|
The branch structure is as follows:
|
||||||
|
|
||||||
|
- `main`: The stable version of Langflow
|
||||||
|
- `dev`: The development version of Langflow. This branch is used to test new features before they are merged into `main` and, as such, may be unstable.
|
||||||
|
|
||||||
## 🗺️Contributing Guidelines
|
## 🗺️Contributing Guidelines
|
||||||
|
|
||||||
## 🚩GitHub Issues
|
## 🚩GitHub Issues
|
||||||
|
|
|
||||||
|
|
@ -275,6 +275,8 @@ flow("Hey, have you heard of Langflow?")
|
||||||
|
|
||||||
We welcome contributions from developers of all levels to our open-source project on GitHub. If you'd like to contribute, please check our [contributing guidelines](./CONTRIBUTING.md) and help make Langflow more accessible.
|
We welcome contributions from developers of all levels to our open-source project on GitHub. If you'd like to contribute, please check our [contributing guidelines](./CONTRIBUTING.md) and help make Langflow more accessible.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
Join our [Discord](https://discord.com/invite/EqksyE2EX9) server to ask questions, make suggestions and showcase your projects! 🦾
|
Join our [Discord](https://discord.com/invite/EqksyE2EX9) server to ask questions, make suggestions and showcase your projects! 🦾
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
version: '3.4'
|
version: "3.4"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
backend:
|
backend:
|
||||||
|
|
@ -7,7 +7,12 @@ services:
|
||||||
build:
|
build:
|
||||||
context: ./
|
context: ./
|
||||||
dockerfile: ./dev.Dockerfile
|
dockerfile: ./dev.Dockerfile
|
||||||
command: ["sh", "-c", "pip install debugpy -t /tmp && python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678 -m uvicorn langflow.main:app --host 0.0.0.0 --port 7860 --reload"]
|
command:
|
||||||
|
[
|
||||||
|
"sh",
|
||||||
|
"-c",
|
||||||
|
"pip install debugpy -t /tmp && python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678 -m uvicorn --factory langflow.main:create_app --host 0.0.0.0 --port 7860 --reload",
|
||||||
|
]
|
||||||
ports:
|
ports:
|
||||||
- 7860:7860
|
- 7860:7860
|
||||||
- 5678:5678
|
- 5678:5678
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
version: '3'
|
version: "3"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
backend:
|
backend:
|
||||||
|
|
@ -9,7 +9,7 @@ services:
|
||||||
- "7860:7860"
|
- "7860:7860"
|
||||||
volumes:
|
volumes:
|
||||||
- ./:/app
|
- ./:/app
|
||||||
command: bash -c "uvicorn langflow.main:app --host 0.0.0.0 --port 7860 --reload"
|
command: bash -c "uvicorn --factory langflow.main:create_app --host 0.0.0.0 --port 7860 --reload"
|
||||||
|
|
||||||
frontend:
|
frontend:
|
||||||
build:
|
build:
|
||||||
|
|
|
||||||
|
|
@ -6,5 +6,5 @@ services:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
ports:
|
ports:
|
||||||
- "5003:5003"
|
- "7860:7860"
|
||||||
command: langflow --host 0.0.0.0
|
command: langflow --host 0.0.0.0
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,6 @@ class DocumentProcessor(CustomComponent):
|
||||||
light: "img/document_processor.png",
|
light: "img/document_processor.png",
|
||||||
}}
|
}}
|
||||||
style={{
|
style={{
|
||||||
width: "40%",
|
|
||||||
margin: "0 auto",
|
margin: "0 auto",
|
||||||
display: "flex",
|
display: "flex",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
|
|
|
||||||
62
poetry.lock
generated
62
poetry.lock
generated
|
|
@ -144,6 +144,25 @@ files = [
|
||||||
{file = "aiostream-0.4.5.tar.gz", hash = "sha256:3ecbf87085230fbcd9605c32ca20c4fb41af02c71d076eab246ea22e35947d88"},
|
{file = "aiostream-0.4.5.tar.gz", hash = "sha256:3ecbf87085230fbcd9605c32ca20c4fb41af02c71d076eab246ea22e35947d88"},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "alembic"
|
||||||
|
version = "1.11.2"
|
||||||
|
description = "A database migration tool for SQLAlchemy."
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.7"
|
||||||
|
files = [
|
||||||
|
{file = "alembic-1.11.2-py3-none-any.whl", hash = "sha256:7981ab0c4fad4fe1be0cf183aae17689fe394ff874fd2464adb774396faf0796"},
|
||||||
|
{file = "alembic-1.11.2.tar.gz", hash = "sha256:678f662130dc540dac12de0ea73de9f89caea9dbea138f60ef6263149bf84657"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.dependencies]
|
||||||
|
Mako = "*"
|
||||||
|
SQLAlchemy = ">=1.3.0"
|
||||||
|
typing-extensions = ">=4"
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
tz = ["python-dateutil"]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "amqp"
|
name = "amqp"
|
||||||
version = "5.1.1"
|
version = "5.1.1"
|
||||||
|
|
@ -3334,6 +3353,25 @@ docs = ["sphinx (>=1.6.0)", "sphinx-bootstrap-theme"]
|
||||||
flake8 = ["flake8"]
|
flake8 = ["flake8"]
|
||||||
tests = ["psutil", "pytest (!=3.3.0)", "pytest-cov"]
|
tests = ["psutil", "pytest (!=3.3.0)", "pytest-cov"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mako"
|
||||||
|
version = "1.2.4"
|
||||||
|
description = "A super-fast templating language that borrows the best ideas from the existing templating languages."
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.7"
|
||||||
|
files = [
|
||||||
|
{file = "Mako-1.2.4-py3-none-any.whl", hash = "sha256:c97c79c018b9165ac9922ae4f32da095ffd3c4e6872b45eded42926deea46818"},
|
||||||
|
{file = "Mako-1.2.4.tar.gz", hash = "sha256:d60a3903dc3bb01a18ad6a89cdbe2e4eadc69c0bc8ef1e3773ba53d44c3f7a34"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.dependencies]
|
||||||
|
MarkupSafe = ">=0.9.2"
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
babel = ["Babel"]
|
||||||
|
lingua = ["lingua"]
|
||||||
|
testing = ["pytest"]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "markdown"
|
name = "markdown"
|
||||||
version = "3.4.4"
|
version = "3.4.4"
|
||||||
|
|
@ -3382,7 +3420,7 @@ testing = ["coverage", "pytest", "pytest-cov", "pytest-regressions"]
|
||||||
name = "markupsafe"
|
name = "markupsafe"
|
||||||
version = "2.1.3"
|
version = "2.1.3"
|
||||||
description = "Safely add untrusted strings to HTML/XML markup."
|
description = "Safely add untrusted strings to HTML/XML markup."
|
||||||
optional = true
|
optional = false
|
||||||
python-versions = ">=3.7"
|
python-versions = ">=3.7"
|
||||||
files = [
|
files = [
|
||||||
{file = "MarkupSafe-2.1.3-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:cd0f502fe016460680cd20aaa5a76d241d6f35a1c3350c474bac1273803893fa"},
|
{file = "MarkupSafe-2.1.3-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:cd0f502fe016460680cd20aaa5a76d241d6f35a1c3350c474bac1273803893fa"},
|
||||||
|
|
@ -3501,6 +3539,20 @@ files = [
|
||||||
{file = "mdurl-0.1.2.tar.gz", hash = "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba"},
|
{file = "mdurl-0.1.2.tar.gz", hash = "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba"},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "metaphor-python"
|
||||||
|
version = "0.1.14"
|
||||||
|
description = "A Python package for the Metaphor API."
|
||||||
|
optional = false
|
||||||
|
python-versions = "*"
|
||||||
|
files = [
|
||||||
|
{file = "metaphor-python-0.1.14.tar.gz", hash = "sha256:9c9be35d1270e1e2984637711c15b614ad852fbd2b51d428b4cc478e95018fab"},
|
||||||
|
{file = "metaphor_python-0.1.14-py3-none-any.whl", hash = "sha256:9435fb702d62032e4affbf7825fe4b1f0c6099d33b4867f4238c07f4515eb9a2"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.dependencies]
|
||||||
|
requests = "*"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "monotonic"
|
name = "monotonic"
|
||||||
version = "1.6"
|
version = "1.6"
|
||||||
|
|
@ -7048,13 +7100,13 @@ files = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "types-pytz"
|
name = "types-pytz"
|
||||||
version = "2023.3.0.0"
|
version = "2023.3.0.1"
|
||||||
description = "Typing stubs for pytz"
|
description = "Typing stubs for pytz"
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = "*"
|
python-versions = "*"
|
||||||
files = [
|
files = [
|
||||||
{file = "types-pytz-2023.3.0.0.tar.gz", hash = "sha256:ecdc70d543aaf3616a7e48631543a884f74205f284cefd6649ddf44c6a820aac"},
|
{file = "types-pytz-2023.3.0.1.tar.gz", hash = "sha256:1a7b8d4aac70981cfa24478a41eadfcd96a087c986d6f150d77e3ceb3c2bdfab"},
|
||||||
{file = "types_pytz-2023.3.0.0-py3-none-any.whl", hash = "sha256:4fc2a7fbbc315f0b6630e0b899fd6c743705abe1094d007b0e612d10da15e0f3"},
|
{file = "types_pytz-2023.3.0.1-py3-none-any.whl", hash = "sha256:65152e872137926bb67a8fe6cc9cfd794365df86650c5d5fdc7b167b0f38892e"},
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -7800,4 +7852,4 @@ local = ["ctransformers", "llama-cpp-python", "sentence-transformers"]
|
||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "2.0"
|
lock-version = "2.0"
|
||||||
python-versions = ">=3.9,<3.11"
|
python-versions = ">=3.9,<3.11"
|
||||||
content-hash = "470ce5cd8ad64d3f6d004cebdb5625c86bd083dc8e4683e084d531e1ccbf90c9"
|
content-hash = "f19617ccd82d10dc15746a965b1dc74e3c79e6755f255ab1d03a1076e6c38e5f"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "langflow"
|
name = "langflow"
|
||||||
version = "0.4.2"
|
version = "0.4.7"
|
||||||
description = "A Python package with a built-in web application"
|
description = "A Python package with a built-in web application"
|
||||||
authors = ["Logspace <contact@logspace.ai>"]
|
authors = ["Logspace <contact@logspace.ai>"]
|
||||||
maintainers = [
|
maintainers = [
|
||||||
|
|
@ -19,7 +19,7 @@ readme = "README.md"
|
||||||
keywords = ["nlp", "langchain", "openai", "gpt", "gui"]
|
keywords = ["nlp", "langchain", "openai", "gpt", "gui"]
|
||||||
packages = [{ include = "langflow", from = "src/backend" }]
|
packages = [{ include = "langflow", from = "src/backend" }]
|
||||||
include = ["src/backend/langflow/*", "src/backend/langflow/**/*"]
|
include = ["src/backend/langflow/*", "src/backend/langflow/**/*"]
|
||||||
|
documentation = "https://docs.langflow.org"
|
||||||
|
|
||||||
[tool.poetry.scripts]
|
[tool.poetry.scripts]
|
||||||
langflow = "langflow.__main__:main"
|
langflow = "langflow.__main__:main"
|
||||||
|
|
@ -80,6 +80,8 @@ langchain-experimental = "^0.0.8"
|
||||||
celery = "^5.3.1"
|
celery = "^5.3.1"
|
||||||
redis = "^4.6.0"
|
redis = "^4.6.0"
|
||||||
flower = "^2.0.1"
|
flower = "^2.0.1"
|
||||||
|
alembic = "^1.11.2"
|
||||||
|
metaphor-python = "^0.1.11"
|
||||||
|
|
||||||
[tool.poetry.group.dev.dependencies]
|
[tool.poetry.group.dev.dependencies]
|
||||||
black = "^23.1.0"
|
black = "^23.1.0"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
from importlib import metadata
|
from importlib import metadata
|
||||||
from langflow.cache import cache_manager
|
|
||||||
|
# Deactivate cache manager for now
|
||||||
|
# from langflow.services.cache import cache_manager
|
||||||
from langflow.processing.process import load_flow_from_json
|
from langflow.processing.process import load_flow_from_json
|
||||||
from langflow.interface.custom.custom_component import CustomComponent
|
from langflow.interface.custom.custom_component import CustomComponent
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import httpx
|
import httpx
|
||||||
|
from langflow.services.utils import get_settings_manager
|
||||||
from langflow.utils.util import get_number_of_workers
|
from langflow.utils.util import get_number_of_workers
|
||||||
from multiprocess import Process # type: ignore
|
from multiprocess import Process # type: ignore
|
||||||
import platform
|
import platform
|
||||||
|
|
@ -12,7 +13,6 @@ from rich import box
|
||||||
from rich import print as rprint
|
from rich import print as rprint
|
||||||
import typer
|
import typer
|
||||||
from langflow.main import setup_app
|
from langflow.main import setup_app
|
||||||
from langflow.settings import settings
|
|
||||||
from langflow.utils.logger import configure, logger
|
from langflow.utils.logger import configure, logger
|
||||||
import webbrowser
|
import webbrowser
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
@ -30,19 +30,19 @@ def update_settings(
|
||||||
"""Update the settings from a config file."""
|
"""Update the settings from a config file."""
|
||||||
|
|
||||||
# Check for database_url in the environment variables
|
# Check for database_url in the environment variables
|
||||||
|
settings_manager = get_settings_manager()
|
||||||
if config:
|
if config:
|
||||||
logger.debug(f"Loading settings from {config}")
|
logger.debug(f"Loading settings from {config}")
|
||||||
settings.update_from_yaml(config, dev=dev)
|
settings_manager.settings.update_from_yaml(config, dev=dev)
|
||||||
if remove_api_keys:
|
if remove_api_keys:
|
||||||
logger.debug(f"Setting remove_api_keys to {remove_api_keys}")
|
logger.debug(f"Setting remove_api_keys to {remove_api_keys}")
|
||||||
settings.update_settings(REMOVE_API_KEYS=remove_api_keys)
|
settings_manager.settings.update_settings(REMOVE_API_KEYS=remove_api_keys)
|
||||||
if cache:
|
if cache:
|
||||||
logger.debug(f"Setting cache to {cache}")
|
logger.debug(f"Setting cache to {cache}")
|
||||||
settings.update_settings(CACHE=cache)
|
settings_manager.settings.update_settings(CACHE=cache)
|
||||||
if components_path:
|
if components_path:
|
||||||
logger.debug(f"Adding component path {components_path}")
|
logger.debug(f"Adding component path {components_path}")
|
||||||
settings.update_settings(COMPONENTS_PATH=components_path)
|
settings_manager.settings.update_settings(COMPONENTS_PATH=components_path)
|
||||||
|
|
||||||
|
|
||||||
def serve_on_jcloud():
|
def serve_on_jcloud():
|
||||||
|
|
@ -106,7 +106,9 @@ def serve(
|
||||||
help="Path to the directory containing custom components.",
|
help="Path to the directory containing custom components.",
|
||||||
envvar="LANGFLOW_COMPONENTS_PATH",
|
envvar="LANGFLOW_COMPONENTS_PATH",
|
||||||
),
|
),
|
||||||
config: str = typer.Option("config.yaml", help="Path to the configuration file."),
|
config: str = typer.Option(
|
||||||
|
Path(__file__).parent / "config.yaml", help="Path to the configuration file."
|
||||||
|
),
|
||||||
# .env file param
|
# .env file param
|
||||||
env_file: Path = typer.Option(
|
env_file: Path = typer.Option(
|
||||||
None, help="Path to the .env file containing environment variables."
|
None, help="Path to the .env file containing environment variables."
|
||||||
|
|
@ -146,6 +148,11 @@ def serve(
|
||||||
help="Remove API keys from the projects saved in the database.",
|
help="Remove API keys from the projects saved in the database.",
|
||||||
envvar="LANGFLOW_REMOVE_API_KEYS",
|
envvar="LANGFLOW_REMOVE_API_KEYS",
|
||||||
),
|
),
|
||||||
|
backend_only: bool = typer.Option(
|
||||||
|
False,
|
||||||
|
help="Run only the backend server without the frontend.",
|
||||||
|
envvar="LANGFLOW_BACKEND_ONLY",
|
||||||
|
),
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Run the Langflow server.
|
Run the Langflow server.
|
||||||
|
|
@ -167,7 +174,7 @@ def serve(
|
||||||
)
|
)
|
||||||
# create path object if path is provided
|
# create path object if path is provided
|
||||||
static_files_dir: Optional[Path] = Path(path) if path else None
|
static_files_dir: Optional[Path] = Path(path) if path else None
|
||||||
app = setup_app(static_files_dir=static_files_dir)
|
app = setup_app(static_files_dir=static_files_dir, backend_only=backend_only)
|
||||||
# check if port is being used
|
# check if port is being used
|
||||||
if is_port_in_use(port, host):
|
if is_port_in_use(port, host):
|
||||||
port = get_free_port(port)
|
port = get_free_port(port)
|
||||||
|
|
@ -179,6 +186,10 @@ def serve(
|
||||||
"timeout": timeout,
|
"timeout": timeout,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Define an env variable to know if we are just testing the server
|
||||||
|
if "pytest" in sys.modules:
|
||||||
|
return
|
||||||
|
|
||||||
if platform.system() in ["Windows"]:
|
if platform.system() in ["Windows"]:
|
||||||
# Run using uvicorn on MacOS and Windows
|
# Run using uvicorn on MacOS and Windows
|
||||||
# Windows doesn't support gunicorn
|
# Windows doesn't support gunicorn
|
||||||
|
|
|
||||||
113
src/backend/langflow/alembic.ini
Normal file
113
src/backend/langflow/alembic.ini
Normal file
|
|
@ -0,0 +1,113 @@
|
||||||
|
# A generic, single database configuration.
|
||||||
|
|
||||||
|
[alembic]
|
||||||
|
# path to migration scripts
|
||||||
|
script_location = alembic
|
||||||
|
|
||||||
|
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
|
||||||
|
# Uncomment the line below if you want the files to be prepended with date and time
|
||||||
|
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
|
||||||
|
# for all available tokens
|
||||||
|
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
|
||||||
|
|
||||||
|
# sys.path path, will be prepended to sys.path if present.
|
||||||
|
# defaults to the current working directory.
|
||||||
|
prepend_sys_path = .
|
||||||
|
|
||||||
|
# timezone to use when rendering the date within the migration file
|
||||||
|
# as well as the filename.
|
||||||
|
# If specified, requires the python-dateutil library that can be
|
||||||
|
# installed by adding `alembic[tz]` to the pip requirements
|
||||||
|
# string value is passed to dateutil.tz.gettz()
|
||||||
|
# leave blank for localtime
|
||||||
|
# timezone =
|
||||||
|
|
||||||
|
# max length of characters to apply to the
|
||||||
|
# "slug" field
|
||||||
|
# truncate_slug_length = 40
|
||||||
|
|
||||||
|
# set to 'true' to run the environment during
|
||||||
|
# the 'revision' command, regardless of autogenerate
|
||||||
|
# revision_environment = false
|
||||||
|
|
||||||
|
# set to 'true' to allow .pyc and .pyo files without
|
||||||
|
# a source .py file to be detected as revisions in the
|
||||||
|
# versions/ directory
|
||||||
|
# sourceless = false
|
||||||
|
|
||||||
|
# version location specification; This defaults
|
||||||
|
# to alembic/versions. When using multiple version
|
||||||
|
# directories, initial revisions must be specified with --version-path.
|
||||||
|
# The path separator used here should be the separator specified by "version_path_separator" below.
|
||||||
|
# version_locations = %(here)s/bar:%(here)s/bat:alembic/versions
|
||||||
|
|
||||||
|
# version path separator; As mentioned above, this is the character used to split
|
||||||
|
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
|
||||||
|
# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.
|
||||||
|
# Valid values for version_path_separator are:
|
||||||
|
#
|
||||||
|
# version_path_separator = :
|
||||||
|
# version_path_separator = ;
|
||||||
|
# version_path_separator = space
|
||||||
|
version_path_separator = os # Use os.pathsep. Default configuration used for new projects.
|
||||||
|
|
||||||
|
# set to 'true' to search source files recursively
|
||||||
|
# in each "version_locations" directory
|
||||||
|
# new in Alembic version 1.10
|
||||||
|
# recursive_version_locations = false
|
||||||
|
|
||||||
|
# the output encoding used when revision files
|
||||||
|
# are written from script.py.mako
|
||||||
|
# output_encoding = utf-8
|
||||||
|
|
||||||
|
# This is the path to the db in the root of the project.
|
||||||
|
# When the user runs the Langflow the database url will
|
||||||
|
# be set dinamically.
|
||||||
|
sqlalchemy.url = sqlite:///../../../langflow.db
|
||||||
|
|
||||||
|
|
||||||
|
[post_write_hooks]
|
||||||
|
# post_write_hooks defines scripts or Python functions that are run
|
||||||
|
# on newly generated revision scripts. See the documentation for further
|
||||||
|
# detail and examples
|
||||||
|
|
||||||
|
# format using "black" - use the console_scripts runner, against the "black" entrypoint
|
||||||
|
# hooks = black
|
||||||
|
# black.type = console_scripts
|
||||||
|
# black.entrypoint = black
|
||||||
|
# black.options = -l 79 REVISION_SCRIPT_FILENAME
|
||||||
|
|
||||||
|
# Logging configuration
|
||||||
|
[loggers]
|
||||||
|
keys = root,sqlalchemy,alembic
|
||||||
|
|
||||||
|
[handlers]
|
||||||
|
keys = console
|
||||||
|
|
||||||
|
[formatters]
|
||||||
|
keys = generic
|
||||||
|
|
||||||
|
[logger_root]
|
||||||
|
level = WARN
|
||||||
|
handlers = console
|
||||||
|
qualname =
|
||||||
|
|
||||||
|
[logger_sqlalchemy]
|
||||||
|
level = WARN
|
||||||
|
handlers =
|
||||||
|
qualname = sqlalchemy.engine
|
||||||
|
|
||||||
|
[logger_alembic]
|
||||||
|
level = INFO
|
||||||
|
handlers =
|
||||||
|
qualname = alembic
|
||||||
|
|
||||||
|
[handler_console]
|
||||||
|
class = StreamHandler
|
||||||
|
args = (sys.stderr,)
|
||||||
|
level = NOTSET
|
||||||
|
formatter = generic
|
||||||
|
|
||||||
|
[formatter_generic]
|
||||||
|
format = %(levelname)-5.5s [%(name)s] %(message)s
|
||||||
|
datefmt = %H:%M:%S
|
||||||
1
src/backend/langflow/alembic/README
Normal file
1
src/backend/langflow/alembic/README
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Generic single-database configuration.
|
||||||
78
src/backend/langflow/alembic/env.py
Normal file
78
src/backend/langflow/alembic/env.py
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
from logging.config import fileConfig
|
||||||
|
|
||||||
|
from sqlalchemy import engine_from_config
|
||||||
|
from sqlalchemy import pool
|
||||||
|
|
||||||
|
from alembic import context
|
||||||
|
|
||||||
|
from langflow.services.database.manager import SQLModel
|
||||||
|
|
||||||
|
# this is the Alembic Config object, which provides
|
||||||
|
# access to the values within the .ini file in use.
|
||||||
|
config = context.config
|
||||||
|
|
||||||
|
# Interpret the config file for Python logging.
|
||||||
|
# This line sets up loggers basically.
|
||||||
|
if config.config_file_name is not None:
|
||||||
|
fileConfig(config.config_file_name)
|
||||||
|
|
||||||
|
# add your model's MetaData object here
|
||||||
|
# for 'autogenerate' support
|
||||||
|
# from myapp import mymodel
|
||||||
|
# target_metadata = mymodel.Base.metadata
|
||||||
|
target_metadata = SQLModel.metadata
|
||||||
|
|
||||||
|
# other values from the config, defined by the needs of env.py,
|
||||||
|
# can be acquired:
|
||||||
|
# my_important_option = config.get_main_option("my_important_option")
|
||||||
|
# ... etc.
|
||||||
|
|
||||||
|
|
||||||
|
def run_migrations_offline() -> None:
|
||||||
|
"""Run migrations in 'offline' mode.
|
||||||
|
|
||||||
|
This configures the context with just a URL
|
||||||
|
and not an Engine, though an Engine is acceptable
|
||||||
|
here as well. By skipping the Engine creation
|
||||||
|
we don't even need a DBAPI to be available.
|
||||||
|
|
||||||
|
Calls to context.execute() here emit the given string to the
|
||||||
|
script output.
|
||||||
|
|
||||||
|
"""
|
||||||
|
url = config.get_main_option("sqlalchemy.url")
|
||||||
|
context.configure(
|
||||||
|
url=url,
|
||||||
|
target_metadata=target_metadata,
|
||||||
|
literal_binds=True,
|
||||||
|
dialect_opts={"paramstyle": "named"},
|
||||||
|
)
|
||||||
|
|
||||||
|
with context.begin_transaction():
|
||||||
|
context.run_migrations()
|
||||||
|
|
||||||
|
|
||||||
|
def run_migrations_online() -> None:
|
||||||
|
"""Run migrations in 'online' mode.
|
||||||
|
|
||||||
|
In this scenario we need to create an Engine
|
||||||
|
and associate a connection with the context.
|
||||||
|
|
||||||
|
"""
|
||||||
|
connectable = engine_from_config(
|
||||||
|
config.get_section(config.config_ini_section, {}),
|
||||||
|
prefix="sqlalchemy.",
|
||||||
|
poolclass=pool.NullPool,
|
||||||
|
)
|
||||||
|
|
||||||
|
with connectable.connect() as connection:
|
||||||
|
context.configure(connection=connection, target_metadata=target_metadata)
|
||||||
|
|
||||||
|
with context.begin_transaction():
|
||||||
|
context.run_migrations()
|
||||||
|
|
||||||
|
|
||||||
|
if context.is_offline_mode():
|
||||||
|
run_migrations_offline()
|
||||||
|
else:
|
||||||
|
run_migrations_online()
|
||||||
27
src/backend/langflow/alembic/script.py.mako
Normal file
27
src/backend/langflow/alembic/script.py.mako
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
"""${message}
|
||||||
|
|
||||||
|
Revision ID: ${up_revision}
|
||||||
|
Revises: ${down_revision | comma,n}
|
||||||
|
Create Date: ${create_date}
|
||||||
|
|
||||||
|
"""
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
import sqlmodel
|
||||||
|
${imports if imports else ""}
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision: str = ${repr(up_revision)}
|
||||||
|
down_revision: Union[str, None] = ${repr(down_revision)}
|
||||||
|
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
|
||||||
|
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
${upgrades if upgrades else "pass"}
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
${downgrades if downgrades else "pass"}
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
"""Remove FlowStyles table
|
||||||
|
|
||||||
|
Revision ID: 0a534bdfd84b
|
||||||
|
Revises: 4814b6f4abfd
|
||||||
|
Create Date: 2023-08-07 14:09:06.844104
|
||||||
|
|
||||||
|
"""
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision: str = "0a534bdfd84b"
|
||||||
|
down_revision: Union[str, None] = "4814b6f4abfd"
|
||||||
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_table("flowstyle")
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_table(
|
||||||
|
"flowstyle",
|
||||||
|
sa.Column("color", sa.VARCHAR(), nullable=False),
|
||||||
|
sa.Column("emoji", sa.VARCHAR(), nullable=False),
|
||||||
|
sa.Column("flow_id", sa.CHAR(length=32), nullable=True),
|
||||||
|
sa.Column("id", sa.CHAR(length=32), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(
|
||||||
|
["flow_id"],
|
||||||
|
["flow.id"],
|
||||||
|
),
|
||||||
|
sa.PrimaryKeyConstraint("id"),
|
||||||
|
sa.UniqueConstraint("id"),
|
||||||
|
)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
"""Add Flow table
|
||||||
|
|
||||||
|
Revision ID: 4814b6f4abfd
|
||||||
|
Revises:
|
||||||
|
Create Date: 2023-08-05 17:47:42.879824
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
import contextlib
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
import sqlmodel
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision: str = "4814b6f4abfd"
|
||||||
|
down_revision: Union[str, None] = None
|
||||||
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
|
||||||
|
# This suppress is used to not break the migration if the table already exists.
|
||||||
|
with contextlib.suppress(sa.exc.OperationalError):
|
||||||
|
op.create_table(
|
||||||
|
"flow",
|
||||||
|
sa.Column("data", sa.JSON(), nullable=True),
|
||||||
|
sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
||||||
|
sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
|
||||||
|
sa.Column("id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
|
||||||
|
sa.PrimaryKeyConstraint("id"),
|
||||||
|
sa.UniqueConstraint("id"),
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
op.f("ix_flow_description"), "flow", ["description"], unique=False
|
||||||
|
)
|
||||||
|
op.create_index(op.f("ix_flow_name"), "flow", ["name"], unique=False)
|
||||||
|
with contextlib.suppress(sa.exc.OperationalError):
|
||||||
|
op.create_table(
|
||||||
|
"flowstyle",
|
||||||
|
sa.Column("color", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
||||||
|
sa.Column("emoji", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
||||||
|
sa.Column("flow_id", sqlmodel.sql.sqltypes.GUID(), nullable=True),
|
||||||
|
sa.Column("id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(
|
||||||
|
["flow_id"],
|
||||||
|
["flow.id"],
|
||||||
|
),
|
||||||
|
sa.PrimaryKeyConstraint("id"),
|
||||||
|
sa.UniqueConstraint("id"),
|
||||||
|
)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_table("flowstyle")
|
||||||
|
op.drop_index(op.f("ix_flow_name"), table_name="flow")
|
||||||
|
op.drop_index(op.f("ix_flow_description"), table_name="flow")
|
||||||
|
op.drop_table("flow")
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
@ -5,7 +5,6 @@ from langflow.api.v1 import (
|
||||||
endpoints_router,
|
endpoints_router,
|
||||||
validate_router,
|
validate_router,
|
||||||
flows_router,
|
flows_router,
|
||||||
flow_styles_router,
|
|
||||||
component_router,
|
component_router,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -17,4 +16,3 @@ router.include_router(endpoints_router)
|
||||||
router.include_router(validate_router)
|
router.include_router(validate_router)
|
||||||
router.include_router(component_router)
|
router.include_router(component_router)
|
||||||
router.include_router(flows_router)
|
router.include_router(flows_router)
|
||||||
router.include_router(flow_styles_router)
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ from langflow.api.v1.endpoints import router as endpoints_router
|
||||||
from langflow.api.v1.validate import router as validate_router
|
from langflow.api.v1.validate import router as validate_router
|
||||||
from langflow.api.v1.chat import router as chat_router
|
from langflow.api.v1.chat import router as chat_router
|
||||||
from langflow.api.v1.flows import router as flows_router
|
from langflow.api.v1.flows import router as flows_router
|
||||||
from langflow.api.v1.flow_styles import router as flow_styles_router
|
|
||||||
from langflow.api.v1.components import router as component_router
|
from langflow.api.v1.components import router as component_router
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
|
|
@ -11,5 +10,4 @@ __all__ = [
|
||||||
"component_router",
|
"component_router",
|
||||||
"validate_router",
|
"validate_router",
|
||||||
"flows_router",
|
"flows_router",
|
||||||
"flow_styles_router",
|
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,13 @@ from fastapi.responses import StreamingResponse
|
||||||
from langflow.api.utils import build_input_keys_response
|
from langflow.api.utils import build_input_keys_response
|
||||||
from langflow.api.v1.schemas import BuildStatus, BuiltResponse, InitResponse, StreamData
|
from langflow.api.v1.schemas import BuildStatus, BuiltResponse, InitResponse, StreamData
|
||||||
|
|
||||||
from langflow.chat.manager import ChatManager
|
from langflow.services import service_manager, ServiceType
|
||||||
from langflow.graph.graph.base import Graph
|
from langflow.graph.graph.base import Graph
|
||||||
from langflow.utils.logger import logger
|
from langflow.utils.logger import logger
|
||||||
from cachetools import LRUCache
|
from cachetools import LRUCache
|
||||||
|
|
||||||
router = APIRouter(tags=["Chat"])
|
router = APIRouter(tags=["Chat"])
|
||||||
chat_manager = ChatManager()
|
|
||||||
flow_data_store: LRUCache = LRUCache(maxsize=10)
|
flow_data_store: LRUCache = LRUCache(maxsize=10)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -17,6 +17,7 @@ flow_data_store: LRUCache = LRUCache(maxsize=10)
|
||||||
async def chat(client_id: str, websocket: WebSocket):
|
async def chat(client_id: str, websocket: WebSocket):
|
||||||
"""Websocket endpoint for chat."""
|
"""Websocket endpoint for chat."""
|
||||||
try:
|
try:
|
||||||
|
chat_manager = service_manager.get(ServiceType.CHAT_MANAGER)
|
||||||
if client_id in chat_manager.in_memory_cache:
|
if client_id in chat_manager.in_memory_cache:
|
||||||
await chat_manager.handle_websocket(client_id, websocket)
|
await chat_manager.handle_websocket(client_id, websocket)
|
||||||
else:
|
else:
|
||||||
|
|
@ -45,6 +46,7 @@ async def init_build(graph_data: dict, flow_id: str):
|
||||||
return InitResponse(flowId=flow_id)
|
return InitResponse(flowId=flow_id)
|
||||||
|
|
||||||
# Delete from cache if already exists
|
# Delete from cache if already exists
|
||||||
|
chat_manager = service_manager.get(ServiceType.CHAT_MANAGER)
|
||||||
if flow_id in chat_manager.in_memory_cache:
|
if flow_id in chat_manager.in_memory_cache:
|
||||||
with chat_manager.in_memory_cache._lock:
|
with chat_manager.in_memory_cache._lock:
|
||||||
chat_manager.in_memory_cache.delete(flow_id)
|
chat_manager.in_memory_cache.delete(flow_id)
|
||||||
|
|
@ -160,7 +162,7 @@ async def stream_build(flow_id: str):
|
||||||
"handle_keys": [],
|
"handle_keys": [],
|
||||||
}
|
}
|
||||||
yield str(StreamData(event="message", data=input_keys_response))
|
yield str(StreamData(event="message", data=input_keys_response))
|
||||||
|
chat_manager = service_manager.get(ServiceType.CHAT_MANAGER)
|
||||||
chat_manager.set_cache(flow_id, langchain_object)
|
chat_manager.set_cache(flow_id, langchain_object)
|
||||||
# We need to reset the chat history
|
# We need to reset the chat history
|
||||||
chat_manager.chat_history.empty_history(flow_id)
|
chat_manager.chat_history.empty_history(flow_id)
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
from datetime import timezone
|
from datetime import timezone
|
||||||
from typing import List
|
from typing import List
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
from langflow.database.models.component import Component, ComponentModel
|
from langflow.services.database.models.component import Component, ComponentModel
|
||||||
from langflow.database.base import get_session
|
from langflow.services.utils import get_session
|
||||||
from sqlmodel import Session, select
|
from sqlmodel import Session, select
|
||||||
from fastapi import APIRouter, Depends, HTTPException
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from typing import Annotated, Optional
|
from typing import Annotated, Optional
|
||||||
|
|
||||||
from langflow.cache.utils import save_uploaded_file
|
from langflow.services.cache.utils import save_uploaded_file
|
||||||
from langflow.database.models.flow import Flow
|
from langflow.services.database.models.flow import Flow
|
||||||
from langflow.processing.process import process_tweaks
|
from langflow.processing.process import process_tweaks
|
||||||
|
from langflow.services.utils import get_settings_manager
|
||||||
from langflow.utils.logger import logger
|
from langflow.utils.logger import logger
|
||||||
from langflow.settings import settings
|
|
||||||
from langflow.worker import process_graph_cached as process_graph_cached_worker
|
from langflow.worker import process_graph_cached as process_graph_cached_worker
|
||||||
from fastapi import APIRouter, Depends, HTTPException, UploadFile, Body
|
from fastapi import APIRouter, Depends, HTTPException, UploadFile, Body
|
||||||
|
|
||||||
|
|
@ -26,7 +26,7 @@ from langflow.interface.types import (
|
||||||
build_langchain_custom_component_list_from_path,
|
build_langchain_custom_component_list_from_path,
|
||||||
)
|
)
|
||||||
|
|
||||||
from langflow.database.base import get_session
|
from langflow.services.utils import get_session
|
||||||
from sqlmodel import Session
|
from sqlmodel import Session
|
||||||
|
|
||||||
# build router
|
# build router
|
||||||
|
|
@ -40,15 +40,20 @@ def get_all():
|
||||||
# custom_components is a list of dicts
|
# custom_components is a list of dicts
|
||||||
# need to merge all the keys into one dict
|
# need to merge all the keys into one dict
|
||||||
custom_components_from_file = {}
|
custom_components_from_file = {}
|
||||||
if settings.COMPONENTS_PATH:
|
settings_manager = get_settings_manager()
|
||||||
logger.info(f"Building custom components from {settings.COMPONENTS_PATH}")
|
if settings_manager.settings.COMPONENTS_PATH:
|
||||||
|
logger.info(
|
||||||
|
f"Building custom components from {settings_manager.settings.COMPONENTS_PATH}"
|
||||||
|
)
|
||||||
custom_component_dicts = [
|
custom_component_dicts = [
|
||||||
build_langchain_custom_component_list_from_path(str(path))
|
build_langchain_custom_component_list_from_path(str(path))
|
||||||
for path in settings.COMPONENTS_PATH
|
for path in settings_manager.settings.COMPONENTS_PATH
|
||||||
]
|
]
|
||||||
logger.info(f"Loading {len(custom_component_dicts)} category(ies)")
|
logger.info(f"Loading {len(custom_component_dicts)} category(ies)")
|
||||||
for custom_component_dict in custom_component_dicts:
|
for custom_component_dict in custom_component_dicts:
|
||||||
# custom_component_dict is a dict of dicts
|
# custom_component_dict is a dict of dicts
|
||||||
|
if not custom_component_dict:
|
||||||
|
continue
|
||||||
category = list(custom_component_dict.keys())[0]
|
category = list(custom_component_dict.keys())[0]
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Loading {len(custom_component_dict[category])} component(s) from category {category}"
|
f"Loading {len(custom_component_dict[category])} component(s) from category {category}"
|
||||||
|
|
|
||||||
|
|
@ -1,83 +0,0 @@
|
||||||
from uuid import UUID
|
|
||||||
from langflow.database.models.flow_style import (
|
|
||||||
FlowStyle,
|
|
||||||
FlowStyleCreate,
|
|
||||||
FlowStyleRead,
|
|
||||||
FlowStyleUpdate,
|
|
||||||
)
|
|
||||||
from langflow.database.base import get_session
|
|
||||||
from sqlmodel import Session, select
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException
|
|
||||||
|
|
||||||
|
|
||||||
# build router
|
|
||||||
router = APIRouter(prefix="/flow_styles", tags=["FlowStyles"])
|
|
||||||
|
|
||||||
# FlowStyleCreate:
|
|
||||||
# class FlowStyleBase(SQLModel):
|
|
||||||
# color: str = Field(index=True)
|
|
||||||
# emoji: str = Field(index=False)
|
|
||||||
# flow_id: UUID = Field(default=None, foreign_key="flow.id")
|
|
||||||
|
|
||||||
|
|
||||||
@router.post("/", response_model=FlowStyleRead)
|
|
||||||
def create_flow_style(
|
|
||||||
*, session: Session = Depends(get_session), flow_style: FlowStyleCreate
|
|
||||||
):
|
|
||||||
"""Create a new flow_style."""
|
|
||||||
db_flow_style = FlowStyle.from_orm(flow_style)
|
|
||||||
session.add(db_flow_style)
|
|
||||||
session.commit()
|
|
||||||
session.refresh(db_flow_style)
|
|
||||||
return db_flow_style
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/", response_model=list[FlowStyleRead])
|
|
||||||
def read_flow_styles(*, session: Session = Depends(get_session)):
|
|
||||||
"""Read all flows."""
|
|
||||||
try:
|
|
||||||
flows = session.exec(select(FlowStyle)).all()
|
|
||||||
except Exception as e:
|
|
||||||
raise HTTPException(status_code=500, detail=str(e)) from e
|
|
||||||
return flows
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{flow_styles_id}", response_model=FlowStyleRead)
|
|
||||||
def read_flow_style(*, session: Session = Depends(get_session), flow_styles_id: UUID):
|
|
||||||
"""Read a flow_style."""
|
|
||||||
if flow_style := session.get(FlowStyle, flow_styles_id):
|
|
||||||
return flow_style
|
|
||||||
else:
|
|
||||||
raise HTTPException(status_code=404, detail="FlowStyle not found")
|
|
||||||
|
|
||||||
|
|
||||||
@router.patch("/{flow_style_id}", response_model=FlowStyleRead)
|
|
||||||
def update_flow_style(
|
|
||||||
*,
|
|
||||||
session: Session = Depends(get_session),
|
|
||||||
flow_style_id: UUID,
|
|
||||||
flow_style: FlowStyleUpdate,
|
|
||||||
):
|
|
||||||
"""Update a flow_style."""
|
|
||||||
db_flow_style = session.get(FlowStyle, flow_style_id)
|
|
||||||
if not db_flow_style:
|
|
||||||
raise HTTPException(status_code=404, detail="FlowStyle not found")
|
|
||||||
flow_data = flow_style.dict(exclude_unset=True)
|
|
||||||
for key, value in flow_data.items():
|
|
||||||
if hasattr(db_flow_style, key) and value is not None:
|
|
||||||
setattr(db_flow_style, key, value)
|
|
||||||
session.add(db_flow_style)
|
|
||||||
session.commit()
|
|
||||||
session.refresh(db_flow_style)
|
|
||||||
return db_flow_style
|
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/{flow_id}")
|
|
||||||
def delete_flow_style(*, session: Session = Depends(get_session), flow_id: UUID):
|
|
||||||
"""Delete a flow_style."""
|
|
||||||
flow_style = session.get(FlowStyle, flow_id)
|
|
||||||
if not flow_style:
|
|
||||||
raise HTTPException(status_code=404, detail="FlowStyle not found")
|
|
||||||
session.delete(flow_style)
|
|
||||||
session.commit()
|
|
||||||
return {"message": "FlowStyle deleted successfully"}
|
|
||||||
|
|
@ -1,16 +1,15 @@
|
||||||
from typing import List
|
from typing import List
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
from langflow.settings import settings
|
|
||||||
from langflow.api.utils import remove_api_keys
|
from langflow.api.utils import remove_api_keys
|
||||||
from langflow.api.v1.schemas import FlowListCreate, FlowListRead
|
from langflow.api.v1.schemas import FlowListCreate, FlowListRead
|
||||||
from langflow.database.models.flow import (
|
from langflow.services.database.models.flow import (
|
||||||
Flow,
|
Flow,
|
||||||
FlowCreate,
|
FlowCreate,
|
||||||
FlowRead,
|
FlowRead,
|
||||||
FlowReadWithStyle,
|
|
||||||
FlowUpdate,
|
FlowUpdate,
|
||||||
)
|
)
|
||||||
from langflow.database.base import get_session
|
from langflow.services.utils import get_session
|
||||||
|
from langflow.services.utils import get_settings_manager
|
||||||
from sqlmodel import Session, select
|
from sqlmodel import Session, select
|
||||||
from fastapi import APIRouter, Depends, HTTPException
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
from fastapi.encoders import jsonable_encoder
|
from fastapi.encoders import jsonable_encoder
|
||||||
|
|
@ -32,7 +31,7 @@ def create_flow(*, session: Session = Depends(get_session), flow: FlowCreate):
|
||||||
return db_flow
|
return db_flow
|
||||||
|
|
||||||
|
|
||||||
@router.get("/", response_model=list[FlowReadWithStyle], status_code=200)
|
@router.get("/", response_model=list[FlowRead], status_code=200)
|
||||||
def read_flows(*, session: Session = Depends(get_session)):
|
def read_flows(*, session: Session = Depends(get_session)):
|
||||||
"""Read all flows."""
|
"""Read all flows."""
|
||||||
try:
|
try:
|
||||||
|
|
@ -42,7 +41,7 @@ def read_flows(*, session: Session = Depends(get_session)):
|
||||||
return [jsonable_encoder(flow) for flow in flows]
|
return [jsonable_encoder(flow) for flow in flows]
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{flow_id}", response_model=FlowReadWithStyle, status_code=200)
|
@router.get("/{flow_id}", response_model=FlowRead, status_code=200)
|
||||||
def read_flow(*, session: Session = Depends(get_session), flow_id: UUID):
|
def read_flow(*, session: Session = Depends(get_session), flow_id: UUID):
|
||||||
"""Read a flow."""
|
"""Read a flow."""
|
||||||
if flow := session.get(Flow, flow_id):
|
if flow := session.get(Flow, flow_id):
|
||||||
|
|
@ -61,7 +60,8 @@ def update_flow(
|
||||||
if not db_flow:
|
if not db_flow:
|
||||||
raise HTTPException(status_code=404, detail="Flow not found")
|
raise HTTPException(status_code=404, detail="Flow not found")
|
||||||
flow_data = flow.dict(exclude_unset=True)
|
flow_data = flow.dict(exclude_unset=True)
|
||||||
if settings.REMOVE_API_KEYS:
|
settings_manager = get_settings_manager()
|
||||||
|
if settings_manager.settings.REMOVE_API_KEYS:
|
||||||
flow_data = remove_api_keys(flow_data)
|
flow_data = remove_api_keys(flow_data)
|
||||||
for key, value in flow_data.items():
|
for key, value in flow_data.items():
|
||||||
setattr(db_flow, key, value)
|
setattr(db_flow, key, value)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Dict, List, Optional, Union
|
from typing import Any, Dict, List, Optional, Union
|
||||||
from langflow.database.models.flow import FlowCreate, FlowRead
|
from langflow.services.database.models.flow import FlowCreate, FlowRead
|
||||||
from pydantic import BaseModel, Field, validator
|
from pydantic import BaseModel, Field, validator
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
|
||||||
7
src/backend/langflow/cache/__init__.py
vendored
7
src/backend/langflow/cache/__init__.py
vendored
|
|
@ -1,7 +0,0 @@
|
||||||
from langflow.cache.manager import cache_manager
|
|
||||||
from langflow.cache.flow import InMemoryCache
|
|
||||||
|
|
||||||
__all__ = [
|
|
||||||
"cache_manager",
|
|
||||||
"InMemoryCache",
|
|
||||||
]
|
|
||||||
56
src/backend/langflow/components/toolkits/Metaphor.py
Normal file
56
src/backend/langflow/components/toolkits/Metaphor.py
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
from typing import List, Union
|
||||||
|
from langflow import CustomComponent
|
||||||
|
|
||||||
|
from metaphor_python import Metaphor # type: ignore
|
||||||
|
from langchain.tools import Tool
|
||||||
|
from langchain.agents import tool
|
||||||
|
from langchain.agents.agent_toolkits.base import BaseToolkit
|
||||||
|
|
||||||
|
|
||||||
|
class MetaphorToolkit(CustomComponent):
|
||||||
|
display_name: str = "Metaphor"
|
||||||
|
description: str = "Metaphor Toolkit"
|
||||||
|
documentation = (
|
||||||
|
"https://python.langchain.com/docs/integrations/tools/metaphor_search"
|
||||||
|
)
|
||||||
|
beta = True
|
||||||
|
# api key should be password = True
|
||||||
|
field_config = {
|
||||||
|
"metaphor_api_key": {"display_name": "Metaphor API Key", "password": True},
|
||||||
|
"code": {"advanced": True},
|
||||||
|
}
|
||||||
|
|
||||||
|
def build(
|
||||||
|
self,
|
||||||
|
metaphor_api_key: str,
|
||||||
|
use_autoprompt: bool = True,
|
||||||
|
search_num_results: int = 5,
|
||||||
|
similar_num_results: int = 5,
|
||||||
|
) -> Union[Tool, BaseToolkit]:
|
||||||
|
# If documents, then we need to create a Vectara instance using .from_documents
|
||||||
|
client = Metaphor(api_key=metaphor_api_key)
|
||||||
|
|
||||||
|
@tool
|
||||||
|
def search(query: str):
|
||||||
|
"""Call search engine with a query."""
|
||||||
|
return client.search(
|
||||||
|
query, use_autoprompt=use_autoprompt, num_results=search_num_results
|
||||||
|
)
|
||||||
|
|
||||||
|
@tool
|
||||||
|
def get_contents(ids: List[str]):
|
||||||
|
"""Get contents of a webpage.
|
||||||
|
|
||||||
|
The ids passed in should be a list of ids as fetched from `search`.
|
||||||
|
"""
|
||||||
|
return client.get_contents(ids)
|
||||||
|
|
||||||
|
@tool
|
||||||
|
def find_similar(url: str):
|
||||||
|
"""Get search results similar to a given URL.
|
||||||
|
|
||||||
|
The url passed in should be a URL returned from `search`
|
||||||
|
"""
|
||||||
|
return client.find_similar(url, num_results=similar_num_results)
|
||||||
|
|
||||||
|
return [search, get_contents, find_similar] # type: ignore
|
||||||
50
src/backend/langflow/components/vectorstores/Vectara.py
Normal file
50
src/backend/langflow/components/vectorstores/Vectara.py
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
from typing import Optional, Union
|
||||||
|
from langflow import CustomComponent
|
||||||
|
|
||||||
|
from langchain.vectorstores import Vectara
|
||||||
|
from langchain.schema import Document
|
||||||
|
from langchain.vectorstores.base import VectorStore
|
||||||
|
from langchain.schema import BaseRetriever
|
||||||
|
from langchain.embeddings.base import Embeddings
|
||||||
|
|
||||||
|
|
||||||
|
class VectaraComponent(CustomComponent):
|
||||||
|
display_name: str = "Vectara"
|
||||||
|
description: str = "Implementation of Vector Store using Vectara"
|
||||||
|
documentation = (
|
||||||
|
"https://python.langchain.com/docs/integrations/vectorstores/vectara"
|
||||||
|
)
|
||||||
|
beta = True
|
||||||
|
# api key should be password = True
|
||||||
|
field_config = {
|
||||||
|
"vectara_customer_id": {"display_name": "Vectara Customer ID"},
|
||||||
|
"vectara_corpus_id": {"display_name": "Vectara Corpus ID"},
|
||||||
|
"vectara_api_key": {"display_name": "Vectara API Key", "password": True},
|
||||||
|
"code": {"show": False},
|
||||||
|
"documents": {"display_name": "Documents"},
|
||||||
|
"embedding": {"display_name": "Embedding"},
|
||||||
|
}
|
||||||
|
|
||||||
|
def build(
|
||||||
|
self,
|
||||||
|
vectara_customer_id: str,
|
||||||
|
vectara_corpus_id: str,
|
||||||
|
vectara_api_key: str,
|
||||||
|
embedding: Optional[Embeddings] = None,
|
||||||
|
documents: Optional[Document] = None,
|
||||||
|
) -> Union[VectorStore, BaseRetriever]:
|
||||||
|
# If documents, then we need to create a Vectara instance using .from_documents
|
||||||
|
if documents is not None and embedding is not None:
|
||||||
|
return Vectara.from_documents(
|
||||||
|
documents=documents, # type: ignore
|
||||||
|
vectara_customer_id=vectara_customer_id,
|
||||||
|
vectara_corpus_id=vectara_corpus_id,
|
||||||
|
vectara_api_key=vectara_api_key,
|
||||||
|
embedding=embedding,
|
||||||
|
)
|
||||||
|
|
||||||
|
return Vectara(
|
||||||
|
vectara_customer_id=vectara_customer_id,
|
||||||
|
vectara_corpus_id=vectara_corpus_id,
|
||||||
|
vectara_api_key=vectara_api_key,
|
||||||
|
)
|
||||||
|
|
@ -1,78 +0,0 @@
|
||||||
from contextlib import contextmanager
|
|
||||||
import os
|
|
||||||
|
|
||||||
from sqlmodel import SQLModel, Session, create_engine
|
|
||||||
from langflow.utils.logger import logger
|
|
||||||
|
|
||||||
|
|
||||||
class Engine:
|
|
||||||
_instance = None
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get(cls):
|
|
||||||
logger.debug("Getting database engine")
|
|
||||||
if cls._instance is None:
|
|
||||||
cls.create()
|
|
||||||
return cls._instance
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def create(cls):
|
|
||||||
logger.debug("Creating database engine")
|
|
||||||
from langflow.settings import settings
|
|
||||||
|
|
||||||
if langflow_database_url := os.getenv("LANGFLOW_DATABASE_URL"):
|
|
||||||
settings.DATABASE_URL = langflow_database_url
|
|
||||||
logger.debug("Using LANGFLOW_DATABASE_URL")
|
|
||||||
|
|
||||||
if settings.DATABASE_URL and settings.DATABASE_URL.startswith("sqlite"):
|
|
||||||
connect_args = {"check_same_thread": False}
|
|
||||||
else:
|
|
||||||
connect_args = {}
|
|
||||||
if not settings.DATABASE_URL:
|
|
||||||
raise RuntimeError("No database_url provided")
|
|
||||||
cls._instance = create_engine(settings.DATABASE_URL, connect_args=connect_args)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def update(cls):
|
|
||||||
logger.debug("Updating database engine")
|
|
||||||
cls._instance = None
|
|
||||||
cls.create()
|
|
||||||
|
|
||||||
|
|
||||||
def create_db_and_tables():
|
|
||||||
logger.debug("Creating database and tables")
|
|
||||||
try:
|
|
||||||
SQLModel.metadata.create_all(Engine.get())
|
|
||||||
except Exception as exc:
|
|
||||||
logger.error(f"Error creating database and tables: {exc}")
|
|
||||||
raise RuntimeError("Error creating database and tables") from exc
|
|
||||||
# Now check if the table Flow exists, if not, something went wrong
|
|
||||||
# and we need to create the tables again.
|
|
||||||
from sqlalchemy import inspect
|
|
||||||
|
|
||||||
inspector = inspect(Engine.get())
|
|
||||||
if "flow" not in inspector.get_table_names():
|
|
||||||
logger.error("Something went wrong creating the database and tables.")
|
|
||||||
logger.error("Please check your database settings.")
|
|
||||||
|
|
||||||
raise RuntimeError("Something went wrong creating the database and tables.")
|
|
||||||
else:
|
|
||||||
logger.debug("Database and tables created successfully")
|
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
|
||||||
def session_getter():
|
|
||||||
try:
|
|
||||||
session = Session(Engine.get())
|
|
||||||
yield session
|
|
||||||
except Exception as e:
|
|
||||||
print("Session rollback because of exception:", e)
|
|
||||||
session.rollback()
|
|
||||||
raise
|
|
||||||
finally:
|
|
||||||
session.close()
|
|
||||||
|
|
||||||
|
|
||||||
def get_session():
|
|
||||||
with session_getter() as session:
|
|
||||||
yield session
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
# Path: src/backend/langflow/database/models/flowstyle.py
|
|
||||||
|
|
||||||
from langflow.database.models.base import SQLModelSerializable
|
|
||||||
from sqlmodel import Field, Relationship
|
|
||||||
from uuid import UUID, uuid4
|
|
||||||
from typing import TYPE_CHECKING, Optional
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from langflow.database.models.flow import Flow
|
|
||||||
|
|
||||||
|
|
||||||
class FlowStyleBase(SQLModelSerializable):
|
|
||||||
color: str
|
|
||||||
emoji: str
|
|
||||||
flow_id: UUID = Field(default=None, foreign_key="flow.id")
|
|
||||||
|
|
||||||
|
|
||||||
class FlowStyle(FlowStyleBase, table=True):
|
|
||||||
id: UUID = Field(default_factory=uuid4, primary_key=True, unique=True)
|
|
||||||
flow: "Flow" = Relationship(back_populates="style")
|
|
||||||
|
|
||||||
|
|
||||||
class FlowStyleUpdate(SQLModelSerializable):
|
|
||||||
color: Optional[str] = None
|
|
||||||
emoji: Optional[str] = None
|
|
||||||
|
|
||||||
|
|
||||||
class FlowStyleCreate(FlowStyleBase):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class FlowStyleRead(FlowStyleBase):
|
|
||||||
id: UUID
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
from typing import Dict, Generator, List, Type, Union
|
from typing import Dict, Generator, List, Type, Union
|
||||||
|
|
||||||
from langflow.graph.edge.base import Edge
|
from langflow.graph.edge.base import Edge
|
||||||
from langflow.graph.graph.constants import VERTEX_TYPE_MAP
|
from langflow.graph.graph.constants import lazy_load_vertex_dict
|
||||||
from langflow.graph.vertex.base import Vertex
|
from langflow.graph.vertex.base import Vertex
|
||||||
from langflow.graph.vertex.types import (
|
from langflow.graph.vertex.types import (
|
||||||
FileToolVertex,
|
FileToolVertex,
|
||||||
|
|
@ -187,10 +187,12 @@ class Graph:
|
||||||
"""Returns the node class based on the node type."""
|
"""Returns the node class based on the node type."""
|
||||||
if node_type in FILE_TOOLS:
|
if node_type in FILE_TOOLS:
|
||||||
return FileToolVertex
|
return FileToolVertex
|
||||||
if node_type in VERTEX_TYPE_MAP:
|
if node_type in lazy_load_vertex_dict.VERTEX_TYPE_MAP:
|
||||||
return VERTEX_TYPE_MAP[node_type]
|
return lazy_load_vertex_dict.VERTEX_TYPE_MAP[node_type]
|
||||||
return (
|
return (
|
||||||
VERTEX_TYPE_MAP[node_lc_type] if node_lc_type in VERTEX_TYPE_MAP else Vertex
|
lazy_load_vertex_dict.VERTEX_TYPE_MAP[node_lc_type]
|
||||||
|
if node_lc_type in lazy_load_vertex_dict.VERTEX_TYPE_MAP
|
||||||
|
else Vertex
|
||||||
)
|
)
|
||||||
|
|
||||||
def _build_vertices(self) -> List[Vertex]:
|
def _build_vertices(self) -> List[Vertex]:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
from langflow.graph.vertex.base import Vertex
|
|
||||||
from langflow.graph.vertex import types
|
from langflow.graph.vertex import types
|
||||||
from langflow.interface.agents.base import agent_creator
|
from langflow.interface.agents.base import agent_creator
|
||||||
from langflow.interface.chains.base import chain_creator
|
from langflow.interface.chains.base import chain_creator
|
||||||
|
|
@ -15,10 +14,26 @@ from langflow.interface.wrappers.base import wrapper_creator
|
||||||
from langflow.interface.output_parsers.base import output_parser_creator
|
from langflow.interface.output_parsers.base import output_parser_creator
|
||||||
from langflow.interface.retrievers.base import retriever_creator
|
from langflow.interface.retrievers.base import retriever_creator
|
||||||
from langflow.interface.custom.base import custom_component_creator
|
from langflow.interface.custom.base import custom_component_creator
|
||||||
from typing import Dict, Type
|
from langflow.utils.lazy_load import LazyLoadDictBase
|
||||||
|
|
||||||
|
|
||||||
VERTEX_TYPE_MAP: Dict[str, Type[Vertex]] = {
|
class VertexTypesDict(LazyLoadDictBase):
|
||||||
|
def __init__(self):
|
||||||
|
self._all_types_dict = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def VERTEX_TYPE_MAP(self):
|
||||||
|
return self.all_types_dict
|
||||||
|
|
||||||
|
def _build_dict(self):
|
||||||
|
langchain_types_dict = self.get_type_dict()
|
||||||
|
return {
|
||||||
|
**langchain_types_dict,
|
||||||
|
"Custom": ["Custom Tool", "Python Function"],
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_type_dict(self):
|
||||||
|
return {
|
||||||
**{t: types.PromptVertex for t in prompt_creator.to_list()},
|
**{t: types.PromptVertex for t in prompt_creator.to_list()},
|
||||||
**{t: types.AgentVertex for t in agent_creator.to_list()},
|
**{t: types.AgentVertex for t in agent_creator.to_list()},
|
||||||
**{t: types.ChainVertex for t in chain_creator.to_list()},
|
**{t: types.ChainVertex for t in chain_creator.to_list()},
|
||||||
|
|
@ -32,6 +47,12 @@ VERTEX_TYPE_MAP: Dict[str, Type[Vertex]] = {
|
||||||
**{t: types.DocumentLoaderVertex for t in documentloader_creator.to_list()},
|
**{t: types.DocumentLoaderVertex for t in documentloader_creator.to_list()},
|
||||||
**{t: types.TextSplitterVertex for t in textsplitter_creator.to_list()},
|
**{t: types.TextSplitterVertex for t in textsplitter_creator.to_list()},
|
||||||
**{t: types.OutputParserVertex for t in output_parser_creator.to_list()},
|
**{t: types.OutputParserVertex for t in output_parser_creator.to_list()},
|
||||||
**{t: types.CustomComponentVertex for t in custom_component_creator.to_list()},
|
**{
|
||||||
|
t: types.CustomComponentVertex
|
||||||
|
for t in custom_component_creator.to_list()
|
||||||
|
},
|
||||||
**{t: types.RetrieverVertex for t in retriever_creator.to_list()},
|
**{t: types.RetrieverVertex for t in retriever_creator.to_list()},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
lazy_load_vertex_dict = VertexTypesDict()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import ast
|
import ast
|
||||||
from langflow.interface.initialize import loading
|
from langflow.interface.initialize import loading
|
||||||
from langflow.interface.listing import ALL_TYPES_DICT
|
from langflow.interface.listing import lazy_load_dict
|
||||||
from langflow.utils.constants import DIRECT_TYPES
|
from langflow.utils.constants import DIRECT_TYPES
|
||||||
from langflow.utils.logger import logger
|
from langflow.utils.logger import logger
|
||||||
from langflow.utils.util import sync_to_async
|
from langflow.utils.util import sync_to_async
|
||||||
|
|
@ -62,7 +62,7 @@ class Vertex:
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.base_type is None:
|
if self.base_type is None:
|
||||||
for base_type, value in ALL_TYPES_DICT.items():
|
for base_type, value in lazy_load_dict.ALL_TYPES_DICT.items():
|
||||||
if self.vertex_type in value:
|
if self.vertex_type in value:
|
||||||
self.base_type = base_type
|
self.base_type = base_type
|
||||||
break
|
break
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,8 @@ from langchain.agents import types
|
||||||
from langflow.custom.customs import get_custom_nodes
|
from langflow.custom.customs import get_custom_nodes
|
||||||
from langflow.interface.agents.custom import CUSTOM_AGENTS
|
from langflow.interface.agents.custom import CUSTOM_AGENTS
|
||||||
from langflow.interface.base import LangChainTypeCreator
|
from langflow.interface.base import LangChainTypeCreator
|
||||||
from langflow.settings import settings
|
from langflow.services.utils import get_settings_manager
|
||||||
|
|
||||||
from langflow.template.frontend_node.agents import AgentFrontendNode
|
from langflow.template.frontend_node.agents import AgentFrontendNode
|
||||||
from langflow.utils.logger import logger
|
from langflow.utils.logger import logger
|
||||||
from langflow.utils.util import build_template_from_class, build_template_from_method
|
from langflow.utils.util import build_template_from_class, build_template_from_method
|
||||||
|
|
@ -53,13 +54,17 @@ class AgentCreator(LangChainTypeCreator):
|
||||||
# Now this is a generator
|
# Now this is a generator
|
||||||
def to_list(self) -> List[str]:
|
def to_list(self) -> List[str]:
|
||||||
names = []
|
names = []
|
||||||
|
settings_manager = get_settings_manager()
|
||||||
for _, agent in self.type_to_loader_dict.items():
|
for _, agent in self.type_to_loader_dict.items():
|
||||||
agent_name = (
|
agent_name = (
|
||||||
agent.function_name()
|
agent.function_name()
|
||||||
if hasattr(agent, "function_name")
|
if hasattr(agent, "function_name")
|
||||||
else agent.__name__
|
else agent.__name__
|
||||||
)
|
)
|
||||||
if agent_name in settings.AGENTS or settings.DEV:
|
if (
|
||||||
|
agent_name in settings_manager.settings.AGENTS
|
||||||
|
or settings_manager.settings.DEV
|
||||||
|
):
|
||||||
names.append(agent_name)
|
names.append(agent_name)
|
||||||
return names
|
return names
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,14 @@ from abc import ABC, abstractmethod
|
||||||
from typing import Any, Dict, List, Optional, Type, Union
|
from typing import Any, Dict, List, Optional, Type, Union
|
||||||
from langchain.chains.base import Chain
|
from langchain.chains.base import Chain
|
||||||
from langchain.agents import AgentExecutor
|
from langchain.agents import AgentExecutor
|
||||||
|
from langflow.services.utils import get_settings_manager
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
from langflow.template.field.base import TemplateField
|
from langflow.template.field.base import TemplateField
|
||||||
from langflow.template.frontend_node.base import FrontendNode
|
from langflow.template.frontend_node.base import FrontendNode
|
||||||
from langflow.template.template.base import Template
|
from langflow.template.template.base import Template
|
||||||
from langflow.utils.logger import logger
|
from langflow.utils.logger import logger
|
||||||
from langflow.settings import settings
|
|
||||||
|
|
||||||
# Assuming necessary imports for Field, Template, and FrontendNode classes
|
# Assuming necessary imports for Field, Template, and FrontendNode classes
|
||||||
|
|
||||||
|
|
@ -26,9 +27,12 @@ class LangChainTypeCreator(BaseModel, ABC):
|
||||||
@property
|
@property
|
||||||
def docs_map(self) -> Dict[str, str]:
|
def docs_map(self) -> Dict[str, str]:
|
||||||
"""A dict with the name of the component as key and the documentation link as value."""
|
"""A dict with the name of the component as key and the documentation link as value."""
|
||||||
|
settings_manager = get_settings_manager()
|
||||||
if self.name_docs_dict is None:
|
if self.name_docs_dict is None:
|
||||||
try:
|
try:
|
||||||
type_settings = getattr(settings, self.type_name.upper())
|
type_settings = getattr(
|
||||||
|
settings_manager.settings, self.type_name.upper()
|
||||||
|
)
|
||||||
self.name_docs_dict = {
|
self.name_docs_dict = {
|
||||||
name: value_dict["documentation"]
|
name: value_dict["documentation"]
|
||||||
for name, value_dict in type_settings.items()
|
for name, value_dict in type_settings.items()
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,8 @@ from typing import Any, Dict, List, Optional, Type
|
||||||
from langflow.custom.customs import get_custom_nodes
|
from langflow.custom.customs import get_custom_nodes
|
||||||
from langflow.interface.base import LangChainTypeCreator
|
from langflow.interface.base import LangChainTypeCreator
|
||||||
from langflow.interface.importing.utils import import_class
|
from langflow.interface.importing.utils import import_class
|
||||||
from langflow.settings import settings
|
from langflow.services.utils import get_settings_manager
|
||||||
|
|
||||||
from langflow.template.frontend_node.chains import ChainFrontendNode
|
from langflow.template.frontend_node.chains import ChainFrontendNode
|
||||||
from langflow.utils.logger import logger
|
from langflow.utils.logger import logger
|
||||||
from langflow.utils.util import build_template_from_class, build_template_from_method
|
from langflow.utils.util import build_template_from_class, build_template_from_method
|
||||||
|
|
@ -30,6 +31,7 @@ class ChainCreator(LangChainTypeCreator):
|
||||||
@property
|
@property
|
||||||
def type_to_loader_dict(self) -> Dict:
|
def type_to_loader_dict(self) -> Dict:
|
||||||
if self.type_dict is None:
|
if self.type_dict is None:
|
||||||
|
settings_manager = get_settings_manager()
|
||||||
self.type_dict: dict[str, Any] = {
|
self.type_dict: dict[str, Any] = {
|
||||||
chain_name: import_class(f"langchain.chains.{chain_name}")
|
chain_name: import_class(f"langchain.chains.{chain_name}")
|
||||||
for chain_name in chains.__all__
|
for chain_name in chains.__all__
|
||||||
|
|
@ -43,7 +45,8 @@ class ChainCreator(LangChainTypeCreator):
|
||||||
self.type_dict = {
|
self.type_dict = {
|
||||||
name: chain
|
name: chain
|
||||||
for name, chain in self.type_dict.items()
|
for name, chain in self.type_dict.items()
|
||||||
if name in settings.CHAINS or settings.DEV
|
if name in settings_manager.settings.CHAINS
|
||||||
|
or settings_manager.settings.DEV
|
||||||
}
|
}
|
||||||
return self.type_dict
|
return self.type_dict
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,9 @@ class Component(BaseModel):
|
||||||
elif "beta" in item_name:
|
elif "beta" in item_name:
|
||||||
template_config["beta"] = ast.literal_eval(item_value)
|
template_config["beta"] = ast.literal_eval(item_value)
|
||||||
|
|
||||||
|
elif "documentation" in item_name:
|
||||||
|
template_config["documentation"] = ast.literal_eval(item_value)
|
||||||
|
|
||||||
return template_config
|
return template_config
|
||||||
|
|
||||||
def build(self, *args: Any, **kwargs: Any) -> Any:
|
def build(self, *args: Any, **kwargs: Any) -> Any:
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,12 @@ from fastapi import HTTPException
|
||||||
from langflow.interface.custom.constants import CUSTOM_COMPONENT_SUPPORTED_TYPES
|
from langflow.interface.custom.constants import CUSTOM_COMPONENT_SUPPORTED_TYPES
|
||||||
from langflow.interface.custom.component import Component
|
from langflow.interface.custom.component import Component
|
||||||
from langflow.interface.custom.directory_reader import DirectoryReader
|
from langflow.interface.custom.directory_reader import DirectoryReader
|
||||||
|
from langflow.services.utils import get_db_manager
|
||||||
|
|
||||||
from langflow.utils import validate
|
from langflow.utils import validate
|
||||||
|
|
||||||
from langflow.database.base import session_getter
|
from langflow.services.database.utils import session_getter
|
||||||
from langflow.database.models.flow import Flow
|
from langflow.services.database.models.flow import Flow
|
||||||
from pydantic import Extra
|
from pydantic import Extra
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
|
@ -49,7 +50,9 @@ class CustomComponent(Component, extra=Extra.allow):
|
||||||
reader = DirectoryReader("", False)
|
reader = DirectoryReader("", False)
|
||||||
|
|
||||||
for type_hint in TYPE_HINT_LIST:
|
for type_hint in TYPE_HINT_LIST:
|
||||||
if reader.is_type_hint_used_but_not_imported(type_hint, code):
|
if reader._is_type_hint_used_in_args(
|
||||||
|
"Optional", code
|
||||||
|
) and not reader._is_type_hint_imported("Optional", code):
|
||||||
error_detail = {
|
error_detail = {
|
||||||
"error": "Type hint Error",
|
"error": "Type hint Error",
|
||||||
"traceback": f"Type hint '{type_hint}' is used but not imported in the code.",
|
"traceback": f"Type hint '{type_hint}' is used but not imported in the code.",
|
||||||
|
|
@ -92,9 +95,9 @@ class CustomComponent(Component, extra=Extra.allow):
|
||||||
return build_method["args"]
|
return build_method["args"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def get_function_entrypoint_return_type(self) -> str:
|
def get_function_entrypoint_return_type(self) -> List[str]:
|
||||||
if not self.code:
|
if not self.code:
|
||||||
return ""
|
return []
|
||||||
tree = self.get_code_tree(self.code)
|
tree = self.get_code_tree(self.code)
|
||||||
|
|
||||||
component_classes = [
|
component_classes = [
|
||||||
|
|
@ -103,7 +106,7 @@ class CustomComponent(Component, extra=Extra.allow):
|
||||||
if self.code_class_base_inheritance in cls["bases"]
|
if self.code_class_base_inheritance in cls["bases"]
|
||||||
]
|
]
|
||||||
if not component_classes:
|
if not component_classes:
|
||||||
return ""
|
return []
|
||||||
|
|
||||||
# Assume the first Component class is the one we're interested in
|
# Assume the first Component class is the one we're interested in
|
||||||
component_class = component_classes[0]
|
component_class = component_classes[0]
|
||||||
|
|
@ -114,11 +117,21 @@ class CustomComponent(Component, extra=Extra.allow):
|
||||||
]
|
]
|
||||||
|
|
||||||
if not build_methods:
|
if not build_methods:
|
||||||
return ""
|
return []
|
||||||
|
|
||||||
build_method = build_methods[0]
|
build_method = build_methods[0]
|
||||||
|
return_type = build_method["return_type"]
|
||||||
|
if not return_type:
|
||||||
|
return []
|
||||||
|
# If the return type is not a Union, then we just return it as a list
|
||||||
|
if "Union" not in return_type:
|
||||||
|
return [return_type] if return_type in self.return_type_valid_list else []
|
||||||
|
|
||||||
return build_method["return_type"]
|
# If the return type is a Union, then we need to parse it
|
||||||
|
return_type = return_type.replace("Union", "").replace("[", "").replace("]", "")
|
||||||
|
return_type = return_type.split(",")
|
||||||
|
return_type = [item.strip() for item in return_type]
|
||||||
|
return [item for item in return_type if item in self.return_type_valid_list]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def get_main_class_name(self):
|
def get_main_class_name(self):
|
||||||
|
|
@ -159,7 +172,8 @@ class CustomComponent(Component, extra=Extra.allow):
|
||||||
from langflow.processing.process import build_sorted_vertices_with_caching
|
from langflow.processing.process import build_sorted_vertices_with_caching
|
||||||
from langflow.processing.process import process_tweaks
|
from langflow.processing.process import process_tweaks
|
||||||
|
|
||||||
with session_getter() as session:
|
db_manager = get_db_manager()
|
||||||
|
with session_getter(db_manager) as session:
|
||||||
graph_data = flow.data if (flow := session.get(Flow, flow_id)) else None
|
graph_data = flow.data if (flow := session.get(Flow, flow_id)) else None
|
||||||
if not graph_data:
|
if not graph_data:
|
||||||
raise ValueError(f"Flow {flow_id} not found")
|
raise ValueError(f"Flow {flow_id} not found")
|
||||||
|
|
@ -169,7 +183,8 @@ class CustomComponent(Component, extra=Extra.allow):
|
||||||
|
|
||||||
def list_flows(self, *, get_session: Optional[Callable] = None) -> List[Flow]:
|
def list_flows(self, *, get_session: Optional[Callable] = None) -> List[Flow]:
|
||||||
get_session = get_session or session_getter
|
get_session = get_session or session_getter
|
||||||
with get_session() as session:
|
db_manager = get_db_manager()
|
||||||
|
with get_session(db_manager) as session:
|
||||||
flows = session.query(Flow).all()
|
flows = session.query(Flow).all()
|
||||||
return flows
|
return flows
|
||||||
|
|
||||||
|
|
@ -182,8 +197,8 @@ class CustomComponent(Component, extra=Extra.allow):
|
||||||
get_session: Optional[Callable] = None,
|
get_session: Optional[Callable] = None,
|
||||||
) -> Flow:
|
) -> Flow:
|
||||||
get_session = get_session or session_getter
|
get_session = get_session or session_getter
|
||||||
|
db_manager = get_db_manager()
|
||||||
with get_session() as session:
|
with get_session(db_manager) as session:
|
||||||
if flow_id:
|
if flow_id:
|
||||||
flow = session.query(Flow).get(flow_id)
|
flow = session.query(Flow).get(flow_id)
|
||||||
elif flow_name:
|
elif flow_name:
|
||||||
|
|
|
||||||
|
|
@ -152,6 +152,7 @@ class DirectoryReader:
|
||||||
Check if a specific type hint is used in the
|
Check if a specific type hint is used in the
|
||||||
function definitions within the given code.
|
function definitions within the given code.
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
module = ast.parse(code)
|
module = ast.parse(code)
|
||||||
|
|
||||||
for node in ast.walk(module):
|
for node in ast.walk(module):
|
||||||
|
|
@ -161,6 +162,9 @@ class DirectoryReader:
|
||||||
arg.annotation, type_hint_name
|
arg.annotation, type_hint_name
|
||||||
):
|
):
|
||||||
return True
|
return True
|
||||||
|
except SyntaxError:
|
||||||
|
# Returns False if the code is not valid Python
|
||||||
|
return False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _is_type_hint_in_arg_annotation(self, annotation, type_hint_name: str) -> bool:
|
def _is_type_hint_in_arg_annotation(self, annotation, type_hint_name: str) -> bool:
|
||||||
|
|
@ -204,8 +208,13 @@ class DirectoryReader:
|
||||||
return False, "Syntax error"
|
return False, "Syntax error"
|
||||||
elif not self.validate_build(file_content):
|
elif not self.validate_build(file_content):
|
||||||
return False, "Missing build function"
|
return False, "Missing build function"
|
||||||
elif self.is_type_hint_used_but_not_imported("Optional", file_content):
|
elif self._is_type_hint_used_in_args(
|
||||||
return False, "Type hint 'Optional' is used but not imported in the code."
|
"Optional", file_content
|
||||||
|
) and not self._is_type_hint_imported("Optional", file_content):
|
||||||
|
return (
|
||||||
|
False,
|
||||||
|
"Type hint 'Optional' is used but not imported in the code.",
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
if self.compress_code_field:
|
if self.compress_code_field:
|
||||||
file_content = str(StringCompressor(file_content).compress_string())
|
file_content = str(StringCompressor(file_content).compress_string())
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
from typing import Dict, List, Optional, Type
|
from typing import Dict, List, Optional, Type
|
||||||
|
|
||||||
from langflow.interface.base import LangChainTypeCreator
|
from langflow.interface.base import LangChainTypeCreator
|
||||||
|
from langflow.services.utils import get_settings_manager
|
||||||
from langflow.template.frontend_node.documentloaders import DocumentLoaderFrontNode
|
from langflow.template.frontend_node.documentloaders import DocumentLoaderFrontNode
|
||||||
from langflow.interface.custom_lists import documentloaders_type_to_cls_dict
|
from langflow.interface.custom_lists import documentloaders_type_to_cls_dict
|
||||||
from langflow.settings import settings
|
|
||||||
from langflow.utils.logger import logger
|
from langflow.utils.logger import logger
|
||||||
from langflow.utils.util import build_template_from_class
|
from langflow.utils.util import build_template_from_class
|
||||||
|
|
||||||
|
|
@ -30,10 +31,12 @@ class DocumentLoaderCreator(LangChainTypeCreator):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def to_list(self) -> List[str]:
|
def to_list(self) -> List[str]:
|
||||||
|
settings_manager = get_settings_manager()
|
||||||
return [
|
return [
|
||||||
documentloader.__name__
|
documentloader.__name__
|
||||||
for documentloader in self.type_to_loader_dict.values()
|
for documentloader in self.type_to_loader_dict.values()
|
||||||
if documentloader.__name__ in settings.DOCUMENTLOADERS or settings.DEV
|
if documentloader.__name__ in settings_manager.settings.DOCUMENTLOADERS
|
||||||
|
or settings_manager.settings.DEV
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@ from typing import Dict, List, Optional, Type
|
||||||
|
|
||||||
from langflow.interface.base import LangChainTypeCreator
|
from langflow.interface.base import LangChainTypeCreator
|
||||||
from langflow.interface.custom_lists import embedding_type_to_cls_dict
|
from langflow.interface.custom_lists import embedding_type_to_cls_dict
|
||||||
from langflow.settings import settings
|
from langflow.services.utils import get_settings_manager
|
||||||
|
|
||||||
from langflow.template.frontend_node.base import FrontendNode
|
from langflow.template.frontend_node.base import FrontendNode
|
||||||
from langflow.template.frontend_node.embeddings import EmbeddingFrontendNode
|
from langflow.template.frontend_node.embeddings import EmbeddingFrontendNode
|
||||||
from langflow.utils.logger import logger
|
from langflow.utils.logger import logger
|
||||||
|
|
@ -32,10 +33,12 @@ class EmbeddingCreator(LangChainTypeCreator):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def to_list(self) -> List[str]:
|
def to_list(self) -> List[str]:
|
||||||
|
settings_manager = get_settings_manager()
|
||||||
return [
|
return [
|
||||||
embedding.__name__
|
embedding.__name__
|
||||||
for embedding in self.type_to_loader_dict.values()
|
for embedding in self.type_to_loader_dict.values()
|
||||||
if embedding.__name__ in settings.EMBEDDINGS or settings.DEV
|
if embedding.__name__ in settings_manager.settings.EMBEDDINGS
|
||||||
|
or settings_manager.settings.DEV
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -116,9 +116,12 @@ def instantiate_based_on_type(class_object, base_type, node_type, params):
|
||||||
|
|
||||||
|
|
||||||
def instantiate_custom_component(node_type, class_object, params):
|
def instantiate_custom_component(node_type, class_object, params):
|
||||||
class_object = get_function_custom(params.pop("code"))
|
# we need to make a copy of the params because we will be
|
||||||
|
# modifying it
|
||||||
|
params_copy = params.copy()
|
||||||
|
class_object = get_function_custom(params_copy.pop("code"))
|
||||||
custom_component = class_object()
|
custom_component = class_object()
|
||||||
built_object = custom_component.build(**params)
|
built_object = custom_component.build(**params_copy)
|
||||||
return built_object, {"repr": custom_component.custom_repr()}
|
return built_object, {"repr": custom_component.custom_repr()}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -130,8 +130,8 @@ def initialize_pinecone(class_object: Type[Pinecone], params: dict):
|
||||||
|
|
||||||
import pinecone # type: ignore
|
import pinecone # type: ignore
|
||||||
|
|
||||||
pinecone_api_key = params.get("pinecone_api_key")
|
pinecone_api_key = params.pop("pinecone_api_key")
|
||||||
pinecone_env = params.get("pinecone_env")
|
pinecone_env = params.pop("pinecone_env")
|
||||||
|
|
||||||
if pinecone_api_key is None or pinecone_env is None:
|
if pinecone_api_key is None or pinecone_env is None:
|
||||||
if os.getenv("PINECONE_API_KEY") is not None:
|
if os.getenv("PINECONE_API_KEY") is not None:
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,25 @@ from langflow.interface.wrappers.base import wrapper_creator
|
||||||
from langflow.interface.output_parsers.base import output_parser_creator
|
from langflow.interface.output_parsers.base import output_parser_creator
|
||||||
from langflow.interface.retrievers.base import retriever_creator
|
from langflow.interface.retrievers.base import retriever_creator
|
||||||
from langflow.interface.custom.base import custom_component_creator
|
from langflow.interface.custom.base import custom_component_creator
|
||||||
|
from langflow.utils.lazy_load import LazyLoadDictBase
|
||||||
|
|
||||||
|
|
||||||
def get_type_dict():
|
class AllTypesDict(LazyLoadDictBase):
|
||||||
|
def __init__(self):
|
||||||
|
self._all_types_dict = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def ALL_TYPES_DICT(self):
|
||||||
|
return self.all_types_dict
|
||||||
|
|
||||||
|
def _build_dict(self):
|
||||||
|
langchain_types_dict = self.get_type_dict()
|
||||||
|
return {
|
||||||
|
**langchain_types_dict,
|
||||||
|
"Custom": ["Custom Tool", "Python Function"],
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_type_dict(self):
|
||||||
return {
|
return {
|
||||||
"agents": agent_creator.to_list(),
|
"agents": agent_creator.to_list(),
|
||||||
"prompts": prompt_creator.to_list(),
|
"prompts": prompt_creator.to_list(),
|
||||||
|
|
@ -37,11 +53,4 @@ def get_type_dict():
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LANGCHAIN_TYPES_DICT = get_type_dict()
|
lazy_load_dict = AllTypesDict()
|
||||||
|
|
||||||
# Now we'll build a dict with Langchain types and ours
|
|
||||||
|
|
||||||
ALL_TYPES_DICT = {
|
|
||||||
**LANGCHAIN_TYPES_DICT,
|
|
||||||
"Custom": ["Custom Tool", "Python Function"],
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@ from typing import Dict, List, Optional, Type
|
||||||
|
|
||||||
from langflow.interface.base import LangChainTypeCreator
|
from langflow.interface.base import LangChainTypeCreator
|
||||||
from langflow.interface.custom_lists import llm_type_to_cls_dict
|
from langflow.interface.custom_lists import llm_type_to_cls_dict
|
||||||
from langflow.settings import settings
|
from langflow.services.utils import get_settings_manager
|
||||||
|
|
||||||
from langflow.template.frontend_node.llms import LLMFrontendNode
|
from langflow.template.frontend_node.llms import LLMFrontendNode
|
||||||
from langflow.utils.logger import logger
|
from langflow.utils.logger import logger
|
||||||
from langflow.utils.util import build_template_from_class
|
from langflow.utils.util import build_template_from_class
|
||||||
|
|
@ -33,10 +34,12 @@ class LLMCreator(LangChainTypeCreator):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def to_list(self) -> List[str]:
|
def to_list(self) -> List[str]:
|
||||||
|
settings_manager = get_settings_manager()
|
||||||
return [
|
return [
|
||||||
llm.__name__
|
llm.__name__
|
||||||
for llm in self.type_to_loader_dict.values()
|
for llm in self.type_to_loader_dict.values()
|
||||||
if llm.__name__ in settings.LLMS or settings.DEV
|
if llm.__name__ in settings_manager.settings.LLMS
|
||||||
|
or settings_manager.settings.DEV
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@ from typing import Dict, List, Optional, Type
|
||||||
|
|
||||||
from langflow.interface.base import LangChainTypeCreator
|
from langflow.interface.base import LangChainTypeCreator
|
||||||
from langflow.interface.custom_lists import memory_type_to_cls_dict
|
from langflow.interface.custom_lists import memory_type_to_cls_dict
|
||||||
from langflow.settings import settings
|
from langflow.services.utils import get_settings_manager
|
||||||
|
|
||||||
from langflow.template.frontend_node.base import FrontendNode
|
from langflow.template.frontend_node.base import FrontendNode
|
||||||
from langflow.template.frontend_node.memories import MemoryFrontendNode
|
from langflow.template.frontend_node.memories import MemoryFrontendNode
|
||||||
from langflow.utils.logger import logger
|
from langflow.utils.logger import logger
|
||||||
|
|
@ -48,10 +49,12 @@ class MemoryCreator(LangChainTypeCreator):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def to_list(self) -> List[str]:
|
def to_list(self) -> List[str]:
|
||||||
|
settings_manager = get_settings_manager()
|
||||||
return [
|
return [
|
||||||
memory.__name__
|
memory.__name__
|
||||||
for memory in self.type_to_loader_dict.values()
|
for memory in self.type_to_loader_dict.values()
|
||||||
if memory.__name__ in settings.MEMORIES or settings.DEV
|
if memory.__name__ in settings_manager.settings.MEMORIES
|
||||||
|
or settings_manager.settings.DEV
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@ from langchain import output_parsers
|
||||||
|
|
||||||
from langflow.interface.base import LangChainTypeCreator
|
from langflow.interface.base import LangChainTypeCreator
|
||||||
from langflow.interface.importing.utils import import_class
|
from langflow.interface.importing.utils import import_class
|
||||||
from langflow.settings import settings
|
from langflow.services.utils import get_settings_manager
|
||||||
|
|
||||||
from langflow.template.frontend_node.output_parsers import OutputParserFrontendNode
|
from langflow.template.frontend_node.output_parsers import OutputParserFrontendNode
|
||||||
from langflow.utils.logger import logger
|
from langflow.utils.logger import logger
|
||||||
from langflow.utils.util import build_template_from_class, build_template_from_method
|
from langflow.utils.util import build_template_from_class, build_template_from_method
|
||||||
|
|
@ -23,6 +24,7 @@ class OutputParserCreator(LangChainTypeCreator):
|
||||||
@property
|
@property
|
||||||
def type_to_loader_dict(self) -> Dict:
|
def type_to_loader_dict(self) -> Dict:
|
||||||
if self.type_dict is None:
|
if self.type_dict is None:
|
||||||
|
settings_manager = get_settings_manager()
|
||||||
self.type_dict = {
|
self.type_dict = {
|
||||||
output_parser_name: import_class(
|
output_parser_name: import_class(
|
||||||
f"langchain.output_parsers.{output_parser_name}"
|
f"langchain.output_parsers.{output_parser_name}"
|
||||||
|
|
@ -33,7 +35,8 @@ class OutputParserCreator(LangChainTypeCreator):
|
||||||
self.type_dict = {
|
self.type_dict = {
|
||||||
name: output_parser
|
name: output_parser
|
||||||
for name, output_parser in self.type_dict.items()
|
for name, output_parser in self.type_dict.items()
|
||||||
if name in settings.OUTPUT_PARSERS or settings.DEV
|
if name in settings_manager.settings.OUTPUT_PARSERS
|
||||||
|
or settings_manager.settings.DEV
|
||||||
}
|
}
|
||||||
return self.type_dict
|
return self.type_dict
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,8 @@ from langchain import prompts
|
||||||
from langflow.custom.customs import get_custom_nodes
|
from langflow.custom.customs import get_custom_nodes
|
||||||
from langflow.interface.base import LangChainTypeCreator
|
from langflow.interface.base import LangChainTypeCreator
|
||||||
from langflow.interface.importing.utils import import_class
|
from langflow.interface.importing.utils import import_class
|
||||||
from langflow.settings import settings
|
from langflow.services.utils import get_settings_manager
|
||||||
|
|
||||||
from langflow.template.frontend_node.prompts import PromptFrontendNode
|
from langflow.template.frontend_node.prompts import PromptFrontendNode
|
||||||
from langflow.utils.logger import logger
|
from langflow.utils.logger import logger
|
||||||
from langflow.utils.util import build_template_from_class
|
from langflow.utils.util import build_template_from_class
|
||||||
|
|
@ -20,6 +21,7 @@ class PromptCreator(LangChainTypeCreator):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def type_to_loader_dict(self) -> Dict:
|
def type_to_loader_dict(self) -> Dict:
|
||||||
|
settings_manager = get_settings_manager()
|
||||||
if self.type_dict is None:
|
if self.type_dict is None:
|
||||||
self.type_dict = {
|
self.type_dict = {
|
||||||
prompt_name: import_class(f"langchain.prompts.{prompt_name}")
|
prompt_name: import_class(f"langchain.prompts.{prompt_name}")
|
||||||
|
|
@ -34,7 +36,8 @@ class PromptCreator(LangChainTypeCreator):
|
||||||
self.type_dict = {
|
self.type_dict = {
|
||||||
name: prompt
|
name: prompt
|
||||||
for name, prompt in self.type_dict.items()
|
for name, prompt in self.type_dict.items()
|
||||||
if name in settings.PROMPTS or settings.DEV
|
if name in settings_manager.settings.PROMPTS
|
||||||
|
or settings_manager.settings.DEV
|
||||||
}
|
}
|
||||||
return self.type_dict
|
return self.type_dict
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@ from langchain import retrievers
|
||||||
|
|
||||||
from langflow.interface.base import LangChainTypeCreator
|
from langflow.interface.base import LangChainTypeCreator
|
||||||
from langflow.interface.importing.utils import import_class
|
from langflow.interface.importing.utils import import_class
|
||||||
from langflow.settings import settings
|
from langflow.services.utils import get_settings_manager
|
||||||
|
|
||||||
from langflow.template.frontend_node.retrievers import RetrieverFrontendNode
|
from langflow.template.frontend_node.retrievers import RetrieverFrontendNode
|
||||||
from langflow.utils.logger import logger
|
from langflow.utils.logger import logger
|
||||||
from langflow.utils.util import build_template_from_method, build_template_from_class
|
from langflow.utils.util import build_template_from_method, build_template_from_class
|
||||||
|
|
@ -48,10 +49,12 @@ class RetrieverCreator(LangChainTypeCreator):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def to_list(self) -> List[str]:
|
def to_list(self) -> List[str]:
|
||||||
|
settings_manager = get_settings_manager()
|
||||||
return [
|
return [
|
||||||
retriever
|
retriever
|
||||||
for retriever in self.type_to_loader_dict.keys()
|
for retriever in self.type_to_loader_dict.keys()
|
||||||
if retriever in settings.RETRIEVERS or settings.DEV
|
if retriever in settings_manager.settings.RETRIEVERS
|
||||||
|
or settings_manager.settings.DEV
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from langflow.cache.utils import memoize_dict
|
from langflow.services.cache.utils import memoize_dict
|
||||||
from langflow.graph import Graph
|
from langflow.graph import Graph
|
||||||
from langflow.utils.logger import logger
|
from langflow.utils.logger import logger
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
from typing import Dict, List, Optional, Type
|
from typing import Dict, List, Optional, Type
|
||||||
|
|
||||||
from langflow.interface.base import LangChainTypeCreator
|
from langflow.interface.base import LangChainTypeCreator
|
||||||
|
from langflow.services.utils import get_settings_manager
|
||||||
from langflow.template.frontend_node.textsplitters import TextSplittersFrontendNode
|
from langflow.template.frontend_node.textsplitters import TextSplittersFrontendNode
|
||||||
from langflow.interface.custom_lists import textsplitter_type_to_cls_dict
|
from langflow.interface.custom_lists import textsplitter_type_to_cls_dict
|
||||||
from langflow.settings import settings
|
|
||||||
from langflow.utils.logger import logger
|
from langflow.utils.logger import logger
|
||||||
from langflow.utils.util import build_template_from_class
|
from langflow.utils.util import build_template_from_class
|
||||||
|
|
||||||
|
|
@ -30,10 +31,12 @@ class TextSplitterCreator(LangChainTypeCreator):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def to_list(self) -> List[str]:
|
def to_list(self) -> List[str]:
|
||||||
|
settings_manager = get_settings_manager()
|
||||||
return [
|
return [
|
||||||
textsplitter.__name__
|
textsplitter.__name__
|
||||||
for textsplitter in self.type_to_loader_dict.values()
|
for textsplitter in self.type_to_loader_dict.values()
|
||||||
if textsplitter.__name__ in settings.TEXTSPLITTERS or settings.DEV
|
if textsplitter.__name__ in settings_manager.settings.TEXTSPLITTERS
|
||||||
|
or settings_manager.settings.DEV
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@ from langchain.agents import agent_toolkits
|
||||||
|
|
||||||
from langflow.interface.base import LangChainTypeCreator
|
from langflow.interface.base import LangChainTypeCreator
|
||||||
from langflow.interface.importing.utils import import_class, import_module
|
from langflow.interface.importing.utils import import_class, import_module
|
||||||
from langflow.settings import settings
|
from langflow.services.utils import get_settings_manager
|
||||||
|
|
||||||
from langflow.utils.logger import logger
|
from langflow.utils.logger import logger
|
||||||
from langflow.utils.util import build_template_from_class
|
from langflow.utils.util import build_template_from_class
|
||||||
|
|
||||||
|
|
@ -29,13 +30,15 @@ class ToolkitCreator(LangChainTypeCreator):
|
||||||
@property
|
@property
|
||||||
def type_to_loader_dict(self) -> Dict:
|
def type_to_loader_dict(self) -> Dict:
|
||||||
if self.type_dict is None:
|
if self.type_dict is None:
|
||||||
|
settings_manager = get_settings_manager()
|
||||||
self.type_dict = {
|
self.type_dict = {
|
||||||
toolkit_name: import_class(
|
toolkit_name: import_class(
|
||||||
f"langchain.agents.agent_toolkits.{toolkit_name}"
|
f"langchain.agents.agent_toolkits.{toolkit_name}"
|
||||||
)
|
)
|
||||||
# if toolkit_name is not lower case it is a class
|
# if toolkit_name is not lower case it is a class
|
||||||
for toolkit_name in agent_toolkits.__all__
|
for toolkit_name in agent_toolkits.__all__
|
||||||
if not toolkit_name.islower() and toolkit_name in settings.TOOLKITS
|
if not toolkit_name.islower()
|
||||||
|
and toolkit_name in settings_manager.settings.TOOLKITS
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.type_dict
|
return self.type_dict
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@ from langflow.interface.tools.constants import (
|
||||||
OTHER_TOOLS,
|
OTHER_TOOLS,
|
||||||
)
|
)
|
||||||
from langflow.interface.tools.util import get_tool_params
|
from langflow.interface.tools.util import get_tool_params
|
||||||
from langflow.settings import settings
|
from langflow.services.utils import get_settings_manager
|
||||||
|
|
||||||
from langflow.template.field.base import TemplateField
|
from langflow.template.field.base import TemplateField
|
||||||
from langflow.template.template.base import Template
|
from langflow.template.template.base import Template
|
||||||
from langflow.utils import util
|
from langflow.utils import util
|
||||||
|
|
@ -66,6 +67,7 @@ class ToolCreator(LangChainTypeCreator):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def type_to_loader_dict(self) -> Dict:
|
def type_to_loader_dict(self) -> Dict:
|
||||||
|
settings_manager = get_settings_manager()
|
||||||
if self.tools_dict is None:
|
if self.tools_dict is None:
|
||||||
all_tools = {}
|
all_tools = {}
|
||||||
|
|
||||||
|
|
@ -74,7 +76,10 @@ class ToolCreator(LangChainTypeCreator):
|
||||||
|
|
||||||
tool_name = tool_params.get("name") or tool
|
tool_name = tool_params.get("name") or tool
|
||||||
|
|
||||||
if tool_name in settings.TOOLS or settings.DEV:
|
if (
|
||||||
|
tool_name in settings_manager.settings.TOOLS
|
||||||
|
or settings_manager.settings.DEV
|
||||||
|
):
|
||||||
if tool_name == "JsonSpec":
|
if tool_name == "JsonSpec":
|
||||||
tool_params["path"] = tool_params.pop("dict_") # type: ignore
|
tool_params["path"] = tool_params.pop("dict_") # type: ignore
|
||||||
all_tools[tool_name] = {
|
all_tools[tool_name] = {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import ast
|
import ast
|
||||||
import contextlib
|
import contextlib
|
||||||
from typing import Any
|
from typing import Any, List
|
||||||
from langflow.api.utils import merge_nested_dicts_with_renaming
|
from langflow.api.utils import merge_nested_dicts_with_renaming
|
||||||
from langflow.interface.agents.base import agent_creator
|
from langflow.interface.agents.base import agent_creator
|
||||||
from langflow.interface.chains.base import chain_creator
|
from langflow.interface.chains.base import chain_creator
|
||||||
|
|
@ -199,6 +199,9 @@ def update_attributes(frontend_node, template_config):
|
||||||
if "beta" in template_config:
|
if "beta" in template_config:
|
||||||
frontend_node["beta"] = template_config["beta"]
|
frontend_node["beta"] = template_config["beta"]
|
||||||
|
|
||||||
|
if "documentation" in template_config:
|
||||||
|
frontend_node["documentation"] = template_config["documentation"]
|
||||||
|
|
||||||
|
|
||||||
def build_field_config(custom_component: CustomComponent):
|
def build_field_config(custom_component: CustomComponent):
|
||||||
"""Build the field configuration for a custom component"""
|
"""Build the field configuration for a custom component"""
|
||||||
|
|
@ -257,8 +260,9 @@ def get_field_properties(extra_field):
|
||||||
return field_name, field_type, field_value, field_required
|
return field_name, field_type, field_value, field_required
|
||||||
|
|
||||||
|
|
||||||
def add_base_classes(frontend_node, return_type):
|
def add_base_classes(frontend_node, return_types: List[str]):
|
||||||
"""Add base classes to the frontend node"""
|
"""Add base classes to the frontend node"""
|
||||||
|
for return_type in return_types:
|
||||||
if return_type not in CUSTOM_COMPONENT_SUPPORTED_TYPES or return_type is None:
|
if return_type not in CUSTOM_COMPONENT_SUPPORTED_TYPES or return_type is None:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=400,
|
status_code=400,
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,8 @@ from langchain import SQLDatabase, utilities
|
||||||
from langflow.custom.customs import get_custom_nodes
|
from langflow.custom.customs import get_custom_nodes
|
||||||
from langflow.interface.base import LangChainTypeCreator
|
from langflow.interface.base import LangChainTypeCreator
|
||||||
from langflow.interface.importing.utils import import_class
|
from langflow.interface.importing.utils import import_class
|
||||||
from langflow.settings import settings
|
from langflow.services.utils import get_settings_manager
|
||||||
|
|
||||||
from langflow.template.frontend_node.utilities import UtilitiesFrontendNode
|
from langflow.template.frontend_node.utilities import UtilitiesFrontendNode
|
||||||
from langflow.utils.logger import logger
|
from langflow.utils.logger import logger
|
||||||
from langflow.utils.util import build_template_from_class
|
from langflow.utils.util import build_template_from_class
|
||||||
|
|
@ -26,6 +27,7 @@ class UtilityCreator(LangChainTypeCreator):
|
||||||
from the langchain.chains module and filtering them according to the settings.utilities list.
|
from the langchain.chains module and filtering them according to the settings.utilities list.
|
||||||
"""
|
"""
|
||||||
if self.type_dict is None:
|
if self.type_dict is None:
|
||||||
|
settings_manager = get_settings_manager()
|
||||||
self.type_dict = {
|
self.type_dict = {
|
||||||
utility_name: import_class(f"langchain.utilities.{utility_name}")
|
utility_name: import_class(f"langchain.utilities.{utility_name}")
|
||||||
for utility_name in utilities.__all__
|
for utility_name in utilities.__all__
|
||||||
|
|
@ -35,7 +37,8 @@ class UtilityCreator(LangChainTypeCreator):
|
||||||
self.type_dict = {
|
self.type_dict = {
|
||||||
name: utility
|
name: utility
|
||||||
for name, utility in self.type_dict.items()
|
for name, utility in self.type_dict.items()
|
||||||
if name in settings.UTILITIES or settings.DEV
|
if name in settings_manager.settings.UTILITIES
|
||||||
|
or settings_manager.settings.DEV
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.type_dict
|
return self.type_dict
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,8 @@ import yaml
|
||||||
from langchain.base_language import BaseLanguageModel
|
from langchain.base_language import BaseLanguageModel
|
||||||
from PIL.Image import Image
|
from PIL.Image import Image
|
||||||
from langflow.utils.logger import logger
|
from langflow.utils.logger import logger
|
||||||
from langflow.chat.config import ChatConfig
|
from langflow.services.chat.config import ChatConfig
|
||||||
|
from langflow.services.utils import get_settings_manager
|
||||||
|
|
||||||
|
|
||||||
def load_file_into_dict(file_path: str) -> dict:
|
def load_file_into_dict(file_path: str) -> dict:
|
||||||
|
|
@ -63,13 +64,11 @@ def extract_input_variables_from_prompt(prompt: str) -> list[str]:
|
||||||
|
|
||||||
def setup_llm_caching():
|
def setup_llm_caching():
|
||||||
"""Setup LLM caching."""
|
"""Setup LLM caching."""
|
||||||
|
settings_manager = get_settings_manager()
|
||||||
from langflow.settings import settings
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
set_langchain_cache(settings)
|
set_langchain_cache(settings_manager.settings)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
logger.warning(f"Could not import {settings.CACHE}. ")
|
logger.warning(f"Could not import {settings_manager.settings.CACHE}. ")
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.warning(f"Could not setup LLM caching. Error: {exc}")
|
logger.warning(f"Could not setup LLM caching. Error: {exc}")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@ from langchain import vectorstores
|
||||||
|
|
||||||
from langflow.interface.base import LangChainTypeCreator
|
from langflow.interface.base import LangChainTypeCreator
|
||||||
from langflow.interface.importing.utils import import_class
|
from langflow.interface.importing.utils import import_class
|
||||||
from langflow.settings import settings
|
from langflow.services.utils import get_settings_manager
|
||||||
|
|
||||||
from langflow.template.frontend_node.vectorstores import VectorStoreFrontendNode
|
from langflow.template.frontend_node.vectorstores import VectorStoreFrontendNode
|
||||||
from langflow.utils.logger import logger
|
from langflow.utils.logger import logger
|
||||||
from langflow.utils.util import build_template_from_method
|
from langflow.utils.util import build_template_from_method
|
||||||
|
|
@ -43,10 +44,12 @@ class VectorstoreCreator(LangChainTypeCreator):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def to_list(self) -> List[str]:
|
def to_list(self) -> List[str]:
|
||||||
|
settings_manager = get_settings_manager()
|
||||||
return [
|
return [
|
||||||
vectorstore
|
vectorstore
|
||||||
for vectorstore in self.type_to_loader_dict.keys()
|
for vectorstore in self.type_to_loader_dict.keys()
|
||||||
if vectorstore in settings.VECTORSTORES or settings.DEV
|
if vectorstore in settings_manager.settings.VECTORSTORES
|
||||||
|
or settings_manager.settings.DEV
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,15 @@ from fastapi.responses import FileResponse
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
|
||||||
from langflow.api import router
|
from langflow.api import router
|
||||||
from langflow.database.base import create_db_and_tables, Engine
|
|
||||||
from langflow.interface.utils import setup_llm_caching
|
from langflow.interface.utils import setup_llm_caching
|
||||||
|
from langflow.services.database.utils import initialize_database
|
||||||
|
from langflow.services.manager import initialize_services
|
||||||
from langflow.utils.logger import configure
|
from langflow.utils.logger import configure
|
||||||
|
|
||||||
|
|
||||||
def create_app():
|
def create_app():
|
||||||
"""Create the FastAPI app and include the router."""
|
"""Create the FastAPI app and include the router."""
|
||||||
|
|
||||||
configure()
|
configure()
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
@ -32,10 +34,10 @@ def create_app():
|
||||||
allow_methods=["*"],
|
allow_methods=["*"],
|
||||||
allow_headers=["*"],
|
allow_headers=["*"],
|
||||||
)
|
)
|
||||||
|
|
||||||
app.include_router(router)
|
app.include_router(router)
|
||||||
app.on_event("startup")(Engine.update)
|
|
||||||
app.on_event("startup")(create_db_and_tables)
|
app.on_event("startup")(initialize_services)
|
||||||
|
app.on_event("startup")(initialize_database)
|
||||||
app.on_event("startup")(setup_llm_caching)
|
app.on_event("startup")(setup_llm_caching)
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
@ -68,15 +70,18 @@ def get_static_files_dir():
|
||||||
return frontend_path / "frontend"
|
return frontend_path / "frontend"
|
||||||
|
|
||||||
|
|
||||||
def setup_app(static_files_dir: Optional[Path] = None) -> FastAPI:
|
def setup_app(
|
||||||
|
static_files_dir: Optional[Path] = None, backend_only: bool = False
|
||||||
|
) -> FastAPI:
|
||||||
"""Setup the FastAPI app."""
|
"""Setup the FastAPI app."""
|
||||||
# get the directory of the current file
|
# get the directory of the current file
|
||||||
if not static_files_dir:
|
if not static_files_dir:
|
||||||
static_files_dir = get_static_files_dir()
|
static_files_dir = get_static_files_dir()
|
||||||
|
|
||||||
if not static_files_dir or not static_files_dir.exists():
|
if not backend_only and (not static_files_dir or not static_files_dir.exists()):
|
||||||
raise RuntimeError(f"Static files directory {static_files_dir} does not exist.")
|
raise RuntimeError(f"Static files directory {static_files_dir} does not exist.")
|
||||||
app = create_app()
|
app = create_app()
|
||||||
|
if not backend_only and static_files_dir is not None:
|
||||||
setup_static_files(app, static_files_dir)
|
setup_static_files(app, static_files_dir)
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
|
||||||
4
src/backend/langflow/services/__init__.py
Normal file
4
src/backend/langflow/services/__init__.py
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
from .manager import service_manager
|
||||||
|
from .schema import ServiceType
|
||||||
|
|
||||||
|
__all__ = ["service_manager", "ServiceType"]
|
||||||
2
src/backend/langflow/services/base.py
Normal file
2
src/backend/langflow/services/base.py
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
class Service:
|
||||||
|
name: str
|
||||||
11
src/backend/langflow/services/cache/__init__.py
vendored
Normal file
11
src/backend/langflow/services/cache/__init__.py
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
from . import factory, manager
|
||||||
|
from langflow.services.cache.manager import cache_manager
|
||||||
|
from langflow.services.cache.flow import InMemoryCache
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"cache_manager",
|
||||||
|
"factory",
|
||||||
|
"manager",
|
||||||
|
"InMemoryCache",
|
||||||
|
]
|
||||||
11
src/backend/langflow/services/cache/factory.py
vendored
Normal file
11
src/backend/langflow/services/cache/factory.py
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
from langflow.services.cache.manager import CacheManager
|
||||||
|
from langflow.services.factory import ServiceFactory
|
||||||
|
|
||||||
|
|
||||||
|
class CacheManagerFactory(ServiceFactory):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(CacheManager)
|
||||||
|
|
||||||
|
def create(self, settings_service):
|
||||||
|
# Here you would have logic to create and configure a CacheManager
|
||||||
|
return CacheManager()
|
||||||
|
|
@ -2,7 +2,7 @@ import threading
|
||||||
import time
|
import time
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
from langflow.cache.base import BaseCache
|
from langflow.services.cache.base import BaseCache
|
||||||
|
|
||||||
|
|
||||||
class InMemoryCache(BaseCache):
|
class InMemoryCache(BaseCache):
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from typing import Any, Awaitable, Callable, List, Optional
|
from typing import Any, Awaitable, Callable, List, Optional
|
||||||
|
from langflow.services.base import Service
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
@ -49,9 +50,11 @@ class AsyncSubject:
|
||||||
await observer()
|
await observer()
|
||||||
|
|
||||||
|
|
||||||
class CacheManager(Subject):
|
class CacheManager(Subject, Service):
|
||||||
"""Manages cache for different clients and notifies observers on changes."""
|
"""Manages cache for different clients and notifies observers on changes."""
|
||||||
|
|
||||||
|
name = "cache_manager"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._cache = {}
|
self._cache = {}
|
||||||
11
src/backend/langflow/services/chat/factory.py
Normal file
11
src/backend/langflow/services/chat/factory.py
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
from langflow.services.chat.manager import ChatManager
|
||||||
|
from langflow.services.factory import ServiceFactory
|
||||||
|
|
||||||
|
|
||||||
|
class ChatManagerFactory(ServiceFactory):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(ChatManager)
|
||||||
|
|
||||||
|
def create(self, settings_service):
|
||||||
|
# Here you would have logic to create and configure a ChatManager
|
||||||
|
return ChatManager()
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from fastapi import WebSocket, status
|
from fastapi import WebSocket, status
|
||||||
from langflow.api.v1.schemas import ChatMessage, ChatResponse, FileResponse
|
from langflow.api.v1.schemas import ChatMessage, ChatResponse, FileResponse
|
||||||
from langflow.cache import cache_manager
|
from langflow.services.base import Service
|
||||||
from langflow.cache.manager import Subject
|
from langflow.services import service_manager
|
||||||
from langflow.chat.utils import process_graph
|
from langflow.services.cache.manager import Subject
|
||||||
|
from langflow.services.chat.utils import process_graph
|
||||||
from langflow.interface.utils import pil_to_base64
|
from langflow.interface.utils import pil_to_base64
|
||||||
|
from langflow.services.schema import ServiceType
|
||||||
from langflow.utils.logger import logger
|
from langflow.utils.logger import logger
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -12,7 +14,7 @@ import asyncio
|
||||||
import json
|
import json
|
||||||
from typing import Any, Dict, List
|
from typing import Any, Dict, List
|
||||||
|
|
||||||
from langflow.cache.flow import InMemoryCache
|
from langflow.services.cache.flow import InMemoryCache
|
||||||
|
|
||||||
|
|
||||||
class ChatHistory(Subject):
|
class ChatHistory(Subject):
|
||||||
|
|
@ -42,11 +44,13 @@ class ChatHistory(Subject):
|
||||||
self.history[client_id] = []
|
self.history[client_id] = []
|
||||||
|
|
||||||
|
|
||||||
class ChatManager:
|
class ChatManager(Service):
|
||||||
|
name = "chat_manager"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.active_connections: Dict[str, WebSocket] = {}
|
self.active_connections: Dict[str, WebSocket] = {}
|
||||||
self.chat_history = ChatHistory()
|
self.chat_history = ChatHistory()
|
||||||
self.cache_manager = cache_manager
|
self.cache_manager = service_manager.get(ServiceType.CACHE_MANAGER)
|
||||||
self.cache_manager.attach(self.update)
|
self.cache_manager.attach(self.update)
|
||||||
self.in_memory_cache = InMemoryCache()
|
self.in_memory_cache = InMemoryCache()
|
||||||
|
|
||||||
0
src/backend/langflow/services/database/__init__.py
Normal file
0
src/backend/langflow/services/database/__init__.py
Normal file
17
src/backend/langflow/services/database/factory.py
Normal file
17
src/backend/langflow/services/database/factory.py
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
from langflow.services.database.manager import DatabaseManager
|
||||||
|
from langflow.services.factory import ServiceFactory
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from langflow.services.settings.manager import SettingsManager
|
||||||
|
|
||||||
|
|
||||||
|
class DatabaseManagerFactory(ServiceFactory):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(DatabaseManager)
|
||||||
|
|
||||||
|
def create(self, settings_service: "SettingsManager"):
|
||||||
|
# Here you would have logic to create and configure a DatabaseManager
|
||||||
|
if not settings_service.settings.DATABASE_URL:
|
||||||
|
raise ValueError("No database URL provided")
|
||||||
|
return DatabaseManager(settings_service.settings.DATABASE_URL)
|
||||||
67
src/backend/langflow/services/database/manager.py
Normal file
67
src/backend/langflow/services/database/manager.py
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
from pathlib import Path
|
||||||
|
from langflow.services.base import Service
|
||||||
|
from sqlmodel import SQLModel, Session, create_engine
|
||||||
|
from langflow.utils.logger import logger
|
||||||
|
from alembic.config import Config
|
||||||
|
from alembic import command
|
||||||
|
from langflow.services.database import models # noqa
|
||||||
|
|
||||||
|
|
||||||
|
class DatabaseManager(Service):
|
||||||
|
name = "database_manager"
|
||||||
|
|
||||||
|
def __init__(self, database_url: str):
|
||||||
|
self.database_url = database_url
|
||||||
|
# This file is in langflow.services.database.manager.py
|
||||||
|
# the ini is in langflow
|
||||||
|
langflow_dir = Path(__file__).parent.parent.parent
|
||||||
|
self.script_location = langflow_dir / "alembic"
|
||||||
|
self.alembic_cfg_path = langflow_dir / "alembic.ini"
|
||||||
|
self.engine = create_engine(database_url)
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
self._session = Session(self.engine)
|
||||||
|
return self._session
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_value, traceback):
|
||||||
|
if exc_type is not None: # If an exception has been raised
|
||||||
|
logger.error(
|
||||||
|
f"Session rollback because of exception: {exc_type.__name__} {exc_value}"
|
||||||
|
)
|
||||||
|
self._session.rollback()
|
||||||
|
else:
|
||||||
|
self._session.commit()
|
||||||
|
self._session.close()
|
||||||
|
|
||||||
|
def get_session(self):
|
||||||
|
with Session(self.engine) as session:
|
||||||
|
yield session
|
||||||
|
|
||||||
|
def run_migrations(self):
|
||||||
|
logger.info(
|
||||||
|
f"Running DB migrations in {self.script_location} on {self.database_url}"
|
||||||
|
)
|
||||||
|
alembic_cfg = Config()
|
||||||
|
alembic_cfg.set_main_option("script_location", str(self.script_location))
|
||||||
|
alembic_cfg.set_main_option("sqlalchemy.url", self.database_url)
|
||||||
|
command.upgrade(alembic_cfg, "head")
|
||||||
|
|
||||||
|
def create_db_and_tables(self):
|
||||||
|
logger.debug("Creating database and tables")
|
||||||
|
try:
|
||||||
|
SQLModel.metadata.create_all(self.engine)
|
||||||
|
except Exception as exc:
|
||||||
|
logger.error(f"Error creating database and tables: {exc}")
|
||||||
|
raise RuntimeError("Error creating database and tables") from exc
|
||||||
|
|
||||||
|
# Now check if the table "flow" exists, if not, something went wrong
|
||||||
|
# and we need to create the tables again.
|
||||||
|
from sqlalchemy import inspect
|
||||||
|
|
||||||
|
inspector = inspect(self.engine)
|
||||||
|
if "flow" not in inspector.get_table_names():
|
||||||
|
logger.error("Something went wrong creating the database and tables.")
|
||||||
|
logger.error("Please check your database settings.")
|
||||||
|
raise RuntimeError("Something went wrong creating the database and tables.")
|
||||||
|
else:
|
||||||
|
logger.debug("Database and tables created successfully")
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
from .flow import Flow
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ["Flow"]
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from langflow.database.models.base import SQLModelSerializable, SQLModel
|
from langflow.services.database.models.base import SQLModelSerializable, SQLModel
|
||||||
from sqlmodel import Field
|
from sqlmodel import Field
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
# Path: src/backend/langflow/database/models/flow.py
|
# Path: src/backend/langflow/database/models/flow.py
|
||||||
|
|
||||||
from langflow.database.models.base import SQLModelSerializable
|
from langflow.services.database.models.base import SQLModelSerializable
|
||||||
from pydantic import validator
|
from pydantic import validator
|
||||||
from sqlmodel import Field, Relationship, JSON, Column
|
from sqlmodel import Field, JSON, Column
|
||||||
from uuid import UUID, uuid4
|
from uuid import UUID, uuid4
|
||||||
from typing import Dict, Optional
|
from typing import Dict, Optional
|
||||||
|
|
||||||
# if TYPE_CHECKING:
|
# if TYPE_CHECKING:
|
||||||
from langflow.database.models.flow_style import FlowStyle, FlowStyleRead
|
|
||||||
|
|
||||||
|
|
||||||
class FlowBase(SQLModelSerializable):
|
class FlowBase(SQLModelSerializable):
|
||||||
|
|
@ -35,11 +34,6 @@ class FlowBase(SQLModelSerializable):
|
||||||
class Flow(FlowBase, table=True):
|
class Flow(FlowBase, table=True):
|
||||||
id: UUID = Field(default_factory=uuid4, primary_key=True, unique=True)
|
id: UUID = Field(default_factory=uuid4, primary_key=True, unique=True)
|
||||||
data: Optional[Dict] = Field(default=None, sa_column=Column(JSON))
|
data: Optional[Dict] = Field(default=None, sa_column=Column(JSON))
|
||||||
style: Optional["FlowStyle"] = Relationship(
|
|
||||||
back_populates="flow",
|
|
||||||
# use "uselist=False" to make it a one-to-one relationship
|
|
||||||
sa_relationship_kwargs={"uselist": False},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class FlowCreate(FlowBase):
|
class FlowCreate(FlowBase):
|
||||||
|
|
@ -50,10 +44,6 @@ class FlowRead(FlowBase):
|
||||||
id: UUID
|
id: UUID
|
||||||
|
|
||||||
|
|
||||||
class FlowReadWithStyle(FlowRead):
|
|
||||||
style: Optional["FlowStyleRead"] = None
|
|
||||||
|
|
||||||
|
|
||||||
class FlowUpdate(SQLModelSerializable):
|
class FlowUpdate(SQLModelSerializable):
|
||||||
name: Optional[str] = None
|
name: Optional[str] = None
|
||||||
description: Optional[str] = None
|
description: Optional[str] = None
|
||||||
47
src/backend/langflow/services/database/utils.py
Normal file
47
src/backend/langflow/services/database/utils.py
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
from langflow.utils.logger import logger
|
||||||
|
from contextlib import contextmanager
|
||||||
|
from alembic.util.exc import CommandError
|
||||||
|
from sqlmodel import Session
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from langflow.services.database.manager import DatabaseManager
|
||||||
|
|
||||||
|
|
||||||
|
def initialize_database():
|
||||||
|
logger.debug("Initializing database")
|
||||||
|
from langflow.services import service_manager, ServiceType
|
||||||
|
|
||||||
|
database_manager = service_manager.get(ServiceType.DATABASE_MANAGER)
|
||||||
|
try:
|
||||||
|
database_manager.run_migrations()
|
||||||
|
except CommandError as exc:
|
||||||
|
if "Can't locate revision identified by" not in str(exc):
|
||||||
|
raise exc
|
||||||
|
# This means there's wrong revision in the DB
|
||||||
|
# We need to delete the alembic_version table
|
||||||
|
# and run the migrations again
|
||||||
|
logger.warning(
|
||||||
|
"Wrong revision in DB, deleting alembic_version table and running migrations again"
|
||||||
|
)
|
||||||
|
with session_getter(database_manager) as session:
|
||||||
|
session.execute("DROP TABLE alembic_version")
|
||||||
|
database_manager.run_migrations()
|
||||||
|
except Exception as exc:
|
||||||
|
logger.error(f"Error running migrations: {exc}")
|
||||||
|
raise RuntimeError("Error running migrations") from exc
|
||||||
|
database_manager.create_db_and_tables()
|
||||||
|
logger.debug("Database initialized")
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def session_getter(db_manager: "DatabaseManager"):
|
||||||
|
try:
|
||||||
|
session = Session(db_manager.engine)
|
||||||
|
yield session
|
||||||
|
except Exception as e:
|
||||||
|
print("Session rollback because of exception:", e)
|
||||||
|
session.rollback()
|
||||||
|
raise
|
||||||
|
finally:
|
||||||
|
session.close()
|
||||||
6
src/backend/langflow/services/factory.py
Normal file
6
src/backend/langflow/services/factory.py
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
class ServiceFactory:
|
||||||
|
def __init__(self, service_class):
|
||||||
|
self.service_class = service_class
|
||||||
|
|
||||||
|
def create(self, *args, **kwargs):
|
||||||
|
raise NotImplementedError
|
||||||
87
src/backend/langflow/services/manager.py
Normal file
87
src/backend/langflow/services/manager.py
Normal file
|
|
@ -0,0 +1,87 @@
|
||||||
|
from langflow.services.schema import ServiceType
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from langflow.services.factory import ServiceFactory
|
||||||
|
|
||||||
|
|
||||||
|
class ServiceManager:
|
||||||
|
"""
|
||||||
|
Manages the creation of different services.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.services = {}
|
||||||
|
self.factories = {}
|
||||||
|
|
||||||
|
def register_factory(self, service_factory: "ServiceFactory"):
|
||||||
|
"""
|
||||||
|
Registers a new factory.
|
||||||
|
"""
|
||||||
|
self.factories[service_factory.service_class.name] = service_factory
|
||||||
|
|
||||||
|
def get(self, service_name: ServiceType):
|
||||||
|
"""
|
||||||
|
Get (or create) a service by its name.
|
||||||
|
"""
|
||||||
|
if service_name not in self.services:
|
||||||
|
self._create_service(service_name)
|
||||||
|
|
||||||
|
return self.services[service_name]
|
||||||
|
|
||||||
|
def _create_service(self, service_name: ServiceType):
|
||||||
|
"""
|
||||||
|
Create a new service given its name.
|
||||||
|
"""
|
||||||
|
self._validate_service_creation(service_name)
|
||||||
|
|
||||||
|
if service_name == ServiceType.SETTINGS_MANAGER:
|
||||||
|
self.services[service_name] = self.factories[service_name].create()
|
||||||
|
else:
|
||||||
|
settings_service = self.get(ServiceType.SETTINGS_MANAGER)
|
||||||
|
self.services[service_name] = self.factories[service_name].create(
|
||||||
|
settings_service
|
||||||
|
)
|
||||||
|
|
||||||
|
def _validate_service_creation(self, service_name: ServiceType):
|
||||||
|
"""
|
||||||
|
Validate whether the service can be created.
|
||||||
|
"""
|
||||||
|
if service_name not in self.factories:
|
||||||
|
raise ValueError(
|
||||||
|
f"No factory registered for the service class '{service_name.name}'"
|
||||||
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
ServiceType.SETTINGS_MANAGER not in self.factories
|
||||||
|
and service_name != ServiceType.SETTINGS_MANAGER
|
||||||
|
):
|
||||||
|
raise ValueError(
|
||||||
|
f"Cannot create service '{service_name.name}' before the settings service"
|
||||||
|
)
|
||||||
|
|
||||||
|
def update(self, service_name: ServiceType):
|
||||||
|
"""
|
||||||
|
Update a service by its name.
|
||||||
|
"""
|
||||||
|
if service_name in self.services:
|
||||||
|
self.services.pop(service_name, None)
|
||||||
|
self.get(service_name)
|
||||||
|
|
||||||
|
|
||||||
|
service_manager = ServiceManager()
|
||||||
|
|
||||||
|
|
||||||
|
def initialize_services():
|
||||||
|
"""
|
||||||
|
Initialize all the services needed.
|
||||||
|
"""
|
||||||
|
from langflow.services.database import factory as database_factory
|
||||||
|
from langflow.services.cache import factory as cache_factory
|
||||||
|
from langflow.services.chat import factory as chat_factory
|
||||||
|
from langflow.services.settings import factory as settings_factory
|
||||||
|
|
||||||
|
service_manager.register_factory(settings_factory.SettingsManagerFactory())
|
||||||
|
service_manager.register_factory(database_factory.DatabaseManagerFactory())
|
||||||
|
service_manager.register_factory(cache_factory.CacheManagerFactory())
|
||||||
|
service_manager.register_factory(chat_factory.ChatManagerFactory())
|
||||||
13
src/backend/langflow/services/schema.py
Normal file
13
src/backend/langflow/services/schema.py
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
|
||||||
|
class ServiceType(str, Enum):
|
||||||
|
"""
|
||||||
|
Enum for the different types of services that can be
|
||||||
|
registered with the service manager.
|
||||||
|
"""
|
||||||
|
|
||||||
|
CACHE_MANAGER = "cache_manager"
|
||||||
|
SETTINGS_MANAGER = "settings_manager"
|
||||||
|
DATABASE_MANAGER = "database_manager"
|
||||||
|
CHAT_MANAGER = "chat_manager"
|
||||||
3
src/backend/langflow/services/settings/__init__.py
Normal file
3
src/backend/langflow/services/settings/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
from . import factory, manager
|
||||||
|
|
||||||
|
__all__ = ["factory", "manager"]
|
||||||
168
src/backend/langflow/services/settings/base.py
Normal file
168
src/backend/langflow/services/settings/base.py
Normal file
|
|
@ -0,0 +1,168 @@
|
||||||
|
import contextlib
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from typing import Optional, List
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
from pydantic import BaseSettings, root_validator, validator
|
||||||
|
from langflow.utils.logger import logger
|
||||||
|
|
||||||
|
BASE_COMPONENTS_PATH = str(Path(__file__).parent / "components")
|
||||||
|
|
||||||
|
|
||||||
|
class Settings(BaseSettings):
|
||||||
|
CHAINS: dict = {}
|
||||||
|
AGENTS: dict = {}
|
||||||
|
PROMPTS: dict = {}
|
||||||
|
LLMS: dict = {}
|
||||||
|
TOOLS: dict = {}
|
||||||
|
MEMORIES: dict = {}
|
||||||
|
EMBEDDINGS: dict = {}
|
||||||
|
VECTORSTORES: dict = {}
|
||||||
|
DOCUMENTLOADERS: dict = {}
|
||||||
|
WRAPPERS: dict = {}
|
||||||
|
RETRIEVERS: dict = {}
|
||||||
|
TOOLKITS: dict = {}
|
||||||
|
TEXTSPLITTERS: dict = {}
|
||||||
|
UTILITIES: dict = {}
|
||||||
|
OUTPUT_PARSERS: dict = {}
|
||||||
|
CUSTOM_COMPONENTS: dict = {}
|
||||||
|
|
||||||
|
DEV: bool = False
|
||||||
|
DATABASE_URL: Optional[str] = None
|
||||||
|
CACHE: str = "InMemoryCache"
|
||||||
|
REMOVE_API_KEYS: bool = False
|
||||||
|
COMPONENTS_PATH: List[str] = []
|
||||||
|
|
||||||
|
@validator("DATABASE_URL", pre=True)
|
||||||
|
def set_database_url(cls, value):
|
||||||
|
if not value:
|
||||||
|
logger.debug(
|
||||||
|
"No database_url provided, trying LANGFLOW_DATABASE_URL env variable"
|
||||||
|
)
|
||||||
|
if langflow_database_url := os.getenv("LANGFLOW_DATABASE_URL"):
|
||||||
|
value = langflow_database_url
|
||||||
|
logger.debug("Using LANGFLOW_DATABASE_URL env variable.")
|
||||||
|
else:
|
||||||
|
logger.debug("No DATABASE_URL env variable, using sqlite database")
|
||||||
|
value = "sqlite:///./langflow.db"
|
||||||
|
|
||||||
|
return value
|
||||||
|
|
||||||
|
@validator("COMPONENTS_PATH", pre=True)
|
||||||
|
def set_components_path(cls, value):
|
||||||
|
if os.getenv("LANGFLOW_COMPONENTS_PATH"):
|
||||||
|
logger.debug("Adding LANGFLOW_COMPONENTS_PATH to components_path")
|
||||||
|
langflow_component_path = os.getenv("LANGFLOW_COMPONENTS_PATH")
|
||||||
|
if (
|
||||||
|
Path(langflow_component_path).exists()
|
||||||
|
and langflow_component_path not in value
|
||||||
|
):
|
||||||
|
if isinstance(langflow_component_path, list):
|
||||||
|
for path in langflow_component_path:
|
||||||
|
if path not in value:
|
||||||
|
value.append(path)
|
||||||
|
logger.debug(
|
||||||
|
f"Extending {langflow_component_path} to components_path"
|
||||||
|
)
|
||||||
|
elif langflow_component_path not in value:
|
||||||
|
value.append(langflow_component_path)
|
||||||
|
logger.debug(
|
||||||
|
f"Appending {langflow_component_path} to components_path"
|
||||||
|
)
|
||||||
|
|
||||||
|
if not value:
|
||||||
|
value = [BASE_COMPONENTS_PATH]
|
||||||
|
logger.debug("Setting default components path to components_path")
|
||||||
|
elif BASE_COMPONENTS_PATH not in value:
|
||||||
|
value.append(BASE_COMPONENTS_PATH)
|
||||||
|
logger.debug("Adding default components path to components_path")
|
||||||
|
|
||||||
|
logger.debug(f"Components path: {value}")
|
||||||
|
return value
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
validate_assignment = True
|
||||||
|
extra = "ignore"
|
||||||
|
env_prefix = "LANGFLOW_"
|
||||||
|
|
||||||
|
@root_validator(allow_reuse=True)
|
||||||
|
def validate_lists(cls, values):
|
||||||
|
for key, value in values.items():
|
||||||
|
if key != "dev" and not value:
|
||||||
|
values[key] = []
|
||||||
|
return values
|
||||||
|
|
||||||
|
def update_from_yaml(self, file_path: str, dev: bool = False):
|
||||||
|
new_settings = load_settings_from_yaml(file_path)
|
||||||
|
self.CHAINS = new_settings.CHAINS or {}
|
||||||
|
self.AGENTS = new_settings.AGENTS or {}
|
||||||
|
self.PROMPTS = new_settings.PROMPTS or {}
|
||||||
|
self.LLMS = new_settings.LLMS or {}
|
||||||
|
self.TOOLS = new_settings.TOOLS or {}
|
||||||
|
self.MEMORIES = new_settings.MEMORIES or {}
|
||||||
|
self.WRAPPERS = new_settings.WRAPPERS or {}
|
||||||
|
self.TOOLKITS = new_settings.TOOLKITS or {}
|
||||||
|
self.TEXTSPLITTERS = new_settings.TEXTSPLITTERS or {}
|
||||||
|
self.UTILITIES = new_settings.UTILITIES or {}
|
||||||
|
self.EMBEDDINGS = new_settings.EMBEDDINGS or {}
|
||||||
|
self.VECTORSTORES = new_settings.VECTORSTORES or {}
|
||||||
|
self.DOCUMENTLOADERS = new_settings.DOCUMENTLOADERS or {}
|
||||||
|
self.RETRIEVERS = new_settings.RETRIEVERS or {}
|
||||||
|
self.OUTPUT_PARSERS = new_settings.OUTPUT_PARSERS or {}
|
||||||
|
self.CUSTOM_COMPONENTS = new_settings.CUSTOM_COMPONENTS or {}
|
||||||
|
self.COMPONENTS_PATH = new_settings.COMPONENTS_PATH or []
|
||||||
|
self.DEV = dev
|
||||||
|
|
||||||
|
def update_settings(self, **kwargs):
|
||||||
|
logger.debug("Updating settings")
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
# value may contain sensitive information, so we don't want to log it
|
||||||
|
if not hasattr(self, key):
|
||||||
|
logger.debug(f"Key {key} not found in settings")
|
||||||
|
continue
|
||||||
|
logger.debug(f"Updating {key}")
|
||||||
|
if isinstance(getattr(self, key), list):
|
||||||
|
# value might be a '[something]' string
|
||||||
|
with contextlib.suppress(json.decoder.JSONDecodeError):
|
||||||
|
value = json.loads(str(value))
|
||||||
|
if isinstance(value, list):
|
||||||
|
for item in value:
|
||||||
|
if item not in getattr(self, key):
|
||||||
|
getattr(self, key).append(item)
|
||||||
|
logger.debug(f"Extended {key}")
|
||||||
|
else:
|
||||||
|
getattr(self, key).append(value)
|
||||||
|
logger.debug(f"Appended {key}")
|
||||||
|
|
||||||
|
else:
|
||||||
|
setattr(self, key, value)
|
||||||
|
logger.debug(f"Updated {key}")
|
||||||
|
logger.debug(f"{key}: {getattr(self, key)}")
|
||||||
|
|
||||||
|
|
||||||
|
def save_settings_to_yaml(settings: Settings, file_path: str):
|
||||||
|
with open(file_path, "w") as f:
|
||||||
|
settings_dict = settings.dict()
|
||||||
|
yaml.dump(settings_dict, f)
|
||||||
|
|
||||||
|
|
||||||
|
def load_settings_from_yaml(file_path: str) -> Settings:
|
||||||
|
# Check if a string is a valid path or a file name
|
||||||
|
if "/" not in file_path:
|
||||||
|
# Get current path
|
||||||
|
current_path = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
file_path = os.path.join(current_path, file_path)
|
||||||
|
|
||||||
|
with open(file_path, "r") as f:
|
||||||
|
settings_dict = yaml.safe_load(f)
|
||||||
|
settings_dict = {k.upper(): v for k, v in settings_dict.items()}
|
||||||
|
|
||||||
|
for key in settings_dict:
|
||||||
|
if key not in Settings.__fields__.keys():
|
||||||
|
raise KeyError(f"Key {key} not found in settings")
|
||||||
|
logger.debug(f"Loading {len(settings_dict[key])} {key} from {file_path}")
|
||||||
|
|
||||||
|
return Settings(**settings_dict)
|
||||||
15
src/backend/langflow/services/settings/factory.py
Normal file
15
src/backend/langflow/services/settings/factory.py
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
from pathlib import Path
|
||||||
|
from langflow.services.settings.manager import SettingsManager
|
||||||
|
from langflow.services.factory import ServiceFactory
|
||||||
|
|
||||||
|
|
||||||
|
class SettingsManagerFactory(ServiceFactory):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(SettingsManager)
|
||||||
|
|
||||||
|
def create(self):
|
||||||
|
# Here you would have logic to create and configure a SettingsManager
|
||||||
|
langflow_dir = Path(__file__).parent.parent.parent
|
||||||
|
return SettingsManager.load_settings_from_yaml(
|
||||||
|
str(langflow_dir / "config.yaml")
|
||||||
|
)
|
||||||
36
src/backend/langflow/services/settings/manager.py
Normal file
36
src/backend/langflow/services/settings/manager.py
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
from langflow.services.base import Service
|
||||||
|
from langflow.services.settings.base import Settings
|
||||||
|
from langflow.utils.logger import logger
|
||||||
|
import os
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
|
class SettingsManager(Service):
|
||||||
|
name = "settings_manager"
|
||||||
|
|
||||||
|
def __init__(self, settings: Settings):
|
||||||
|
super().__init__()
|
||||||
|
self.settings = settings
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def load_settings_from_yaml(cls, file_path: str) -> "SettingsManager":
|
||||||
|
# Check if a string is a valid path or a file name
|
||||||
|
if "/" not in file_path:
|
||||||
|
# Get current path
|
||||||
|
current_path = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
file_path = os.path.join(current_path, file_path)
|
||||||
|
|
||||||
|
with open(file_path, "r") as f:
|
||||||
|
settings_dict = yaml.safe_load(f)
|
||||||
|
settings_dict = {k.upper(): v for k, v in settings_dict.items()}
|
||||||
|
|
||||||
|
for key in settings_dict:
|
||||||
|
if key not in Settings.__fields__.keys():
|
||||||
|
raise KeyError(f"Key {key} not found in settings")
|
||||||
|
logger.debug(
|
||||||
|
f"Loading {len(settings_dict[key])} {key} from {file_path}"
|
||||||
|
)
|
||||||
|
|
||||||
|
settings = Settings(**settings_dict)
|
||||||
|
return cls(settings)
|
||||||
18
src/backend/langflow/services/utils.py
Normal file
18
src/backend/langflow/services/utils.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
from langflow.services import ServiceType, service_manager
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from langflow.services.settings.manager import SettingsManager
|
||||||
|
|
||||||
|
|
||||||
|
def get_settings_manager() -> "SettingsManager":
|
||||||
|
return service_manager.get(ServiceType.SETTINGS_MANAGER)
|
||||||
|
|
||||||
|
|
||||||
|
def get_db_manager():
|
||||||
|
return service_manager.get(ServiceType.DATABASE_MANAGER)
|
||||||
|
|
||||||
|
|
||||||
|
def get_session():
|
||||||
|
db_manager = service_manager.get(ServiceType.DATABASE_MANAGER)
|
||||||
|
yield from db_manager.get_session()
|
||||||
|
|
@ -30,7 +30,6 @@ class DocumentLoaderFrontNode(FrontendNode):
|
||||||
"UnstructuredEmailLoader": build_file_field(
|
"UnstructuredEmailLoader": build_file_field(
|
||||||
suffixes=[".eml"], fileTypes=["eml"]
|
suffixes=[".eml"], fileTypes=["eml"]
|
||||||
),
|
),
|
||||||
"SlackDirectoryLoader": build_file_field(suffixes=[".zip"], fileTypes=["zip"]),
|
|
||||||
"EverNoteLoader": build_file_field(suffixes=[".xml"], fileTypes=["xml"]),
|
"EverNoteLoader": build_file_field(suffixes=[".xml"], fileTypes=["xml"]),
|
||||||
"FacebookChatLoader": build_file_field(suffixes=[".json"], fileTypes=["json"]),
|
"FacebookChatLoader": build_file_field(suffixes=[".json"], fileTypes=["json"]),
|
||||||
"BSHTMLLoader": build_file_field(suffixes=[".html"], fileTypes=["html"]),
|
"BSHTMLLoader": build_file_field(suffixes=[".html"], fileTypes=["html"]),
|
||||||
|
|
@ -105,7 +104,30 @@ class DocumentLoaderFrontNode(FrontendNode):
|
||||||
advanced=False,
|
advanced=False,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
elif self.template.type_name in {"SlackDirectoryLoader"}:
|
||||||
|
self.template.add_field(
|
||||||
|
TemplateField(
|
||||||
|
field_type="file",
|
||||||
|
required=True,
|
||||||
|
show=True,
|
||||||
|
name="zip_path",
|
||||||
|
value="",
|
||||||
|
display_name="Path to zip file",
|
||||||
|
suffixes=[".zip"],
|
||||||
|
file_types=["zip"],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.template.add_field(
|
||||||
|
TemplateField(
|
||||||
|
field_type="str",
|
||||||
|
required=False,
|
||||||
|
show=True,
|
||||||
|
name="workspace_url",
|
||||||
|
value="",
|
||||||
|
display_name="Workspace URL",
|
||||||
|
advanced=False,
|
||||||
|
)
|
||||||
|
)
|
||||||
elif self.template.type_name in self.file_path_templates:
|
elif self.template.type_name in self.file_path_templates:
|
||||||
self.template.add_field(self.file_path_templates[self.template.type_name])
|
self.template.add_field(self.file_path_templates[self.template.type_name])
|
||||||
elif self.template.type_name in {
|
elif self.template.type_name in {
|
||||||
|
|
|
||||||
15
src/backend/langflow/utils/lazy_load.py
Normal file
15
src/backend/langflow/utils/lazy_load.py
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
class LazyLoadDictBase:
|
||||||
|
def __init__(self):
|
||||||
|
self._all_types_dict = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def all_types_dict(self):
|
||||||
|
if self._all_types_dict is None:
|
||||||
|
self._all_types_dict = self._build_dict()
|
||||||
|
return self._all_types_dict
|
||||||
|
|
||||||
|
def _build_dict(self):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def get_type_dict(self):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
@ -1,5 +1,11 @@
|
||||||
import { cloneDeep } from "lodash";
|
import { cloneDeep } from "lodash";
|
||||||
import React, { useContext, useEffect, useRef, useState } from "react";
|
import React, {
|
||||||
|
ReactNode,
|
||||||
|
useContext,
|
||||||
|
useEffect,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
} from "react";
|
||||||
import { Handle, Position, useUpdateNodeInternals } from "reactflow";
|
import { Handle, Position, useUpdateNodeInternals } from "reactflow";
|
||||||
import ShadTooltip from "../../../../components/ShadTooltipComponent";
|
import ShadTooltip from "../../../../components/ShadTooltipComponent";
|
||||||
import CodeAreaComponent from "../../../../components/codeAreaComponent";
|
import CodeAreaComponent from "../../../../components/codeAreaComponent";
|
||||||
|
|
@ -17,6 +23,7 @@ import { TOOLTIP_EMPTY } from "../../../../constants/constants";
|
||||||
import { TabsContext } from "../../../../contexts/tabsContext";
|
import { TabsContext } from "../../../../contexts/tabsContext";
|
||||||
import { typesContext } from "../../../../contexts/typesContext";
|
import { typesContext } from "../../../../contexts/typesContext";
|
||||||
import { ParameterComponentType } from "../../../../types/components";
|
import { ParameterComponentType } from "../../../../types/components";
|
||||||
|
import { TabsState } from "../../../../types/tabs";
|
||||||
import { isValidConnection } from "../../../../utils/reactflowUtils";
|
import { isValidConnection } from "../../../../utils/reactflowUtils";
|
||||||
import {
|
import {
|
||||||
nodeColors,
|
nodeColors,
|
||||||
|
|
@ -38,15 +45,15 @@ export default function ParameterComponent({
|
||||||
required = false,
|
required = false,
|
||||||
optionalHandle = null,
|
optionalHandle = null,
|
||||||
info = "",
|
info = "",
|
||||||
}: ParameterComponentType) {
|
}: ParameterComponentType): JSX.Element {
|
||||||
const ref = useRef(null);
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
const refHtml = useRef(null);
|
const refHtml = useRef<HTMLDivElement & ReactNode>(null);
|
||||||
const infoHtml = useRef(null);
|
const infoHtml = useRef<HTMLDivElement & ReactNode>(null);
|
||||||
const updateNodeInternals = useUpdateNodeInternals();
|
const updateNodeInternals = useUpdateNodeInternals();
|
||||||
const [position, setPosition] = useState(0);
|
const [position, setPosition] = useState(0);
|
||||||
const { setTabsState, tabId, save, flows } = useContext(TabsContext);
|
const { setTabsState, tabId, save, flows } = useContext(TabsContext);
|
||||||
|
|
||||||
const flow = flows.find((f) => f.id === tabId).data?.nodes ?? null;
|
const flow = flows.find((flow) => flow.id === tabId)?.data?.nodes ?? null;
|
||||||
|
|
||||||
// Update component position
|
// Update component position
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -62,16 +69,18 @@ export default function ParameterComponent({
|
||||||
|
|
||||||
const { reactFlowInstance } = useContext(typesContext);
|
const { reactFlowInstance } = useContext(typesContext);
|
||||||
let disabled =
|
let disabled =
|
||||||
reactFlowInstance?.getEdges().some((e) => e.targetHandle === id) ?? false;
|
reactFlowInstance?.getEdges().some((edge) => edge.targetHandle === id) ??
|
||||||
|
false;
|
||||||
|
|
||||||
const { data: myData } = useContext(typesContext);
|
const { data: myData } = useContext(typesContext);
|
||||||
|
|
||||||
const handleOnNewValue = (newValue: any) => {
|
const handleOnNewValue = (newValue: string | string[] | boolean): void => {
|
||||||
let newData = cloneDeep(data);
|
let newData = cloneDeep(data);
|
||||||
newData.node.template[name].value = newValue;
|
newData.node!.template[name].value = newValue;
|
||||||
setData(newData);
|
setData(newData);
|
||||||
// Set state to pending
|
// Set state to pending
|
||||||
setTabsState((prev) => {
|
//@ts-ignore
|
||||||
|
setTabsState((prev: TabsState) => {
|
||||||
return {
|
return {
|
||||||
...prev,
|
...prev,
|
||||||
[tabId]: {
|
[tabId]: {
|
||||||
|
|
@ -86,10 +95,11 @@ export default function ParameterComponent({
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (name === "openai_api_base") console.log(info);
|
if (name === "openai_api_base") console.log(info);
|
||||||
|
// @ts-ignore
|
||||||
infoHtml.current = (
|
infoHtml.current = (
|
||||||
<div className="h-full w-full word-break-break-word">
|
<div className="h-full w-full break-words">
|
||||||
{info.split("\n").map((line, i) => (
|
{info.split("\n").map((line, index) => (
|
||||||
<p key={i} className="block">
|
<p key={index} className="block">
|
||||||
{line}
|
{line}
|
||||||
</p>
|
</p>
|
||||||
))}
|
))}
|
||||||
|
|
@ -98,18 +108,19 @@ export default function ParameterComponent({
|
||||||
}, [info]);
|
}, [info]);
|
||||||
|
|
||||||
function renderTooltips() {
|
function renderTooltips() {
|
||||||
let groupedObj = groupByFamily(myData, tooltipTitle, left, flow);
|
let groupedObj = groupByFamily(myData, tooltipTitle!, left, flow!);
|
||||||
|
|
||||||
if (groupedObj && groupedObj.length > 0) {
|
if (groupedObj && groupedObj.length > 0) {
|
||||||
refHtml.current = groupedObj.map((item, i) => {
|
//@ts-ignore
|
||||||
|
refHtml.current = groupedObj.map((item, index) => {
|
||||||
const Icon: any =
|
const Icon: any =
|
||||||
nodeIconsLucide[item.family] ?? nodeIconsLucide["unknown"];
|
nodeIconsLucide[item.family] ?? nodeIconsLucide["unknown"];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
key={i}
|
key={index}
|
||||||
className={classNames(
|
className={classNames(
|
||||||
i > 0 ? "mt-2 flex items-center" : "flex items-center"
|
index > 0 ? "mt-2 flex items-center" : "flex items-center"
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
|
|
@ -132,10 +143,10 @@ export default function ParameterComponent({
|
||||||
{" "}
|
{" "}
|
||||||
{item.type === "" ? "" : " - "}
|
{item.type === "" ? "" : " - "}
|
||||||
{item.type.split(", ").length > 2
|
{item.type.split(", ").length > 2
|
||||||
? item.type.split(", ").map((el, i) => (
|
? item.type.split(", ").map((el, index) => (
|
||||||
<React.Fragment key={el + i}>
|
<React.Fragment key={el + index}>
|
||||||
<span>
|
<span>
|
||||||
{i === item.type.split(", ").length - 1
|
{index === item.type.split(", ").length - 1
|
||||||
? el
|
? el
|
||||||
: (el += `, `)}
|
: (el += `, `)}
|
||||||
</span>
|
</span>
|
||||||
|
|
@ -148,6 +159,7 @@ export default function ParameterComponent({
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
//@ts-ignore
|
||||||
refHtml.current = <span>{TOOLTIP_EMPTY}</span>;
|
refHtml.current = <span>{TOOLTIP_EMPTY}</span>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -207,7 +219,7 @@ export default function ParameterComponent({
|
||||||
position={left ? Position.Left : Position.Right}
|
position={left ? Position.Left : Position.Right}
|
||||||
id={id}
|
id={id}
|
||||||
isValidConnection={(connection) =>
|
isValidConnection={(connection) =>
|
||||||
isValidConnection(connection, reactFlowInstance)
|
isValidConnection(connection, reactFlowInstance!)
|
||||||
}
|
}
|
||||||
className={classNames(
|
className={classNames(
|
||||||
left ? "-ml-0.5 " : "-mr-0.5 ",
|
left ? "-ml-0.5 " : "-mr-0.5 ",
|
||||||
|
|
@ -223,9 +235,9 @@ export default function ParameterComponent({
|
||||||
|
|
||||||
{left === true &&
|
{left === true &&
|
||||||
type === "str" &&
|
type === "str" &&
|
||||||
!data.node.template[name].options ? (
|
!data.node?.template[name].options ? (
|
||||||
<div className="mt-2 w-full">
|
<div className="mt-2 w-full">
|
||||||
{data.node.template[name].list ? (
|
{data.node?.template[name].list ? (
|
||||||
<InputListComponent
|
<InputListComponent
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
value={
|
value={
|
||||||
|
|
@ -236,7 +248,7 @@ export default function ParameterComponent({
|
||||||
}
|
}
|
||||||
onChange={handleOnNewValue}
|
onChange={handleOnNewValue}
|
||||||
/>
|
/>
|
||||||
) : data.node.template[name].multiline ? (
|
) : data.node?.template[name].multiline ? (
|
||||||
<TextAreaComponent
|
<TextAreaComponent
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
value={data.node.template[name].value ?? ""}
|
value={data.node.template[name].value ?? ""}
|
||||||
|
|
@ -245,8 +257,8 @@ export default function ParameterComponent({
|
||||||
) : (
|
) : (
|
||||||
<InputComponent
|
<InputComponent
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
password={data.node.template[name].password ?? false}
|
password={data.node?.template[name].password ?? false}
|
||||||
value={data.node.template[name].value ?? ""}
|
value={data.node?.template[name].value ?? ""}
|
||||||
onChange={handleOnNewValue}
|
onChange={handleOnNewValue}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
@ -255,9 +267,9 @@ export default function ParameterComponent({
|
||||||
<div className="mt-2 w-full">
|
<div className="mt-2 w-full">
|
||||||
<ToggleShadComponent
|
<ToggleShadComponent
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
enabled={data.node.template[name].value ?? false}
|
enabled={data.node?.template[name].value ?? false}
|
||||||
setEnabled={(t) => {
|
setEnabled={(isEnabled) => {
|
||||||
handleOnNewValue(t);
|
handleOnNewValue(isEnabled);
|
||||||
}}
|
}}
|
||||||
size="large"
|
size="large"
|
||||||
/>
|
/>
|
||||||
|
|
@ -266,13 +278,13 @@ export default function ParameterComponent({
|
||||||
<div className="mt-2 w-full">
|
<div className="mt-2 w-full">
|
||||||
<FloatComponent
|
<FloatComponent
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
value={data.node.template[name].value ?? ""}
|
value={data.node?.template[name].value ?? ""}
|
||||||
onChange={handleOnNewValue}
|
onChange={handleOnNewValue}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
) : left === true &&
|
) : left === true &&
|
||||||
type === "str" &&
|
type === "str" &&
|
||||||
data.node.template[name].options ? (
|
data.node?.template[name].options ? (
|
||||||
<div className="mt-2 w-full">
|
<div className="mt-2 w-full">
|
||||||
<Dropdown
|
<Dropdown
|
||||||
options={data.node.template[name].options}
|
options={data.node.template[name].options}
|
||||||
|
|
@ -283,13 +295,13 @@ export default function ParameterComponent({
|
||||||
) : left === true && type === "code" ? (
|
) : left === true && type === "code" ? (
|
||||||
<div className="mt-2 w-full">
|
<div className="mt-2 w-full">
|
||||||
<CodeAreaComponent
|
<CodeAreaComponent
|
||||||
dynamic={data.node.template[name].dynamic ?? false}
|
dynamic={data.node?.template[name].dynamic ?? false}
|
||||||
setNodeClass={(nodeClass) => {
|
setNodeClass={(nodeClass) => {
|
||||||
data.node = nodeClass;
|
data.node = nodeClass;
|
||||||
}}
|
}}
|
||||||
nodeClass={data.node}
|
nodeClass={data.node}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
value={data.node.template[name].value ?? ""}
|
value={data.node?.template[name].value ?? ""}
|
||||||
onChange={handleOnNewValue}
|
onChange={handleOnNewValue}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -297,12 +309,12 @@ export default function ParameterComponent({
|
||||||
<div className="mt-2 w-full">
|
<div className="mt-2 w-full">
|
||||||
<InputFileComponent
|
<InputFileComponent
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
value={data.node.template[name].value ?? ""}
|
value={data.node?.template[name].value ?? ""}
|
||||||
onChange={handleOnNewValue}
|
onChange={handleOnNewValue}
|
||||||
fileTypes={data.node.template[name].fileTypes}
|
fileTypes={data.node?.template[name].fileTypes}
|
||||||
suffixes={data.node.template[name].suffixes}
|
suffixes={data.node?.template[name].suffixes}
|
||||||
onFileChange={(t: string) => {
|
onFileChange={(filePath: string) => {
|
||||||
data.node.template[name].file_path = t;
|
data.node!.template[name].file_path = filePath;
|
||||||
save();
|
save();
|
||||||
}}
|
}}
|
||||||
></InputFileComponent>
|
></InputFileComponent>
|
||||||
|
|
@ -311,7 +323,7 @@ export default function ParameterComponent({
|
||||||
<div className="mt-2 w-full">
|
<div className="mt-2 w-full">
|
||||||
<IntComponent
|
<IntComponent
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
value={data.node.template[name].value ?? ""}
|
value={data.node?.template[name].value ?? ""}
|
||||||
onChange={handleOnNewValue}
|
onChange={handleOnNewValue}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -324,7 +336,7 @@ export default function ParameterComponent({
|
||||||
}}
|
}}
|
||||||
nodeClass={data.node}
|
nodeClass={data.node}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
value={data.node.template[name].value ?? ""}
|
value={data.node?.template[name].value ?? ""}
|
||||||
onChange={handleOnNewValue}
|
onChange={handleOnNewValue}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -159,52 +159,59 @@ export default function GenericNode({
|
||||||
|
|
||||||
<>
|
<>
|
||||||
{Object.keys(data.node.template)
|
{Object.keys(data.node.template)
|
||||||
.filter((t) => t.charAt(0) !== "_")
|
.filter((templateField) => templateField.charAt(0) !== "_")
|
||||||
.map((t: string, idx) => (
|
.map((templateField: string, idx) => (
|
||||||
<div key={idx}>
|
<div key={idx}>
|
||||||
{data.node.template[t].show &&
|
{data.node.template[templateField].show &&
|
||||||
!data.node.template[t].advanced ? (
|
!data.node.template[templateField].advanced ? (
|
||||||
<ParameterComponent
|
<ParameterComponent
|
||||||
key={
|
key={
|
||||||
(data.node.template[t].input_types?.join(";") ??
|
(data.node.template[templateField].input_types?.join(
|
||||||
data.node.template[t].type) +
|
";"
|
||||||
|
) ?? data.node.template[templateField].type) +
|
||||||
"|" +
|
"|" +
|
||||||
t +
|
templateField +
|
||||||
"|" +
|
"|" +
|
||||||
data.id
|
data.id
|
||||||
}
|
}
|
||||||
data={data}
|
data={data}
|
||||||
setData={setData}
|
setData={setData}
|
||||||
color={
|
color={
|
||||||
nodeColors[types[data.node.template[t].type]] ??
|
nodeColors[
|
||||||
nodeColors[data.node.template[t].type] ??
|
types[data.node.template[templateField].type]
|
||||||
|
] ??
|
||||||
|
nodeColors[data.node.template[templateField].type] ??
|
||||||
nodeColors.unknown
|
nodeColors.unknown
|
||||||
}
|
}
|
||||||
title={
|
title={
|
||||||
data.node.template[t].display_name
|
data.node.template[templateField].display_name
|
||||||
? data.node.template[t].display_name
|
? data.node.template[templateField].display_name
|
||||||
: data.node.template[t].name
|
: data.node.template[templateField].name
|
||||||
? toTitleCase(data.node.template[t].name)
|
? toTitleCase(data.node.template[templateField].name)
|
||||||
: toTitleCase(t)
|
: toTitleCase(templateField)
|
||||||
}
|
}
|
||||||
info={data.node.template[t].info}
|
info={data.node.template[templateField].info}
|
||||||
name={t}
|
name={templateField}
|
||||||
tooltipTitle={
|
tooltipTitle={
|
||||||
data.node.template[t].input_types?.join("\n") ??
|
data.node.template[templateField].input_types?.join(
|
||||||
data.node.template[t].type
|
"\n"
|
||||||
|
) ?? data.node.template[templateField].type
|
||||||
}
|
}
|
||||||
required={data.node.template[t].required}
|
required={data.node.template[templateField].required}
|
||||||
id={
|
id={
|
||||||
(data.node.template[t].input_types?.join(";") ??
|
(data.node.template[templateField].input_types?.join(
|
||||||
data.node.template[t].type) +
|
";"
|
||||||
|
) ?? data.node.template[templateField].type) +
|
||||||
"|" +
|
"|" +
|
||||||
t +
|
templateField +
|
||||||
"|" +
|
"|" +
|
||||||
data.id
|
data.id
|
||||||
}
|
}
|
||||||
left={true}
|
left={true}
|
||||||
type={data.node.template[t].type}
|
type={data.node.template[templateField].type}
|
||||||
optionalHandle={data.node.template[t].input_types}
|
optionalHandle={
|
||||||
|
data.node.template[templateField].input_types
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<></>
|
<></>
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,9 @@ export default function AlertDropdown({ children }: AlertDropdownType) {
|
||||||
return (
|
return (
|
||||||
<Popover
|
<Popover
|
||||||
open={open}
|
open={open}
|
||||||
onOpenChange={(k) => {
|
onOpenChange={(target) => {
|
||||||
setOpen(k);
|
setOpen(target);
|
||||||
if (k) setNotificationCenter(false);
|
if (target) setNotificationCenter(false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<PopoverTrigger>{children}</PopoverTrigger>
|
<PopoverTrigger>{children}</PopoverTrigger>
|
||||||
|
|
|
||||||
|
|
@ -55,12 +55,12 @@ export const EditFlowSettings: React.FC<InputProps> = ({
|
||||||
};
|
};
|
||||||
|
|
||||||
const [desc, setDesc] = useState(
|
const [desc, setDesc] = useState(
|
||||||
flows.find((f) => f.id === tabId).description
|
flows.find((flow) => flow.id === tabId).description
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleDescriptionChange = (event: ChangeEvent<HTMLTextAreaElement>) => {
|
const handleDescriptionChange = (event: ChangeEvent<HTMLTextAreaElement>) => {
|
||||||
flows.find((f) => f.id === tabId).description = event.target.value;
|
flows.find((flow) => flow.id === tabId).description = event.target.value;
|
||||||
setDesc(flows.find((f) => f.id === tabId).description);
|
setDesc(flows.find((flow) => flow.id === tabId).description);
|
||||||
setDescription(event.target.value);
|
setDescription(event.target.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,9 @@ export default function CodeAreaComponent({
|
||||||
value={myValue}
|
value={myValue}
|
||||||
nodeClass={nodeClass}
|
nodeClass={nodeClass}
|
||||||
setNodeClass={setNodeClass}
|
setNodeClass={setNodeClass}
|
||||||
setValue={(t: string) => {
|
setValue={(value: string) => {
|
||||||
setMyValue(t);
|
setMyValue(value);
|
||||||
onChange(t);
|
onChange(value);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className="flex w-full items-center">
|
<div className="flex w-full items-center">
|
||||||
|
|
|
||||||
|
|
@ -205,13 +205,15 @@ export default function CodeTabsComponent({
|
||||||
: "overflow-hidden"
|
: "overflow-hidden"
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{data.map((t: any, index) => (
|
{data.map((node: any, index) => (
|
||||||
<div className="px-3" key={index}>
|
<div className="px-3" key={index}>
|
||||||
{tweaks.tweaksList.current.includes(t["data"]["id"]) && (
|
{tweaks.tweaksList.current.includes(
|
||||||
|
node["data"]["id"]
|
||||||
|
) && (
|
||||||
<AccordionComponent
|
<AccordionComponent
|
||||||
trigger={t["data"]["id"]}
|
trigger={node["data"]["id"]}
|
||||||
open={openAccordion}
|
open={openAccordion}
|
||||||
keyValue={t["data"]["id"]}
|
keyValue={node["data"]["id"]}
|
||||||
>
|
>
|
||||||
<div className="api-modal-table-arrangement">
|
<div className="api-modal-table-arrangement">
|
||||||
<Table className="table-fixed bg-muted outline-1">
|
<Table className="table-fixed bg-muted outline-1">
|
||||||
|
|
@ -226,78 +228,92 @@ export default function CodeTabsComponent({
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody className="p-0">
|
<TableBody className="p-0">
|
||||||
{Object.keys(t["data"]["node"]["template"])
|
{Object.keys(node["data"]["node"]["template"])
|
||||||
.filter(
|
.filter(
|
||||||
(n) =>
|
(templateField) =>
|
||||||
n.charAt(0) !== "_" &&
|
templateField.charAt(0) !== "_" &&
|
||||||
t.data.node.template[n].show &&
|
node.data.node.template[templateField]
|
||||||
(t.data.node.template[n].type === "str" ||
|
.show &&
|
||||||
t.data.node.template[n].type ===
|
(node.data.node.template[templateField]
|
||||||
"bool" ||
|
.type === "str" ||
|
||||||
t.data.node.template[n].type ===
|
node.data.node.template[templateField]
|
||||||
"float" ||
|
.type === "bool" ||
|
||||||
t.data.node.template[n].type ===
|
node.data.node.template[templateField]
|
||||||
"code" ||
|
.type === "float" ||
|
||||||
t.data.node.template[n].type ===
|
node.data.node.template[templateField]
|
||||||
"prompt" ||
|
.type === "code" ||
|
||||||
t.data.node.template[n].type ===
|
node.data.node.template[templateField]
|
||||||
"file" ||
|
.type === "prompt" ||
|
||||||
t.data.node.template[n].type === "int")
|
node.data.node.template[templateField]
|
||||||
|
.type === "file" ||
|
||||||
|
node.data.node.template[templateField]
|
||||||
|
.type === "int")
|
||||||
)
|
)
|
||||||
.map((n, i) => {
|
.map((templateField, index) => {
|
||||||
return (
|
return (
|
||||||
<TableRow
|
<TableRow
|
||||||
key={i}
|
key={index}
|
||||||
className="h-10 dark:border-b-muted"
|
className="h-10 dark:border-b-muted"
|
||||||
>
|
>
|
||||||
<TableCell className="p-0 text-center text-sm text-foreground">
|
<TableCell className="p-0 text-center text-sm text-foreground">
|
||||||
{n}
|
{templateField}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="p-0 text-xs text-foreground">
|
<TableCell className="p-0 text-xs text-foreground">
|
||||||
<div className="m-auto w-[250px]">
|
<div className="m-auto w-[250px]">
|
||||||
{t.data.node.template[n].type ===
|
{node.data.node.template[
|
||||||
"str" &&
|
templateField
|
||||||
!t.data.node.template[n].options ? (
|
].type === "str" &&
|
||||||
|
!node.data.node.template[
|
||||||
|
templateField
|
||||||
|
].options ? (
|
||||||
<div className="mx-auto">
|
<div className="mx-auto">
|
||||||
{t.data.node.template[n]
|
{node.data.node.template[
|
||||||
.list ? (
|
templateField
|
||||||
|
].list ? (
|
||||||
<InputListComponent
|
<InputListComponent
|
||||||
editNode={true}
|
editNode={true}
|
||||||
disabled={false}
|
disabled={false}
|
||||||
value={
|
value={
|
||||||
!t.data.node.template[n]
|
!node.data.node.template[
|
||||||
.value ||
|
templateField
|
||||||
t.data.node.template[n]
|
].value ||
|
||||||
.value === ""
|
node.data.node.template[
|
||||||
|
templateField
|
||||||
|
].value === ""
|
||||||
? [""]
|
? [""]
|
||||||
: t.data.node.template[
|
: node.data.node
|
||||||
n
|
.template[
|
||||||
|
templateField
|
||||||
].value
|
].value
|
||||||
}
|
}
|
||||||
onChange={(k) => {
|
onChange={(target) => {
|
||||||
setData((old) => {
|
setData((old) => {
|
||||||
let newInputList =
|
let newInputList =
|
||||||
cloneDeep(old);
|
cloneDeep(old);
|
||||||
newInputList[
|
newInputList[
|
||||||
index
|
index
|
||||||
].data.node.template[
|
].data.node.template[
|
||||||
n
|
templateField
|
||||||
].value = k;
|
].value = target;
|
||||||
return newInputList;
|
return newInputList;
|
||||||
});
|
});
|
||||||
tweaks.buildTweakObject(
|
tweaks.buildTweakObject(
|
||||||
t["data"]["id"],
|
node["data"]["id"],
|
||||||
k,
|
target,
|
||||||
t.data.node.template[n]
|
node.data.node.template[
|
||||||
|
templateField
|
||||||
|
]
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
) : t.data.node.template[n]
|
) : node.data.node.template[
|
||||||
.multiline ? (
|
templateField
|
||||||
|
].multiline ? (
|
||||||
<ShadTooltip
|
<ShadTooltip
|
||||||
content={tweaks.buildContent(
|
content={tweaks.buildContent(
|
||||||
t.data.node.template[n]
|
node.data.node.template[
|
||||||
.value
|
templateField
|
||||||
|
].value
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -305,33 +321,38 @@ export default function CodeTabsComponent({
|
||||||
disabled={false}
|
disabled={false}
|
||||||
editNode={true}
|
editNode={true}
|
||||||
value={
|
value={
|
||||||
!t.data.node.template[
|
!node.data.node
|
||||||
n
|
.template[
|
||||||
|
templateField
|
||||||
].value ||
|
].value ||
|
||||||
t.data.node.template[
|
node.data.node
|
||||||
n
|
.template[
|
||||||
|
templateField
|
||||||
].value === ""
|
].value === ""
|
||||||
? ""
|
? ""
|
||||||
: t.data.node
|
: node.data.node
|
||||||
.template[n]
|
.template[
|
||||||
.value
|
templateField
|
||||||
|
].value
|
||||||
}
|
}
|
||||||
onChange={(k) => {
|
onChange={(target) => {
|
||||||
setData((old) => {
|
setData((old) => {
|
||||||
let newInputList =
|
let newInputList =
|
||||||
cloneDeep(old);
|
cloneDeep(old);
|
||||||
newInputList[
|
newInputList[
|
||||||
index
|
index
|
||||||
].data.node.template[
|
].data.node.template[
|
||||||
n
|
templateField
|
||||||
].value = k;
|
].value = target;
|
||||||
return newInputList;
|
return newInputList;
|
||||||
});
|
});
|
||||||
tweaks.buildTweakObject(
|
tweaks.buildTweakObject(
|
||||||
t["data"]["id"],
|
node["data"]["id"],
|
||||||
k,
|
target,
|
||||||
t.data.node
|
node.data.node
|
||||||
.template[n]
|
.template[
|
||||||
|
templateField
|
||||||
|
]
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
@ -342,47 +363,55 @@ export default function CodeTabsComponent({
|
||||||
editNode={true}
|
editNode={true}
|
||||||
disabled={false}
|
disabled={false}
|
||||||
password={
|
password={
|
||||||
t.data.node.template[n]
|
node.data.node.template[
|
||||||
.password ?? false
|
templateField
|
||||||
|
].password ?? false
|
||||||
}
|
}
|
||||||
value={
|
value={
|
||||||
!t.data.node.template[n]
|
!node.data.node.template[
|
||||||
.value ||
|
templateField
|
||||||
t.data.node.template[n]
|
].value ||
|
||||||
.value === ""
|
node.data.node.template[
|
||||||
|
templateField
|
||||||
|
].value === ""
|
||||||
? ""
|
? ""
|
||||||
: t.data.node.template[
|
: node.data.node
|
||||||
n
|
.template[
|
||||||
|
templateField
|
||||||
].value
|
].value
|
||||||
}
|
}
|
||||||
onChange={(k) => {
|
onChange={(target) => {
|
||||||
setData((old) => {
|
setData((old) => {
|
||||||
let newInputList =
|
let newInputList =
|
||||||
cloneDeep(old);
|
cloneDeep(old);
|
||||||
newInputList[
|
newInputList[
|
||||||
index
|
index
|
||||||
].data.node.template[
|
].data.node.template[
|
||||||
n
|
templateField
|
||||||
].value = k;
|
].value = target;
|
||||||
return newInputList;
|
return newInputList;
|
||||||
});
|
});
|
||||||
tweaks.buildTweakObject(
|
tweaks.buildTweakObject(
|
||||||
t["data"]["id"],
|
node["data"]["id"],
|
||||||
k,
|
target,
|
||||||
t.data.node.template[n]
|
node.data.node.template[
|
||||||
|
templateField
|
||||||
|
]
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
) : t.data.node.template[n].type ===
|
) : node.data.node.template[
|
||||||
"bool" ? (
|
templateField
|
||||||
|
].type === "bool" ? (
|
||||||
<div className="ml-auto">
|
<div className="ml-auto">
|
||||||
{" "}
|
{" "}
|
||||||
<ToggleShadComponent
|
<ToggleShadComponent
|
||||||
enabled={
|
enabled={
|
||||||
t.data.node.template[n]
|
node.data.node.template[
|
||||||
.value
|
templateField
|
||||||
|
].value
|
||||||
}
|
}
|
||||||
setEnabled={(e) => {
|
setEnabled={(e) => {
|
||||||
setData((old) => {
|
setData((old) => {
|
||||||
|
|
@ -391,31 +420,37 @@ export default function CodeTabsComponent({
|
||||||
newInputList[
|
newInputList[
|
||||||
index
|
index
|
||||||
].data.node.template[
|
].data.node.template[
|
||||||
n
|
templateField
|
||||||
].value = e;
|
].value = e;
|
||||||
return newInputList;
|
return newInputList;
|
||||||
});
|
});
|
||||||
tweaks.buildTweakObject(
|
tweaks.buildTweakObject(
|
||||||
t["data"]["id"],
|
node["data"]["id"],
|
||||||
e,
|
e,
|
||||||
t.data.node.template[n]
|
node.data.node.template[
|
||||||
|
templateField
|
||||||
|
]
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
size="small"
|
size="small"
|
||||||
disabled={false}
|
disabled={false}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
) : t.data.node.template[n].type ===
|
) : node.data.node.template[
|
||||||
"file" ? (
|
templateField
|
||||||
|
].type === "file" ? (
|
||||||
<ShadTooltip
|
<ShadTooltip
|
||||||
content={tweaks.buildContent(
|
content={tweaks.buildContent(
|
||||||
!t.data.node.template[n]
|
!node.data.node.template[
|
||||||
.value ||
|
templateField
|
||||||
t.data.node.template[n]
|
].value ||
|
||||||
.value === ""
|
node.data.node.template[
|
||||||
|
templateField
|
||||||
|
].value === ""
|
||||||
? ""
|
? ""
|
||||||
: t.data.node.template[n]
|
: node.data.node.template[
|
||||||
.value
|
templateField
|
||||||
|
].value
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className="mx-auto">
|
<div className="mx-auto">
|
||||||
|
|
@ -423,147 +458,176 @@ export default function CodeTabsComponent({
|
||||||
editNode={true}
|
editNode={true}
|
||||||
disabled={false}
|
disabled={false}
|
||||||
value={
|
value={
|
||||||
t.data.node.template[n]
|
node.data.node.template[
|
||||||
.value ?? ""
|
templateField
|
||||||
|
].value ?? ""
|
||||||
}
|
}
|
||||||
onChange={(k: any) => {}}
|
onChange={(
|
||||||
|
target: any
|
||||||
|
) => {}}
|
||||||
fileTypes={
|
fileTypes={
|
||||||
t.data.node.template[n]
|
node.data.node.template[
|
||||||
.fileTypes
|
templateField
|
||||||
|
].fileTypes
|
||||||
}
|
}
|
||||||
suffixes={
|
suffixes={
|
||||||
t.data.node.template[n]
|
node.data.node.template[
|
||||||
.suffixes
|
templateField
|
||||||
|
].suffixes
|
||||||
}
|
}
|
||||||
onFileChange={(
|
onFileChange={(
|
||||||
value: any
|
value: any
|
||||||
) => {
|
) => {
|
||||||
t.data.node.template[
|
node.data.node.template[
|
||||||
n
|
templateField
|
||||||
].file_path = value;
|
].file_path = value;
|
||||||
}}
|
}}
|
||||||
></InputFileComponent>
|
></InputFileComponent>
|
||||||
</div>
|
</div>
|
||||||
</ShadTooltip>
|
</ShadTooltip>
|
||||||
) : t.data.node.template[n].type ===
|
) : node.data.node.template[
|
||||||
"float" ? (
|
templateField
|
||||||
|
].type === "float" ? (
|
||||||
<div className="mx-auto">
|
<div className="mx-auto">
|
||||||
<FloatComponent
|
<FloatComponent
|
||||||
disabled={false}
|
disabled={false}
|
||||||
editNode={true}
|
editNode={true}
|
||||||
value={
|
value={
|
||||||
!t.data.node.template[n]
|
!node.data.node.template[
|
||||||
.value ||
|
templateField
|
||||||
t.data.node.template[n]
|
].value ||
|
||||||
.value === ""
|
node.data.node.template[
|
||||||
|
templateField
|
||||||
|
].value === ""
|
||||||
? ""
|
? ""
|
||||||
: t.data.node.template[n]
|
: node.data.node.template[
|
||||||
.value
|
templateField
|
||||||
|
].value
|
||||||
}
|
}
|
||||||
onChange={(k) => {
|
onChange={(target) => {
|
||||||
setData((old) => {
|
setData((old) => {
|
||||||
let newInputList =
|
let newInputList =
|
||||||
cloneDeep(old);
|
cloneDeep(old);
|
||||||
newInputList[
|
newInputList[
|
||||||
index
|
index
|
||||||
].data.node.template[
|
].data.node.template[
|
||||||
n
|
templateField
|
||||||
].value = k;
|
].value = target;
|
||||||
return newInputList;
|
return newInputList;
|
||||||
});
|
});
|
||||||
tweaks.buildTweakObject(
|
tweaks.buildTweakObject(
|
||||||
t["data"]["id"],
|
node["data"]["id"],
|
||||||
k,
|
target,
|
||||||
t.data.node.template[n]
|
node.data.node.template[
|
||||||
|
templateField
|
||||||
|
]
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
) : t.data.node.template[n].type ===
|
) : node.data.node.template[
|
||||||
"str" &&
|
templateField
|
||||||
t.data.node.template[n]
|
].type === "str" &&
|
||||||
.options ? (
|
node.data.node.template[
|
||||||
|
templateField
|
||||||
|
].options ? (
|
||||||
<div className="mx-auto">
|
<div className="mx-auto">
|
||||||
<Dropdown
|
<Dropdown
|
||||||
editNode={true}
|
editNode={true}
|
||||||
apiModal={true}
|
apiModal={true}
|
||||||
options={
|
options={
|
||||||
t.data.node.template[n]
|
node.data.node.template[
|
||||||
.options
|
templateField
|
||||||
|
].options
|
||||||
}
|
}
|
||||||
onSelect={(k) => {
|
onSelect={(target) => {
|
||||||
setData((old) => {
|
setData((old) => {
|
||||||
let newInputList =
|
let newInputList =
|
||||||
cloneDeep(old);
|
cloneDeep(old);
|
||||||
newInputList[
|
newInputList[
|
||||||
index
|
index
|
||||||
].data.node.template[
|
].data.node.template[
|
||||||
n
|
templateField
|
||||||
].value = k;
|
].value = target;
|
||||||
return newInputList;
|
return newInputList;
|
||||||
});
|
});
|
||||||
tweaks.buildTweakObject(
|
tweaks.buildTweakObject(
|
||||||
t["data"]["id"],
|
node["data"]["id"],
|
||||||
k,
|
target,
|
||||||
t.data.node.template[n]
|
node.data.node.template[
|
||||||
|
templateField
|
||||||
|
]
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
value={
|
value={
|
||||||
!t.data.node.template[n]
|
!node.data.node.template[
|
||||||
.value ||
|
templateField
|
||||||
t.data.node.template[n]
|
].value ||
|
||||||
.value === ""
|
node.data.node.template[
|
||||||
|
templateField
|
||||||
|
].value === ""
|
||||||
? ""
|
? ""
|
||||||
: t.data.node.template[n]
|
: node.data.node.template[
|
||||||
.value
|
templateField
|
||||||
|
].value
|
||||||
}
|
}
|
||||||
></Dropdown>
|
></Dropdown>
|
||||||
</div>
|
</div>
|
||||||
) : t.data.node.template[n].type ===
|
) : node.data.node.template[
|
||||||
"int" ? (
|
templateField
|
||||||
|
].type === "int" ? (
|
||||||
<div className="mx-auto">
|
<div className="mx-auto">
|
||||||
<IntComponent
|
<IntComponent
|
||||||
disabled={false}
|
disabled={false}
|
||||||
editNode={true}
|
editNode={true}
|
||||||
value={
|
value={
|
||||||
!t.data.node.template[n]
|
!node.data.node.template[
|
||||||
.value ||
|
templateField
|
||||||
t.data.node.template[n]
|
].value ||
|
||||||
.value === ""
|
node.data.node.template[
|
||||||
|
templateField
|
||||||
|
].value === ""
|
||||||
? ""
|
? ""
|
||||||
: t.data.node.template[n]
|
: node.data.node.template[
|
||||||
.value
|
templateField
|
||||||
|
].value
|
||||||
}
|
}
|
||||||
onChange={(k) => {
|
onChange={(target) => {
|
||||||
setData((old) => {
|
setData((old) => {
|
||||||
let newInputList =
|
let newInputList =
|
||||||
cloneDeep(old);
|
cloneDeep(old);
|
||||||
newInputList[
|
newInputList[
|
||||||
index
|
index
|
||||||
].data.node.template[
|
].data.node.template[
|
||||||
n
|
templateField
|
||||||
].value = k;
|
].value = target;
|
||||||
return newInputList;
|
return newInputList;
|
||||||
});
|
});
|
||||||
tweaks.buildTweakObject(
|
tweaks.buildTweakObject(
|
||||||
t["data"]["id"],
|
node["data"]["id"],
|
||||||
k,
|
target,
|
||||||
t.data.node.template[n]
|
node.data.node.template[
|
||||||
|
templateField
|
||||||
|
]
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
) : t.data.node.template[n].type ===
|
) : node.data.node.template[
|
||||||
"prompt" ? (
|
templateField
|
||||||
|
].type === "prompt" ? (
|
||||||
<ShadTooltip
|
<ShadTooltip
|
||||||
content={tweaks.buildContent(
|
content={tweaks.buildContent(
|
||||||
!t.data.node.template[n]
|
!node.data.node.template[
|
||||||
.value ||
|
templateField
|
||||||
t.data.node.template[n]
|
].value ||
|
||||||
.value === ""
|
node.data.node.template[
|
||||||
|
templateField
|
||||||
|
].value === ""
|
||||||
? ""
|
? ""
|
||||||
: t.data.node.template[n]
|
: node.data.node.template[
|
||||||
.value
|
templateField
|
||||||
|
].value
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className="mx-auto">
|
<div className="mx-auto">
|
||||||
|
|
@ -571,44 +635,53 @@ export default function CodeTabsComponent({
|
||||||
editNode={true}
|
editNode={true}
|
||||||
disabled={false}
|
disabled={false}
|
||||||
value={
|
value={
|
||||||
!t.data.node.template[n]
|
!node.data.node.template[
|
||||||
.value ||
|
templateField
|
||||||
t.data.node.template[n]
|
].value ||
|
||||||
.value === ""
|
node.data.node.template[
|
||||||
|
templateField
|
||||||
|
].value === ""
|
||||||
? ""
|
? ""
|
||||||
: t.data.node.template[
|
: node.data.node
|
||||||
n
|
.template[
|
||||||
|
templateField
|
||||||
].value
|
].value
|
||||||
}
|
}
|
||||||
onChange={(k) => {
|
onChange={(target) => {
|
||||||
setData((old) => {
|
setData((old) => {
|
||||||
let newInputList =
|
let newInputList =
|
||||||
cloneDeep(old);
|
cloneDeep(old);
|
||||||
newInputList[
|
newInputList[
|
||||||
index
|
index
|
||||||
].data.node.template[
|
].data.node.template[
|
||||||
n
|
templateField
|
||||||
].value = k;
|
].value = target;
|
||||||
return newInputList;
|
return newInputList;
|
||||||
});
|
});
|
||||||
tweaks.buildTweakObject(
|
tweaks.buildTweakObject(
|
||||||
t["data"]["id"],
|
node["data"]["id"],
|
||||||
k,
|
target,
|
||||||
t.data.node.template[n]
|
node.data.node.template[
|
||||||
|
templateField
|
||||||
|
]
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</ShadTooltip>
|
</ShadTooltip>
|
||||||
) : t.data.node.template[n].type ===
|
) : node.data.node.template[
|
||||||
"code" ? (
|
templateField
|
||||||
|
].type === "code" ? (
|
||||||
<ShadTooltip
|
<ShadTooltip
|
||||||
content={tweaks.buildContent(
|
content={tweaks.buildContent(
|
||||||
tweaks.getValue(
|
tweaks.getValue(
|
||||||
t.data.node.template[n]
|
node.data.node.template[
|
||||||
.value,
|
templateField
|
||||||
t.data,
|
].value,
|
||||||
t.data.node.template[n]
|
node.data,
|
||||||
|
node.data.node.template[
|
||||||
|
templateField
|
||||||
|
]
|
||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
|
|
@ -617,37 +690,43 @@ export default function CodeTabsComponent({
|
||||||
disabled={false}
|
disabled={false}
|
||||||
editNode={true}
|
editNode={true}
|
||||||
value={
|
value={
|
||||||
!t.data.node.template[n]
|
!node.data.node.template[
|
||||||
.value ||
|
templateField
|
||||||
t.data.node.template[n]
|
].value ||
|
||||||
.value === ""
|
node.data.node.template[
|
||||||
|
templateField
|
||||||
|
].value === ""
|
||||||
? ""
|
? ""
|
||||||
: t.data.node.template[
|
: node.data.node
|
||||||
n
|
.template[
|
||||||
|
templateField
|
||||||
].value
|
].value
|
||||||
}
|
}
|
||||||
onChange={(k) => {
|
onChange={(target) => {
|
||||||
setData((old) => {
|
setData((old) => {
|
||||||
let newInputList =
|
let newInputList =
|
||||||
cloneDeep(old);
|
cloneDeep(old);
|
||||||
newInputList[
|
newInputList[
|
||||||
index
|
index
|
||||||
].data.node.template[
|
].data.node.template[
|
||||||
n
|
templateField
|
||||||
].value = k;
|
].value = target;
|
||||||
return newInputList;
|
return newInputList;
|
||||||
});
|
});
|
||||||
tweaks.buildTweakObject(
|
tweaks.buildTweakObject(
|
||||||
t["data"]["id"],
|
node["data"]["id"],
|
||||||
k,
|
target,
|
||||||
t.data.node.template[n]
|
node.data.node.template[
|
||||||
|
templateField
|
||||||
|
]
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</ShadTooltip>
|
</ShadTooltip>
|
||||||
) : t.data.node.template[n].type ===
|
) : node.data.node.template[
|
||||||
"Any" ? (
|
templateField
|
||||||
|
].type === "Any" ? (
|
||||||
"-"
|
"-"
|
||||||
) : (
|
) : (
|
||||||
<div className="hidden"></div>
|
<div className="hidden"></div>
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,12 @@ export default function FloatComponent({
|
||||||
type="number"
|
type="number"
|
||||||
step={step}
|
step={step}
|
||||||
min={min}
|
min={min}
|
||||||
onInput={(e: React.ChangeEvent<HTMLInputElement>) => {
|
onInput={(event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
if (e.target.value < min.toString()) {
|
if (event.target.value < min.toString()) {
|
||||||
e.target.value = min.toString();
|
event.target.value = min.toString();
|
||||||
}
|
}
|
||||||
if (e.target.value > max.toString()) {
|
if (event.target.value > max.toString()) {
|
||||||
e.target.value = max.toString();
|
event.target.value = max.toString();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
max={max}
|
max={max}
|
||||||
|
|
@ -40,8 +40,8 @@ export default function FloatComponent({
|
||||||
placeholder={
|
placeholder={
|
||||||
editNode ? "Number 0 to 1" : "Type a number from zero to one"
|
editNode ? "Number 0 to 1" : "Type a number from zero to one"
|
||||||
}
|
}
|
||||||
onChange={(e) => {
|
onChange={(event) => {
|
||||||
onChange(e.target.value);
|
onChange(event.target.value);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue