Makefile 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. SHELL=/bin/bash
  2. # Makefile for OpenDevin project
  3. # Variables
  4. DOCKER_IMAGE = ghcr.io/opendevin/sandbox
  5. BACKEND_PORT = 3000
  6. BACKEND_HOST = "127.0.0.1:$(BACKEND_PORT)"
  7. FRONTEND_PORT = 3001
  8. DEFAULT_WORKSPACE_DIR = "./workspace"
  9. DEFAULT_MODEL = "gpt-3.5-turbo-1106"
  10. CONFIG_FILE = config.toml
  11. PRECOMMIT_CONFIG_PATH = "./dev_config/python/.pre-commit-config.yaml"
  12. # ANSI color codes
  13. GREEN=$(shell tput -Txterm setaf 2)
  14. YELLOW=$(shell tput -Txterm setaf 3)
  15. RED=$(shell tput -Txterm setaf 1)
  16. BLUE=$(shell tput -Txterm setaf 6)
  17. RESET=$(shell tput -Txterm sgr0)
  18. # Build
  19. build:
  20. @echo "$(GREEN)Building project...$(RESET)"
  21. @$(MAKE) -s check-dependencies
  22. @$(MAKE) -s pull-docker-image
  23. @$(MAKE) -s install-python-dependencies
  24. @$(MAKE) -s install-frontend-dependencies
  25. @$(MAKE) -s install-precommit-hooks
  26. @$(MAKE) -s build-frontend
  27. @echo "$(GREEN)Build completed successfully.$(RESET)"
  28. check-dependencies:
  29. @echo "$(YELLOW)Checking dependencies...$(RESET)"
  30. @$(MAKE) -s check-system
  31. @$(MAKE) -s check-python
  32. @$(MAKE) -s check-npm
  33. @$(MAKE) -s check-nodejs
  34. @$(MAKE) -s check-docker
  35. @$(MAKE) -s check-poetry
  36. @echo "$(GREEN)Dependencies checked successfully.$(RESET)"
  37. check-system:
  38. @echo "$(YELLOW)Checking system...$(RESET)"
  39. @if [ "$(shell uname)" = "Darwin" ]; then \
  40. echo "$(BLUE)macOS detected.$(RESET)"; \
  41. elif [ "$(shell uname)" = "Linux" ]; then \
  42. echo "$(BLUE)Linux detected.$(RESET)"; \
  43. elif [ "$$(uname -r | grep -i microsoft)" ]; then \
  44. echo "$(BLUE)Windows Subsystem for Linux detected.$(RESET)"; \
  45. else \
  46. echo "$(RED)Unsupported system detected. Please use macOS, Linux, or Windows Subsystem for Linux (WSL).$(RESET)"; \
  47. exit 1; \
  48. fi
  49. check-python:
  50. @echo "$(YELLOW)Checking Python installation...$(RESET)"
  51. @if command -v python3.11 > /dev/null; then \
  52. echo "$(BLUE)$(shell python3.11 --version) is already installed.$(RESET)"; \
  53. else \
  54. echo "$(RED)Python 3.11 is not installed. Please install Python 3.11 to continue.$(RESET)"; \
  55. exit 1; \
  56. fi
  57. check-npm:
  58. @echo "$(YELLOW)Checking npm installation...$(RESET)"
  59. @if command -v npm > /dev/null; then \
  60. echo "$(BLUE)npm $(shell npm --version) is already installed.$(RESET)"; \
  61. else \
  62. echo "$(RED)npm is not installed. Please install Node.js to continue.$(RESET)"; \
  63. exit 1; \
  64. fi
  65. check-nodejs:
  66. @echo "$(YELLOW)Checking Node.js installation...$(RESET)"
  67. @if command -v node > /dev/null; then \
  68. NODE_VERSION=$(shell node --version | sed -E 's/v//g'); \
  69. IFS='.' read -r -a NODE_VERSION_ARRAY <<< "$$NODE_VERSION"; \
  70. if [ "$${NODE_VERSION_ARRAY[0]}" -gt 18 ] || ([ "$${NODE_VERSION_ARRAY[0]}" -eq 18 ] && [ "$${NODE_VERSION_ARRAY[1]}" -gt 17 ]) || ([ "$${NODE_VERSION_ARRAY[0]}" -eq 18 ] && [ "$${NODE_VERSION_ARRAY[1]}" -eq 17 ] && [ "$${NODE_VERSION_ARRAY[2]}" -ge 1 ]); then \
  71. echo "$(BLUE)Node.js $$NODE_VERSION is already installed.$(RESET)"; \
  72. else \
  73. echo "$(RED)Node.js 18.17.1 or later is required. Please install Node.js 18.17.1 or later to continue.$(RESET)"; \
  74. exit 1; \
  75. fi; \
  76. else \
  77. echo "$(RED)Node.js is not installed. Please install Node.js to continue.$(RESET)"; \
  78. exit 1; \
  79. fi
  80. check-docker:
  81. @echo "$(YELLOW)Checking Docker installation...$(RESET)"
  82. @if command -v docker > /dev/null; then \
  83. echo "$(BLUE)$(shell docker --version) is already installed.$(RESET)"; \
  84. else \
  85. echo "$(RED)Docker is not installed. Please install Docker to continue.$(RESET)"; \
  86. exit 1; \
  87. fi
  88. check-poetry:
  89. @echo "$(YELLOW)Checking Poetry installation...$(RESET)"
  90. @if command -v poetry > /dev/null; then \
  91. POETRY_VERSION=$(shell poetry --version 2>&1 | sed -E 's/Poetry \(version ([0-9]+\.[0-9]+\.[0-9]+)\)/\1/'); \
  92. IFS='.' read -r -a POETRY_VERSION_ARRAY <<< "$$POETRY_VERSION"; \
  93. if [ $${POETRY_VERSION_ARRAY[0]} -ge 1 ] && [ $${POETRY_VERSION_ARRAY[1]} -ge 8 ]; then \
  94. echo "$(BLUE)$(shell poetry --version) is already installed.$(RESET)"; \
  95. else \
  96. echo "$(RED)Poetry 1.8 or later is required. You can install poetry by running the following command, then adding Poetry to your PATH:"; \
  97. echo "$(RED) curl -sSL https://install.python-poetry.org | python3 -$(RESET)"; \
  98. echo "$(RED)More detail here: https://python-poetry.org/docs/#installing-with-the-official-installer$(RESET)"; \
  99. exit 1; \
  100. fi; \
  101. else \
  102. echo "$(RED)Poetry is not installed. You can install poetry by running the following command, then adding Poetry to your PATH:"; \
  103. echo "$(RED) curl -sSL https://install.python-poetry.org | python3.11 -$(RESET)"; \
  104. echo "$(RED)More detail here: https://python-poetry.org/docs/#installing-with-the-official-installer$(RESET)"; \
  105. exit 1; \
  106. fi
  107. pull-docker-image:
  108. @echo "$(YELLOW)Pulling Docker image...$(RESET)"
  109. @docker pull $(DOCKER_IMAGE)
  110. @echo "$(GREEN)Docker image pulled successfully.$(RESET)"
  111. install-python-dependencies:
  112. @echo "$(GREEN)Installing Python dependencies...$(RESET)"
  113. @if [ "$(shell uname)" = "Darwin" ]; then \
  114. echo "$(BLUE)Installing `chroma-hnswlib`...$(RESET)"; \
  115. export HNSWLIB_NO_NATIVE=1; \
  116. poetry run pip install chroma-hnswlib; \
  117. fi
  118. @poetry install --without evaluation
  119. @echo "$(GREEN)Python dependencies installed successfully.$(RESET)"
  120. install-frontend-dependencies:
  121. @echo "$(YELLOW)Setting up frontend environment...$(RESET)"
  122. @echo "$(YELLOW)Detect Node.js version...$(RESET)"
  123. @cd frontend && node ./scripts/detect-node-version.js
  124. @cd frontend && \
  125. echo "$(BLUE)Installing frontend dependencies with npm...$(RESET)" && \
  126. npm install && \
  127. echo "$(BLUE)Running make-i18n with npm...$(RESET)" && \
  128. npm run make-i18n
  129. @echo "$(GREEN)Frontend dependencies installed successfully.$(RESET)"
  130. install-precommit-hooks:
  131. @echo "$(YELLOW)Installing pre-commit hooks...$(RESET)"
  132. @git config --unset-all core.hooksPath || true
  133. @poetry run pre-commit install --config $(PRECOMMIT_CONFIG_PATH)
  134. @echo "$(GREEN)Pre-commit hooks installed successfully.$(RESET)"
  135. lint:
  136. @echo "$(YELLOW)Running linters...$(RESET)"
  137. @poetry run pre-commit run --files opendevin/**/* agenthub/**/* --show-diff-on-failure --config $(PRECOMMIT_CONFIG_PATH)
  138. build-frontend:
  139. @echo "$(YELLOW)Building frontend...$(RESET)"
  140. @cd frontend && npm run build
  141. # Start backend
  142. start-backend:
  143. @echo "$(YELLOW)Starting backend...$(RESET)"
  144. @poetry run uvicorn opendevin.server.listen:app --port $(BACKEND_PORT)
  145. # Start frontend
  146. start-frontend:
  147. @echo "$(YELLOW)Starting frontend...$(RESET)"
  148. @cd frontend && VITE_BACKEND_HOST=$(BACKEND_HOST) VITE_FRONTEND_PORT=$(FRONTEND_PORT) npm run start
  149. # Run the app
  150. run:
  151. @echo "$(YELLOW)Running the app...$(RESET)"
  152. @if [ "$(OS)" = "Windows_NT" ]; then \
  153. echo "$(RED)`make run` is not supported on Windows. Please run `make start-frontend` and `make start-backend` separately.$(RESET)"; \
  154. exit 1; \
  155. fi
  156. @mkdir -p logs
  157. @echo "$(YELLOW)Starting backend server...$(RESET)"
  158. @poetry run uvicorn opendevin.server.listen:app --port $(BACKEND_PORT) &
  159. @echo "$(YELLOW)Waiting for the backend to start...$(RESET)"
  160. @until nc -z localhost $(BACKEND_PORT); do sleep 0.1; done
  161. @echo "$(GREEN)Backend started successfully.$(RESET)"
  162. @cd frontend && echo "$(BLUE)Starting frontend with npm...$(RESET)" && npm run start -- --port $(FRONTEND_PORT)
  163. @echo "$(GREEN)Application started successfully.$(RESET)"
  164. # Setup config.toml
  165. setup-config:
  166. @echo "$(YELLOW)Setting up config.toml...$(RESET)"
  167. @$(MAKE) setup-config-prompts
  168. @mv $(CONFIG_FILE).tmp $(CONFIG_FILE)
  169. @echo "$(GREEN)Config.toml setup completed.$(RESET)"
  170. setup-config-prompts:
  171. @read -p "Enter your LLM Model name (see https://docs.litellm.ai/docs/providers for full list) [default: $(DEFAULT_MODEL)]: " llm_model; \
  172. llm_model=$${llm_model:-$(DEFAULT_MODEL)}; \
  173. echo "LLM_MODEL=\"$$llm_model\"" > $(CONFIG_FILE).tmp
  174. @read -p "Enter your LLM API key: " llm_api_key; \
  175. echo "LLM_API_KEY=\"$$llm_api_key\"" >> $(CONFIG_FILE).tmp
  176. @read -p "Enter your LLM Base URL [mostly used for local LLMs, leave blank if not needed - example: http://localhost:5001/v1/]: " llm_base_url; \
  177. if [[ ! -z "$$llm_base_url" ]]; then echo "LLM_BASE_URL=\"$$llm_base_url\"" >> $(CONFIG_FILE).tmp; fi
  178. @echo "Enter your LLM Embedding Model\nChoices are openai, azureopenai, llama2 or leave blank to default to 'BAAI/bge-small-en-v1.5' via huggingface"; \
  179. read -p "> " llm_embedding_model; \
  180. echo "LLM_EMBEDDING_MODEL=\"$$llm_embedding_model\"" >> $(CONFIG_FILE).tmp; \
  181. if [ "$$llm_embedding_model" = "llama2" ]; then \
  182. read -p "Enter the local model URL (will overwrite LLM_BASE_URL): " llm_base_url; \
  183. echo "LLM_BASE_URL=\"$$llm_base_url\"" >> $(CONFIG_FILE).tmp; \
  184. elif [ "$$llm_embedding_model" = "azureopenai" ]; then \
  185. read -p "Enter the Azure endpoint URL (will overwrite LLM_BASE_URL): " llm_base_url; \
  186. echo "LLM_BASE_URL=\"$$llm_base_url\"" >> $(CONFIG_FILE).tmp; \
  187. read -p "Enter the Azure LLM Embedding Deployment Name: " llm_embedding_deployment_name; \
  188. echo "LLM_EMBEDDING_DEPLOYMENT_NAME=\"$$llm_embedding_deployment_name\"" >> $(CONFIG_FILE).tmp; \
  189. read -p "Enter the Azure API Version: " llm_api_version; \
  190. echo "LLM_API_VERSION=\"$$llm_api_version\"" >> $(CONFIG_FILE).tmp; \
  191. fi
  192. @read -p "Enter your workspace directory [default: $(DEFAULT_WORKSPACE_DIR)]: " workspace_dir; \
  193. workspace_dir=$${workspace_dir:-$(DEFAULT_WORKSPACE_DIR)}; \
  194. echo "WORKSPACE_BASE=\"$$workspace_dir\"" >> $(CONFIG_FILE).tmp
  195. # Help
  196. help:
  197. @echo "$(BLUE)Usage: make [target]$(RESET)"
  198. @echo "Targets:"
  199. @echo " $(GREEN)build$(RESET) - Build project, including environment setup and dependencies."
  200. @echo " $(GREEN)lint$(RESET) - Run linters on the project."
  201. @echo " $(GREEN)setup-config$(RESET) - Setup the configuration for OpenDevin by providing LLM API key,"
  202. @echo " LLM Model name, and workspace directory."
  203. @echo " $(GREEN)start-backend$(RESET) - Start the backend server for the OpenDevin project."
  204. @echo " $(GREEN)start-frontend$(RESET) - Start the frontend server for the OpenDevin project."
  205. @echo " $(GREEN)run$(RESET) - Run the OpenDevin application, starting both backend and frontend servers."
  206. @echo " Backend Log file will be stored in the 'logs' directory."
  207. @echo " $(GREEN)help$(RESET) - Display this help message, providing information on available targets."
  208. # Phony targets
  209. .PHONY: build check-dependencies check-python check-npm check-docker check-poetry pull-docker-image install-python-dependencies install-frontend-dependencies install-precommit-hooks lint start-backend start-frontend run setup-config setup-config-prompts help