refac: langflow_backend -> langflow
This commit is contained in:
parent
aa8e1aee8a
commit
70dbc7eb1e
104 changed files with 174 additions and 50 deletions
|
|
@ -63,7 +63,7 @@ make run_backend
|
|||
```
|
||||
For the frontend, you will need to install the dependencies and start the development server.
|
||||
```bash
|
||||
cd langflow/frontend
|
||||
cd src/frontend
|
||||
npm install
|
||||
npm start
|
||||
```
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ COPY pyproject.toml ./
|
|||
COPY ./langflow ./langflow
|
||||
|
||||
# Copy files from frontend
|
||||
COPY --from=frontend_build /app/build /app/langflow/frontend/build/
|
||||
COPY --from=frontend_build /app/build /app/src/frontend/build/
|
||||
|
||||
RUN pip install .
|
||||
|
||||
|
|
|
|||
12
Makefile
12
Makefile
|
|
@ -21,23 +21,23 @@ lint:
|
|||
poetry run ruff . --fix
|
||||
|
||||
install_frontend:
|
||||
cd langflow/frontend && npm install
|
||||
cd src/frontend && npm install
|
||||
|
||||
run_frontend:
|
||||
cd langflow/frontend && npm start
|
||||
cd src/frontend && npm start
|
||||
|
||||
run_backend:
|
||||
poetry run uvicorn langflow_backend.main:app --port 5003 --reload
|
||||
poetry run uvicorn langflow.main:app --port 5003 --reload
|
||||
|
||||
build_frontend:
|
||||
cd langflow/frontend && CI='' npm run build
|
||||
cd src/frontend && CI='' npm run build
|
||||
cp -r src/frontend/build src/backend/langflow/frontend
|
||||
|
||||
build:
|
||||
make install_frontend
|
||||
make build_frontend
|
||||
cp -r langflow/frontend/build langflow/backend/langflow_backend/frontend
|
||||
poetry build --format sdist
|
||||
rm -rf langflow/backend/langflow_backend/frontend
|
||||
rm -rf src/backend/langflow/frontend
|
||||
|
||||
publish:
|
||||
make build
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#! /bin/bash
|
||||
|
||||
cd langflow/frontend
|
||||
cd src/frontend
|
||||
docker build -t logspace/frontend_build -f build.Dockerfile .
|
||||
cd ../backend
|
||||
docker build -t logspace/backend_build -f build.Dockerfile .
|
||||
|
|
|
|||
|
|
@ -15,4 +15,4 @@ COPY ./ ./
|
|||
# Install dependencies
|
||||
RUN poetry config virtualenvs.create false && poetry install --no-interaction --no-ansi
|
||||
|
||||
CMD ["uvicorn", "langflow_backend.main:app", "--host", "0.0.0.0", "--port", "5003", "--reload"]
|
||||
CMD ["uvicorn", "langflow.main:app", "--host", "0.0.0.0", "--port", "5003", "--reload"]
|
||||
|
|
@ -9,16 +9,16 @@ services:
|
|||
- "5003:5003"
|
||||
volumes:
|
||||
- ./:/app
|
||||
command: bash -c "uvicorn langflow_backend.main:app --host 0.0.0.0 --port 5003 --reload"
|
||||
command: bash -c "uvicorn langflow.main:app --host 0.0.0.0 --port 5003 --reload"
|
||||
|
||||
frontend:
|
||||
build:
|
||||
context: ./langflow/frontend
|
||||
context: ./src/frontend
|
||||
dockerfile: ./dev.Dockerfile
|
||||
ports:
|
||||
- "3000:3000"
|
||||
volumes:
|
||||
- ./langflow/frontend:/app
|
||||
- ./src/frontend:/app
|
||||
# Set process.env.BACKEND to the backend service
|
||||
environment:
|
||||
- BACKEND="http://backend:5003"
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
from langflow_backend.interface.loading import load_flow_from_json # noqa
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
FROM node:14-alpine as frontend_build
|
||||
ARG BACKEND
|
||||
WORKDIR /app
|
||||
COPY . /app
|
||||
RUN npm install
|
||||
CMD ["npm", "start"]
|
||||
|
|
@ -4,14 +4,14 @@ version = "0.0.33"
|
|||
description = "A Python package with a built-in web application"
|
||||
authors = ["Logspace <contact@logspace.ai>"]
|
||||
packages = [
|
||||
{ include = "langflow_backend", from = "langflow/backend" },
|
||||
{ include = "langflow", from = "src/backend" },
|
||||
]
|
||||
include = ["langflow/backend/langflow_backend/*", "langflow/backend/langflow_backend/**/*"]
|
||||
include = ["src/backend/langflow/*", "src/backend/langflow/**/*"]
|
||||
license = "MIT"
|
||||
readme = "README.md"
|
||||
|
||||
[tool.poetry.scripts]
|
||||
langflow = "langflow_backend.__main__:main"
|
||||
langflow = "langflow.__main__:main"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.9"
|
||||
|
|
|
|||
133
src/backend/.gitignore
vendored
Normal file
133
src/backend/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
notebooks
|
||||
|
||||
# frontend
|
||||
src/frontend
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
pip-wheel-metadata/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
.python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
14
src/backend/Dockerfile
Normal file
14
src/backend/Dockerfile
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
FROM logspace/backend_build as backend_build
|
||||
|
||||
FROM python:3.10-slim
|
||||
WORKDIR /app
|
||||
|
||||
RUN apt-get update && apt-get install git -y
|
||||
|
||||
COPY --from=backend_build /app/dist/*.whl /app/
|
||||
RUN pip install langflow-*.whl
|
||||
RUN rm *.whl
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
CMD [ "uvicorn", "--host", "0.0.0.0", "--port", "80", "langflow.backend.app:app" ]
|
||||
52
src/backend/build.Dockerfile
Normal file
52
src/backend/build.Dockerfile
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
# `python-base` sets up all our shared environment variables
|
||||
FROM python:3.10-slim
|
||||
|
||||
# python
|
||||
ENV PYTHONUNBUFFERED=1 \
|
||||
# prevents python creating .pyc files
|
||||
PYTHONDONTWRITEBYTECODE=1 \
|
||||
\
|
||||
# pip
|
||||
PIP_NO_CACHE_DIR=off \
|
||||
PIP_DISABLE_PIP_VERSION_CHECK=on \
|
||||
PIP_DEFAULT_TIMEOUT=100 \
|
||||
\
|
||||
# poetry
|
||||
# https://python-poetry.org/docs/configuration/#using-environment-variables
|
||||
POETRY_VERSION=1.4.0 \
|
||||
# make poetry install to this location
|
||||
POETRY_HOME="/opt/poetry" \
|
||||
# make poetry create the virtual environment in the project's root
|
||||
# it gets named `.venv`
|
||||
POETRY_VIRTUALENVS_IN_PROJECT=true \
|
||||
# do not ask any interactive question
|
||||
POETRY_NO_INTERACTION=1 \
|
||||
\
|
||||
# paths
|
||||
# this is where our requirements + virtual environment will live
|
||||
PYSETUP_PATH="/opt/pysetup" \
|
||||
VENV_PATH="/opt/pysetup/.venv"
|
||||
|
||||
# prepend poetry and venv to path
|
||||
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install --no-install-recommends -y \
|
||||
# deps for installing poetry
|
||||
curl \
|
||||
# deps for building python deps
|
||||
build-essential libpq-dev
|
||||
|
||||
# install poetry - respects $POETRY_VERSION & $POETRY_HOME
|
||||
RUN curl -sSL https://install.python-poetry.org | python3 -
|
||||
|
||||
# copy project requirement files here to ensure they will be cached.
|
||||
WORKDIR /app
|
||||
COPY poetry.lock pyproject.toml ./
|
||||
COPY langflow/ ./langflow
|
||||
|
||||
# poetry install
|
||||
RUN poetry install --without dev
|
||||
|
||||
# build wheel
|
||||
RUN poetry build -f wheel
|
||||
6
src/backend/build_and_push
Executable file
6
src/backend/build_and_push
Executable file
|
|
@ -0,0 +1,6 @@
|
|||
#! /bin/bash
|
||||
|
||||
docker build -t logspace/backend_build -f build.Dockerfile .
|
||||
VERSION=$(toml get --toml-path pyproject.toml tool.poetry.version)
|
||||
docker build --build-arg VERSION=$VERSION -t ibiscp/langflow:$VERSION .
|
||||
docker push ibiscp/langflow:$VERSION
|
||||
1
src/backend/langflow/__init__.py
Normal file
1
src/backend/langflow/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from langflow.interface.loading import load_flow_from_json # noqa
|
||||
57
src/backend/langflow/__main__.py
Normal file
57
src/backend/langflow/__main__.py
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import multiprocessing
|
||||
import platform
|
||||
|
||||
from langflow.main import create_app
|
||||
|
||||
import typer
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def get_number_of_workers(workers=None):
|
||||
if workers == -1:
|
||||
workers = (multiprocessing.cpu_count() * 2) + 1
|
||||
return workers
|
||||
|
||||
|
||||
def serve(
|
||||
host: str = "127.0.0.1",
|
||||
workers: int = 1,
|
||||
timeout: int = 60,
|
||||
):
|
||||
app = create_app()
|
||||
# get the directory of the current file
|
||||
path = Path(__file__).parent
|
||||
static_files_dir = path / "frontend"
|
||||
app.mount(
|
||||
"/",
|
||||
StaticFiles(directory=static_files_dir, html=True),
|
||||
name="static",
|
||||
)
|
||||
port = 5003
|
||||
options = {
|
||||
"bind": f"{host}:{port}",
|
||||
"workers": get_number_of_workers(workers),
|
||||
"worker_class": "uvicorn.workers.UvicornWorker",
|
||||
"timeout": timeout,
|
||||
}
|
||||
|
||||
if platform.system() in ["Darwin", "Windows"]:
|
||||
# Run using uvicorn on MacOS and Windows
|
||||
# Windows doesn't support gunicorn
|
||||
# MacOS requires a env variable to be set to use gunicorn
|
||||
import uvicorn
|
||||
|
||||
uvicorn.run(app, host=host, port=port, log_level="info")
|
||||
else:
|
||||
from langflow.server import LangflowApplication
|
||||
|
||||
LangflowApplication(app, options).run()
|
||||
|
||||
|
||||
def main():
|
||||
typer.run(serve)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
0
src/backend/langflow/api/__init__.py
Normal file
0
src/backend/langflow/api/__init__.py
Normal file
21
src/backend/langflow/api/endpoints.py
Normal file
21
src/backend/langflow/api/endpoints.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
from fastapi import APIRouter, HTTPException
|
||||
from langflow.interface.types import build_langchain_types_dict
|
||||
from langflow.interface.run import process_data_graph
|
||||
from typing import Any, Dict
|
||||
|
||||
|
||||
# build router
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/all")
|
||||
def get_all():
|
||||
return build_langchain_types_dict()
|
||||
|
||||
|
||||
@router.post("/predict")
|
||||
def get_load(data: Dict[str, Any]):
|
||||
try:
|
||||
return process_data_graph(data)
|
||||
except Exception as e:
|
||||
return HTTPException(status_code=500, detail=str(e))
|
||||
58
src/backend/langflow/api/list_endpoints.py
Normal file
58
src/backend/langflow/api/list_endpoints.py
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
from fastapi import APIRouter
|
||||
|
||||
from langflow.interface.listing import list_type
|
||||
|
||||
# build router
|
||||
router = APIRouter(
|
||||
prefix="/list",
|
||||
tags=["list"],
|
||||
)
|
||||
|
||||
|
||||
@router.get("/")
|
||||
def read_items():
|
||||
"""List all components"""
|
||||
return [
|
||||
"chains",
|
||||
"agents",
|
||||
"prompts",
|
||||
"llms",
|
||||
"tools",
|
||||
]
|
||||
|
||||
|
||||
@router.get("/chains")
|
||||
def list_chains():
|
||||
"""List all chain types"""
|
||||
return list_type("chains")
|
||||
|
||||
|
||||
@router.get("/agents")
|
||||
def list_agents():
|
||||
"""List all agent types"""
|
||||
# return list(agents.loading.AGENT_TO_CLASS.keys())
|
||||
return list_type("agents")
|
||||
|
||||
|
||||
@router.get("/prompts")
|
||||
def list_prompts():
|
||||
"""List all prompt types"""
|
||||
return list_type("prompts")
|
||||
|
||||
|
||||
@router.get("/llms")
|
||||
def list_llms():
|
||||
"""List all llm types"""
|
||||
return list_type("llms")
|
||||
|
||||
|
||||
@router.get("/memories")
|
||||
def list_memories():
|
||||
"""List all memory types"""
|
||||
return list_type("memories")
|
||||
|
||||
|
||||
@router.get("/tools")
|
||||
def list_tools():
|
||||
"""List all load tools"""
|
||||
return list_type("tools")
|
||||
63
src/backend/langflow/api/signature.py
Normal file
63
src/backend/langflow/api/signature.py
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
from langflow.interface.signature import get_signature
|
||||
|
||||
# build router
|
||||
router = APIRouter(
|
||||
prefix="/signatures",
|
||||
tags=["signatures"],
|
||||
)
|
||||
|
||||
|
||||
@router.get("/chain")
|
||||
def get_chain(name: str):
|
||||
"""Get the signature of a chain."""
|
||||
try:
|
||||
return get_signature(name, "chains")
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=404, detail="Chain not found") from exc
|
||||
|
||||
|
||||
@router.get("/agent")
|
||||
def get_agent(name: str):
|
||||
"""Get the signature of an agent."""
|
||||
try:
|
||||
return get_signature(name, "agents")
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=404, detail="Agent not found") from exc
|
||||
|
||||
|
||||
@router.get("/prompt")
|
||||
def get_prompt(name: str):
|
||||
"""Get the signature of a prompt."""
|
||||
try:
|
||||
return get_signature(name, "prompts")
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=404, detail="Prompt not found") from exc
|
||||
|
||||
|
||||
@router.get("/llm")
|
||||
def get_llm(name: str):
|
||||
"""Get the signature of an llm."""
|
||||
try:
|
||||
return get_signature(name, "llms")
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=404, detail="LLM not found") from exc
|
||||
|
||||
|
||||
@router.get("/memory")
|
||||
def get_memory(name: str):
|
||||
"""Get the signature of a memory."""
|
||||
try:
|
||||
return get_signature(name, "memories")
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=404, detail="Memory not found") from exc
|
||||
|
||||
|
||||
@router.get("/tool")
|
||||
def get_tool(name: str):
|
||||
"""Get the signature of a tool."""
|
||||
try:
|
||||
return get_signature(name, "tools")
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=404, detail="Tool not found") from exc
|
||||
0
src/backend/langflow/custom/__init__.py
Normal file
0
src/backend/langflow/custom/__init__.py
Normal file
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue