Merge pull request #10 from logspace-ai/dev

Use uvicorn on macOS to avoid making the user set env variable
This commit is contained in:
Ibis Prevedello 2023-03-14 11:11:58 -03:00 • committed by GitHub
commit feb83ffe46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 2218 additions and 3466 deletions

7
.gitignore vendored
View file

@ -6,6 +6,9 @@ yarn-debug.log*
yarn-error.log* yarn-error.log*
lerna-debug.log* lerna-debug.log*
# Mac
.DS_Store
# Diagnostic reports (https://nodejs.org/api/report.html) # Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
@ -230,5 +233,5 @@ venv.bak/
.dmypy.json .dmypy.json
dmypy.json dmypy.json
# Pyre type checker # Poetry
.pyre/ .testenv/*

View file

@ -18,7 +18,7 @@ format:
lint: lint:
poetry run mypy . poetry run mypy .
poetry run black . --check poetry run black . --check
poetry run ruff . poetry run ruff . --fix
install_frontend: install_frontend:
cd langflow/frontend && npm install cd langflow/frontend && npm install
@ -29,7 +29,13 @@ build_frontend:
build: build:
make install_frontend make install_frontend
make build_frontend make build_frontend
cp -r langflow/frontend/build langflow/backend/langflow_backend/frontend
poetry build --format sdist poetry build --format sdist
rm -rf langflow/backend/langflow_backend/frontend
publish:
make build
poetry publish
help: help:
@echo '----' @echo '----'

View file

@ -4,21 +4,17 @@
~ A User Interface For [LangChain](https://github.com/hwchase17/langchain) ~ ~ A User Interface For [LangChain](https://github.com/hwchase17/langchain) ~
<p> <p>
<img alt="GitHub Contributors" src="https://img.shields.io/github/contributors/logspace-ai/langflow" /> <img alt="GitHub Contributors" src="https://img.shields.io/github/contributors/logspace-ai/langflow" />
<img alt="GitHub Last Commit" src="https://img.shields.io/github/last-commit/logspace-ai/langflow" /> <img alt="GitHub Last Commit" src="https://img.shields.io/github/last-commit/logspace-ai/langflow" />
<!-- <img alt="GitHub Language Count" src="https://img.shields.io/github/languages/count/logspace-ai/langflow" /> -->
<img alt="" src="https://img.shields.io/github/repo-size/logspace-ai/langflow" /> <img alt="" src="https://img.shields.io/github/repo-size/logspace-ai/langflow" />
<!-- <img alt="GitHub Issues" src="https://img.shields.io/github/issues/logspace-ai/langflow" /> --> <img alt="GitHub Issues" src="https://img.shields.io/github/issues/logspace-ai/langflow" />
<!-- <img alt="GitHub Closed Issues" src="https://img.shields.io/github/issues-closed/logspace-ai/langflow" /> --> <img alt="GitHub Pull Requests" src="https://img.shields.io/github/issues-pr/logspace-ai/langflow" />
<!-- <img alt="GitHub Pull Requests" src="https://img.shields.io/github/issues-pr/logspace-ai/langflow" /> -->
<!-- <img alt="GitHub Closed Pull Requests" src="https://img.shields.io/github/issues-pr-closed/logspace-ai/langflow" /> -->
<!-- <img alt="GitHub Commit Activity (Year)" src="https://img.shields.io/github/commit-activity/y/logspace-ai/langflow" /> -->
<img alt="Github License" src="https://img.shields.io/github/license/logspace-ai/langflow" /> <img alt="Github License" src="https://img.shields.io/github/license/logspace-ai/langflow" />
</p> </p>
![LangFlow Logo](https://github.com/logspace-ai/langflow/blob/main/img/langflow-demo.gif) <a href="https://github.com/logspace-ai/langflow">
<img width="100%" src="https://github.com/logspace-ai/langflow/blob/main/img/langflow-demo.gif?raw=true"></a>
LangFlow is a GUI for [LangChain](https://github.com/hwchase17/langchain), designed with [react-flow](https://github.com/wbkd/react-flow) to provide an effortless way to experiment and prototype flows with drag-and-drop components and a chat box. LangFlow is a GUI for [LangChain](https://github.com/hwchase17/langchain), designed with [react-flow](https://github.com/wbkd/react-flow) to provide an effortless way to experiment and prototype flows with drag-and-drop components and a chat box.
@ -32,18 +28,16 @@ Next, run:
`python -m langflow` or just `langflow` `python -m langflow` or just `langflow`
## 🎨 Creating Flows ## 🎨 Creating Flows
Creating flows with LangFlow is easy. Simply drag sidebar components onto the canvas and connect them together to create your pipeline. LangFlow provides a range of [LangChain components](https://langchain.readthedocs.io/en/latest/reference.html) to choose from, including LLMs, prompt serializers, agents, and chains. Creating flows with LangFlow is easy. Simply drag sidebar components onto the canvas and connect them together to create your pipeline. LangFlow provides a range of [LangChain components](https://langchain.readthedocs.io/en/latest/reference.html) to choose from, including LLMs, prompt serializers, agents, and chains.
Explore by editing prompt parameters, link chains and agents, track an agent's thought process, and export your flow. Explore by editing prompt parameters, link chains and agents, track an agent's thought process, and export your flow.
## 👋 Contributing ## 👋 Contributing
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 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 and help make LangFlow more accessible.
## 📄 License ## 📄 License

View file

@ -1 +0,0 @@
from langflow_backend.interface.loading import load_flow_from_json

View file

@ -4,6 +4,9 @@ __pycache__/
*$py.class *$py.class
notebooks notebooks
# frontend
langflow_backend/frontend
# C extensions # C extensions
*.so *.so

View file

@ -0,0 +1 @@
from langflow_backend.interface.loading import load_flow_from_json # noqa

View file

@ -1,42 +1,51 @@
import multiprocessing import multiprocessing
import platform
from langflow_backend.main import create_app from langflow_backend.main import create_app
import typer import typer
from fastapi.staticfiles import StaticFiles from fastapi.staticfiles import StaticFiles
from pathlib import Path from pathlib import Path
from langflow.server import LangflowApplication
def get_number_of_workers(workers=None):
if workers == -1:
workers = (multiprocessing.cpu_count() * 2) + 1
return workers
def serve( def serve(
workers: int = None, workers: int = 1,
timeout: int = None, timeout: int = 60,
): ):
app = create_app() app = create_app()
# get the directory of the current file # get the directory of the current file
path = Path(__file__).parent path = Path(__file__).parent
static_files_dir = path / "frontend/build" static_files_dir = path / "frontend"
app.mount( app.mount(
"/", "/",
StaticFiles(directory=static_files_dir, html=True), StaticFiles(directory=static_files_dir, html=True),
name="static", name="static",
) )
if not workers:
workers = 1
elif workers == -1:
workers = (multiprocessing.cpu_count() * 2) + 1
if not timeout:
timeout = 60
host = "127.0.0.1"
port = 5003
options = { options = {
"bind": "0.0.0.0:5003", "bind": f"{host}:{port}",
"workers": workers, "workers": get_number_of_workers(workers),
"worker_class": "uvicorn.workers.UvicornWorker", "worker_class": "uvicorn.workers.UvicornWorker",
"timeout": timeout, "timeout": timeout,
} }
LangflowApplication(app, options).run() if platform.system() == "Darwin":
# Run using uvicorn on MacOS
import uvicorn
uvicorn.run(app, host=host, port=port, log_level="info")
else:
from langflow_backend.server import LangflowApplication
LangflowApplication(app, options).run()
def main(): def main():

View file

@ -120,7 +120,7 @@ def get_tool_signature(name: str):
template["aiosession"]["required"] = False template["aiosession"]["required"] = False
template["aiosession"]["show"] = False template["aiosession"]["show"] = False
template["_type"] = tool_type template["_type"] = tool_type # type: ignore
return { return {
"template": template, "template": template,

View file

@ -33,4 +33,4 @@ app = create_app()
if __name__ == "__main__": if __name__ == "__main__":
import uvicorn import uvicorn
uvicorn.run(app, host="0.0.0.0", port=5003) uvicorn.run(app, host="127.0.0.1", port=5003)

View file

@ -1,4 +1,4 @@
from gunicorn.app.base import BaseApplication from gunicorn.app.base import BaseApplication # type: ignore
class LangflowApplication(BaseApplication): class LangflowApplication(BaseApplication):

File diff suppressed because it is too large Load diff

View file

@ -1,28 +0,0 @@
[tool.poetry]
name = "langflow-backend"
version = "0.0.22"
description = "Backend for Langflow"
authors = ["Ibis Prevedello <ibiscp@gmail.com>", "Gabriel Almeida <gabrielf.almeida90@gmail.com>"]
packages = [
{ include = "langflow_backend" },
]
[tool.poetry.dependencies]
python = "^3.9"
openai = "^0.26.5"
fastapi = "^0.91.0"
uvicorn = "^0.20.0"
beautifulsoup4 = "^4.11.2"
google-search-results = "^2.4.1"
google-api-python-client = "^2.79.0"
langchain = {git = "https://github.com/ibiscp/langchain.git", rev = "ibis"}
[tool.poetry.group.dev.dependencies]
black = "^23.1.0"
ipykernel = "^6.21.2"
mypy = "^1.1.1"
ruff = "^0.0.254"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

3173
poetry.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,31 +1,39 @@
[tool.poetry] [tool.poetry]
name = "langflow" name = "langflow"
version = "0.0.1" version = "0.0.27"
description = "A Python package with a built-in web application" description = "A Python package with a built-in web application"
authors = ["Ibis Prevedello <ibiscp@gmail.com>", "Gabriel Almeida <gabrielf.almeida90@gmail.com>","Otávio Anovazzi <otavio2204@gmail.com>"] authors = ["Ibis Prevedello <ibiscp@gmail.com>",
"Gabriel Almeida <gabrielf.almeida90@gmail.com>",
"Otávio Anovazzi <otavio2204@gmail.com>",
"Lucas Eduoli <lucaseduoli@gmail.com"]
packages = [ packages = [
{ include = "langflow"}, { include = "langflow_backend", from = "langflow/backend" },
] ]
include = ["langflow/frontend/build/*", "langflow/frontend/build/**/*"] include = ["langflow/backend/langflow_backend/*", "langflow/backend/langflow_backend/**/*"]
exclude = ["langflow/frontend/node_modules/*", "langflow/frontend/src/*"] license = "MIT"
readme = "README.md"
[tool.poetry.scripts] [tool.poetry.scripts]
langflow = "langflow.__main__:main" langflow = "langflow_backend.__main__:main"
[tool.poetry.group.dev.dependencies]
ruff = "^0.0.254"
black = "^23.1.0"
mypy = "^1.1.1"
pytest = "^7.2.2"
pytest-cov = "^4.0.0"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = "^3.9" python = "^3.9"
openai = "^0.26.5"
fastapi = "^0.91.0"
uvicorn = "^0.20.0"
beautifulsoup4 = "^4.11.2"
google-search-results = "^2.4.1"
google-api-python-client = "^2.79.0"
langchain_ibis = "0.0.100"
typer = "^0.7.0" typer = "^0.7.0"
gunicorn = "^20.1.0" gunicorn = "^20.1.0"
langflow_backend = {path = "langflow/backend"}
[tool.poetry.group.dev.dependencies]
black = "^23.1.0"
ipykernel = "^6.21.2"
mypy = "^1.1.1"
ruff = "^0.0.254"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

View file

@ -1,5 +1,5 @@
from pathlib import Path from pathlib import Path
from langflow import load_flow_from_json from langflow_backend import load_flow_from_json
def test_load_flow_from_json(): def test_load_flow_from_json():