Improve Makefile: color output, clean commands, dependency checks (#2672)

* feat: Add Gemma 2 to Groq model list (#2586)

Add gemma2 to groq_constants.py

* Improve Makefile: color output, clean commands, dependency checks

- Add colored output to 'make help' for various shells.
- Add 'clean_all', 'clean_python_cache', and 'clean_npm_cache' commands.
- Check for installed tools: 'poetry', 'docker', 'pipx', and 'npm'.

* Added success message at the end of the check_tools target to indicate all required tools are installed.
This commit is contained in:
Daniel Gines 2024-07-16 06:56:05 -03:00 • committed by GitHub
commit e56a1c1e10
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 42 additions and 61 deletions

101
Makefile
View file

@ -1,6 +1,6 @@
.PHONY: all init format lint build build_frontend install_frontend run_frontend run_backend dev help tests coverage .PHONY: all init format lint build build_frontend install_frontend run_frontend run_backend dev help tests coverage clean_python_cache clean_npm_cache clean_all
all: help # Configurations
VERSION=$(shell grep "^version" pyproject.toml | sed 's/.*\"\(.*\)\"$$/\1/') VERSION=$(shell grep "^version" pyproject.toml | sed 's/.*\"\(.*\)\"$$/\1/')
DOCKERFILE=docker/build_and_push.Dockerfile DOCKERFILE=docker/build_and_push.Dockerfile
DOCKERFILE_BACKEND=docker/build_and_push_backend.Dockerfile DOCKERFILE_BACKEND=docker/build_and_push_backend.Dockerfile
@ -15,21 +15,37 @@ open_browser ?= true
path = src/backend/base/langflow/frontend path = src/backend/base/langflow/frontend
workers ?= 1 workers ?= 1
all: help
clean_python_cache:
@echo 'Cleaning Python cache...'
find . -type d -name '__pycache__' -exec rm -r {} +
find . -type f -name '*.py[cod]' -exec rm -f {} +
find . -type f -name '*~' -exec rm -f {} +
find . -type f -name '.*~' -exec rm -f {} +
@echo 'Python cache cleaned.'
clean_npm_cache:
@echo 'Cleaning npm cache...'
cd src/frontend && npm cache clean --force
rm -rf src/frontend/node_modules
rm -f src/frontend/package-lock.json
@echo 'NPM cache cleaned.'
clean_all: clean_python_cache clean_npm_cache
@echo 'All caches cleaned.'
codespell: codespell:
@poetry install --with spelling @poetry install --with spelling
poetry run codespell --toml pyproject.toml poetry run codespell --toml pyproject.toml
fix_codespell: fix_codespell:
@poetry install --with spelling @poetry install --with spelling
poetry run codespell --toml pyproject.toml --write poetry run codespell --toml pyproject.toml --write
setup_poetry: setup_poetry:
pipx install poetry pipx install poetry
add: add:
@echo 'Adding dependencies' @echo 'Adding dependencies'
ifdef devel ifdef devel
@ -44,19 +60,16 @@ ifdef base
cd src/backend/base && poetry add $(base) cd src/backend/base && poetry add $(base)
endif endif
init: check_tools ## initialize the project
init:
@echo 'Installing backend dependencies' @echo 'Installing backend dependencies'
make install_backend make install_backend
@echo 'Installing frontend dependencies' @echo 'Installing frontend dependencies'
make install_frontend make install_frontend
coverage: ## run the tests and generate a coverage report coverage: ## run the tests and generate a coverage report
@poetry run coverage run @poetry run coverage run
@poetry run coverage erase @poetry run coverage erase
# allow passing arguments to pytest # allow passing arguments to pytest
unit_tests: unit_tests:
poetry run pytest \ poetry run pytest \
@ -64,7 +77,6 @@ unit_tests:
--instafail -ra -n auto -m "not api_key_required" \ --instafail -ra -n auto -m "not api_key_required" \
$(args) $(args)
integration_tests: integration_tests:
poetry run pytest tests/integration \ poetry run pytest tests/integration \
--instafail -ra -n auto \ --instafail -ra -n auto \
@ -75,36 +87,29 @@ format: ## run code formatters
poetry run ruff format . poetry run ruff format .
cd src/frontend && npm run format cd src/frontend && npm run format
lint: ## run linters lint: ## run linters
poetry run mypy --namespace-packages -p "langflow" poetry run mypy --namespace-packages -p "langflow"
install_frontend: ## install the frontend dependencies install_frontend: ## install the frontend dependencies
cd src/frontend && npm install cd src/frontend && npm install
install_frontendci: install_frontendci:
cd src/frontend && npm ci cd src/frontend && npm ci
install_frontendc: install_frontendc:
cd src/frontend && rm -rf node_modules package-lock.json && npm install cd src/frontend && rm -rf node_modules package-lock.json && npm install
run_frontend: run_frontend:
@-kill -9 `lsof -t -i:3000` @-kill -9 `lsof -t -i:3000`
cd src/frontend && npm start cd src/frontend && npm start
tests_frontend: tests_frontend:
ifeq ($(UI), true) ifeq ($(UI), true)
cd src/frontend && npx playwright test --ui --project=chromium cd src/frontend && npx playwright test --ui --project=chromium
else else
cd src/frontend && npx playwright test --project=chromium cd src/frontend && npx playwright test --project=chromium
endif endif
run_cli: run_cli:
@echo 'Running the CLI' @echo 'Running the CLI'
@make install_frontend > /dev/null @make install_frontend > /dev/null
@ -118,7 +123,6 @@ else
@make start host=$(host) port=$(port) log_level=$(log_level) @make start host=$(host) port=$(port) log_level=$(log_level)
endif endif
run_cli_debug: run_cli_debug:
@echo 'Running the CLI in debug mode' @echo 'Running the CLI in debug mode'
@make install_frontend > /dev/null @make install_frontend > /dev/null
@ -132,7 +136,6 @@ else
@make start host=$(host) port=$(port) log_level=debug @make start host=$(host) port=$(port) log_level=debug
endif endif
start: start:
@echo 'Running the CLI' @echo 'Running the CLI'
@ -153,34 +156,28 @@ else
--env-file $(env) --env-file $(env)
endif endif
setup_devcontainer: setup_devcontainer:
make init make init
make build_frontend make build_frontend
poetry run langflow --path src/frontend/build poetry run langflow --path src/frontend/build
setup_env: setup_env:
@sh ./scripts/setup/update_poetry.sh 1.8.2 @sh ./scripts/setup/update_poetry.sh 1.8.2
@sh ./scripts/setup/setup_env.sh @sh ./scripts/setup/setup_env.sh
frontend: ## run the frontend in development mode frontend: ## run the frontend in development mode
make install_frontend make install_frontend
make run_frontend make run_frontend
frontendc: frontendc:
make install_frontendc make install_frontendc
make run_frontend make run_frontend
install_backend: install_backend:
@echo 'Installing backend dependencies' @echo 'Installing backend dependencies'
@poetry install @poetry install
@poetry run pre-commit install @poetry run pre-commit install
backend: ## run the backend in development mode backend: ## run the backend in development mode
@echo 'Setting up the environment' @echo 'Setting up the environment'
@make setup_env @make setup_env
@ -208,7 +205,6 @@ else
--workers $(workers) --workers $(workers)
endif endif
build_and_run: build_and_run:
@echo 'Removing dist folder' @echo 'Removing dist folder'
@make setup_env @make setup_env
@ -218,20 +214,17 @@ build_and_run:
poetry run pip install dist/*.tar.gz poetry run pip install dist/*.tar.gz
poetry run langflow run poetry run langflow run
build_and_install: build_and_install:
@echo 'Removing dist folder' @echo 'Removing dist folder'
rm -rf dist rm -rf dist
rm -rf src/backend/base/dist rm -rf src/backend/base/dist
make build && poetry run pip install dist/*.whl && pip install src/backend/base/dist/*.whl --force-reinstall make build && poetry run pip install dist/*.whl && pip install src/backend/base/dist/*.whl --force-reinstall
build_frontend: ## build the frontend static files build_frontend: ## build the frontend static files
cd src/frontend && CI='' npm run build cd src/frontend && CI='' npm run build
rm -rf src/backend/base/langflow/frontend rm -rf src/backend/base/langflow/frontend
cp -r src/frontend/build src/backend/base/langflow/frontend cp -r src/frontend/build src/backend/base/langflow/frontend
build: ## build the frontend static files and package the project build: ## build the frontend static files and package the project
@echo 'Building the project' @echo 'Building the project'
@make setup_env @make setup_env
@ -245,16 +238,13 @@ ifdef main
make build_langflow make build_langflow
endif endif
build_langflow_base: build_langflow_base:
cd src/backend/base && poetry build cd src/backend/base && poetry build
rm -rf src/backend/base/langflow/frontend rm -rf src/backend/base/langflow/frontend
build_langflow_backup: build_langflow_backup:
poetry lock && poetry build poetry lock && poetry build
build_langflow: build_langflow:
cd ./scripts && poetry run python update_dependencies.py cd ./scripts && poetry run python update_dependencies.py
poetry lock poetry lock
@ -264,49 +254,41 @@ ifdef restore
mv poetry.lock.bak poetry.lock mv poetry.lock.bak poetry.lock
endif endif
dev: ## run the project in development mode with docker compose dev: ## run the project in development mode with docker compose
make install_frontend make install_frontend
ifeq ($(build),1) ifeq ($(build),1)
@echo 'Running docker compose up with build' @echo 'Running docker compose up with build'
docker compose $(if $(debug),-f docker-compose.debug.yml) up --build docker compose $(if $(debug),-f docker-compose.debug.yml) up --build
else else
@echo 'Running docker compose up without build' @echo 'Running docker compose up without build'
docker compose $(if $(debug),-f docker-compose.debug.yml) up docker compose $(if $(debug),-f docker-compose.debug.yml) up
endif endif
docker_build: dockerfile_build clear_dockerimage ## build DockerFile docker_build: dockerfile_build clear_dockerimage ## build DockerFile
docker_build_backend: dockerfile_build_be clear_dockerimage ## build Backend DockerFile docker_build_backend: dockerfile_build_be clear_dockerimage ## build Backend DockerFile
docker_build_frontend: dockerfile_build_fe clear_dockerimage ## build Frontend Dockerfile docker_build_frontend: dockerfile_build_fe clear_dockerimage ## build Frontend Dockerfile
dockerfile_build: dockerfile_build:
@echo 'BUILDING DOCKER IMAGE: ${DOCKERFILE}' @echo 'BUILDING DOCKER IMAGE: ${DOCKERFILE}'
@docker build --rm \ @docker build --rm \
-f ${DOCKERFILE} \ -f ${DOCKERFILE} \
-t langflow:${VERSION} . -t langflow:${VERSION} .
dockerfile_build_be: dockerfile_build dockerfile_build_be: dockerfile_build
@echo 'BUILDING DOCKER IMAGE BACKEND: ${DOCKERFILE_BACKEND}' @echo 'BUILDING DOCKER IMAGE BACKEND: ${DOCKERFILE_BACKEND}'
@docker build --rm \ @docker build --rm \
--build-arg LANGFLOW_IMAGE=langflow:${VERSION} \ --build-arg LANGFLOW_IMAGE=langflow:${VERSION} \
-f ${DOCKERFILE_BACKEND} \ -f ${DOCKERFILE_BACKEND} \
-t langflow_backend:${VERSION} . -t langflow_backend:${VERSION} .
dockerfile_build_fe: dockerfile_build dockerfile_build_fe: dockerfile_build
@echo 'BUILDING DOCKER IMAGE FRONTEND: ${DOCKERFILE_FRONTEND}' @echo 'BUILDING DOCKER IMAGE FRONTEND: ${DOCKERFILE_FRONTEND}'
@docker build --rm \ @docker build --rm \
--build-arg LANGFLOW_IMAGE=langflow:${VERSION} \ --build-arg LANGFLOW_IMAGE=langflow:${VERSION} \
-f ${DOCKERFILE_FRONTEND} \ -f ${DOCKERFILE_FRONTEND} \
-t langflow_frontend:${VERSION} . -t langflow_frontend:${VERSION} .
clear_dockerimage: clear_dockerimage:
@echo 'Clearing the docker build' @echo 'Clearing the docker build'
@ -314,24 +296,20 @@ clear_dockerimage:
docker rmi $$(docker images -f "dangling=true" -q); \ docker rmi $$(docker images -f "dangling=true" -q); \
fi fi
docker_compose_up: docker_build docker_compose_down docker_compose_up: docker_build docker_compose_down
@echo 'Running docker compose up' @echo 'Running docker compose up'
docker compose -f $(DOCKER_COMPOSE) up --remove-orphans docker compose -f $(DOCKER_COMPOSE) up --remove-orphans
docker_compose_down: docker_compose_down:
@echo 'Running docker compose down' @echo 'Running docker compose down'
docker compose -f $(DOCKER_COMPOSE) down || true docker compose -f $(DOCKER_COMPOSE) down || true
lock_base: lock_base:
cd src/backend/base && poetry lock cd src/backend/base && poetry lock
lock_langflow: lock_langflow:
poetry lock poetry lock
lock: lock:
# Run both in parallel # Run both in parallel
@echo 'Locking dependencies' @echo 'Locking dependencies'
@ -346,11 +324,9 @@ update:
publish_base: publish_base:
cd src/backend/base && poetry publish cd src/backend/base && poetry publish
publish_langflow: publish_langflow:
poetry publish poetry publish
publish: ## build the frontend static files and package the project and publish it to PyPI publish: ## build the frontend static files and package the project and publish it to PyPI
@echo 'Publishing the project' @echo 'Publishing the project'
ifdef base ifdef base
@ -361,11 +337,16 @@ ifdef main
make publish_langflow make publish_langflow
endif endif
check_tools: ## check for required tools
@command -v poetry >/dev/null 2>&1 || { echo >&2 "Poetry is not installed. Aborting."; exit 1; }
@command -v npm >/dev/null 2>&1 || { echo >&2 "NPM is not installed. Aborting."; exit 1; }
@command -v docker >/dev/null 2>&1 || { echo >&2 "Docker is not installed. Aborting."; exit 1; }
@command -v pipx >/dev/null 2>&1 || { echo >&2 "pipx is not installed. Aborting."; exit 1; }
@echo "All required tools are installed."
help: ## show this help message help: ## show this help message
@echo '----' @echo '----'
@echo -e "$$(grep -hE '^\S+:.*##' $(MAKEFILE_LIST) | \ @grep -hE '^\S+:.*##' $(MAKEFILE_LIST) | \
sed -e 's/:.*##\s*/:/' \ awk -F ':.*##' '{printf "\033[36mmake %s\033[0m: %s\n", $$1, $$2}' | \
-e 's/^\(.\+\):\(.*\)/\\x1b[36mmake \1\\x1b[m:\2/' | \ column -c2 -t -s :
column -c2 -t -s :']]')"
@echo '----' @echo '----'

View file

@ -1 +1 @@
MODEL_NAMES = ["llama3-8b-8192", "llama3-70b-8192", "mixtral-8x7b-32768", "gemma-7b-it"] MODEL_NAMES = ["llama3-8b-8192", "llama3-70b-8192", "mixtral-8x7b-32768", "gemma-7b-it", "gemma2-9b-it"]