Makefile 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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"
  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. ifeq ($(INSTALL_DOCKER),)
  23. @$(MAKE) -s pull-docker-image
  24. endif
  25. @$(MAKE) -s install-python-dependencies
  26. @$(MAKE) -s install-frontend-dependencies
  27. @$(MAKE) -s install-precommit-hooks
  28. @$(MAKE) -s build-frontend
  29. @echo "$(GREEN)Build completed successfully.$(RESET)"
  30. check-dependencies:
  31. @echo "$(YELLOW)Checking dependencies...$(RESET)"
  32. @$(MAKE) -s check-system
  33. @$(MAKE) -s check-python
  34. @$(MAKE) -s check-npm
  35. @$(MAKE) -s check-nodejs
  36. ifeq ($(INSTALL_DOCKER),)
  37. @$(MAKE) -s check-docker
  38. endif
  39. @$(MAKE) -s check-poetry
  40. @echo "$(GREEN)Dependencies checked successfully.$(RESET)"
  41. check-system:
  42. @echo "$(YELLOW)Checking system...$(RESET)"
  43. @if [ "$(shell uname)" = "Darwin" ]; then \
  44. echo "$(BLUE)macOS detected.$(RESET)"; \
  45. elif [ "$(shell uname)" = "Linux" ]; then \
  46. if [ -f "/etc/manjaro-release" ]; then \
  47. echo "$(BLUE)Manjaro Linux detected.$(RESET)"; \
  48. else \
  49. echo "$(BLUE)Linux detected.$(RESET)"; \
  50. fi; \
  51. elif [ "$$(uname -r | grep -i microsoft)" ]; then \
  52. echo "$(BLUE)Windows Subsystem for Linux detected.$(RESET)"; \
  53. else \
  54. echo "$(RED)Unsupported system detected. Please use macOS, Linux, or Windows Subsystem for Linux (WSL).$(RESET)"; \
  55. exit 1; \
  56. fi
  57. check-python:
  58. @echo "$(YELLOW)Checking Python installation...$(RESET)"
  59. @if command -v python3.11 > /dev/null; then \
  60. echo "$(BLUE)$(shell python3.11 --version) is already installed.$(RESET)"; \
  61. else \
  62. echo "$(RED)Python 3.11 is not installed. Please install Python 3.11 to continue.$(RESET)"; \
  63. exit 1; \
  64. fi
  65. check-npm:
  66. @echo "$(YELLOW)Checking npm installation...$(RESET)"
  67. @if command -v npm > /dev/null; then \
  68. echo "$(BLUE)npm $(shell npm --version) is already installed.$(RESET)"; \
  69. else \
  70. echo "$(RED)npm is not installed. Please install Node.js to continue.$(RESET)"; \
  71. exit 1; \
  72. fi
  73. check-nodejs:
  74. @echo "$(YELLOW)Checking Node.js installation...$(RESET)"
  75. @if command -v node > /dev/null; then \
  76. NODE_VERSION=$(shell node --version | sed -E 's/v//g'); \
  77. IFS='.' read -r -a NODE_VERSION_ARRAY <<< "$$NODE_VERSION"; \
  78. 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 \
  79. echo "$(BLUE)Node.js $$NODE_VERSION is already installed.$(RESET)"; \
  80. else \
  81. echo "$(RED)Node.js 18.17.1 or later is required. Please install Node.js 18.17.1 or later to continue.$(RESET)"; \
  82. exit 1; \
  83. fi; \
  84. else \
  85. echo "$(RED)Node.js is not installed. Please install Node.js to continue.$(RESET)"; \
  86. exit 1; \
  87. fi
  88. check-docker:
  89. @echo "$(YELLOW)Checking Docker installation...$(RESET)"
  90. @if command -v docker > /dev/null; then \
  91. echo "$(BLUE)$(shell docker --version) is already installed.$(RESET)"; \
  92. else \
  93. echo "$(RED)Docker is not installed. Please install Docker to continue.$(RESET)"; \
  94. exit 1; \
  95. fi
  96. check-poetry:
  97. @echo "$(YELLOW)Checking Poetry installation...$(RESET)"
  98. @if command -v poetry > /dev/null; then \
  99. POETRY_VERSION=$(shell poetry --version 2>&1 | sed -E 's/Poetry \(version ([0-9]+\.[0-9]+\.[0-9]+)\)/\1/'); \
  100. IFS='.' read -r -a POETRY_VERSION_ARRAY <<< "$$POETRY_VERSION"; \
  101. if [ $${POETRY_VERSION_ARRAY[0]} -ge 1 ] && [ $${POETRY_VERSION_ARRAY[1]} -ge 8 ]; then \
  102. echo "$(BLUE)$(shell poetry --version) is already installed.$(RESET)"; \
  103. else \
  104. echo "$(RED)Poetry 1.8 or later is required. You can install poetry by running the following command, then adding Poetry to your PATH:"; \
  105. echo "$(RED) curl -sSL https://install.python-poetry.org | python3 -$(RESET)"; \
  106. echo "$(RED)More detail here: https://python-poetry.org/docs/#installing-with-the-official-installer$(RESET)"; \
  107. exit 1; \
  108. fi; \
  109. else \
  110. echo "$(RED)Poetry is not installed. You can install poetry by running the following command, then adding Poetry to your PATH:"; \
  111. echo "$(RED) curl -sSL https://install.python-poetry.org | python3.11 -$(RESET)"; \
  112. echo "$(RED)More detail here: https://python-poetry.org/docs/#installing-with-the-official-installer$(RESET)"; \
  113. exit 1; \
  114. fi
  115. pull-docker-image:
  116. @echo "$(YELLOW)Pulling Docker image...$(RESET)"
  117. @docker pull $(DOCKER_IMAGE)
  118. @echo "$(GREEN)Docker image pulled successfully.$(RESET)"
  119. install-python-dependencies:
  120. @echo "$(GREEN)Installing Python dependencies...$(RESET)"
  121. poetry env use python3.11
  122. @if [ "$(shell uname)" = "Darwin" ]; then \
  123. echo "$(BLUE)Installing chroma-hnswlib...$(RESET)"; \
  124. export HNSWLIB_NO_NATIVE=1; \
  125. poetry run pip install chroma-hnswlib; \
  126. fi
  127. @poetry install
  128. @if [ -f "/etc/manjaro-release" ]; then \
  129. echo "$(BLUE)Detected Manjaro Linux. Installing Playwright dependencies...$(RESET)"; \
  130. poetry run pip install playwright; \
  131. poetry run playwright install chromium; \
  132. else \
  133. poetry run playwright install --with-deps chromium; \
  134. fi
  135. @echo "$(GREEN)Python dependencies installed successfully.$(RESET)"
  136. install-frontend-dependencies:
  137. @echo "$(YELLOW)Setting up frontend environment...$(RESET)"
  138. @echo "$(YELLOW)Detect Node.js version...$(RESET)"
  139. @cd frontend && node ./scripts/detect-node-version.js
  140. @cd frontend && \
  141. echo "$(BLUE)Installing frontend dependencies with npm...$(RESET)" && \
  142. npm install && \
  143. echo "$(BLUE)Running make-i18n with npm...$(RESET)" && \
  144. npm run make-i18n
  145. @echo "$(GREEN)Frontend dependencies installed successfully.$(RESET)"
  146. install-precommit-hooks:
  147. @echo "$(YELLOW)Installing pre-commit hooks...$(RESET)"
  148. @git config --unset-all core.hooksPath || true
  149. @poetry run pre-commit install --config $(PRECOMMIT_CONFIG_PATH)
  150. @echo "$(GREEN)Pre-commit hooks installed successfully.$(RESET)"
  151. lint-backend:
  152. @echo "$(YELLOW)Running linters...$(RESET)"
  153. @poetry run pre-commit run --files $$(git diff --name-only $$(git merge-base main $$(git branch --show-current)) $$(git branch --show-current) | tr '\n' ' ') --show-diff-on-failure --config $(PRECOMMIT_CONFIG_PATH)
  154. lint-frontend:
  155. @echo "$(YELLOW)Running linters for frontend...$(RESET)"
  156. @cd frontend && npm run lint
  157. lint:
  158. @$(MAKE) -s lint-frontend
  159. @$(MAKE) -s lint-backend
  160. test-frontend:
  161. @echo "$(YELLOW)Running tests for frontend...$(RESET)"
  162. @cd frontend && npm run test
  163. test:
  164. @$(MAKE) -s test-frontend
  165. build-frontend:
  166. @echo "$(YELLOW)Building frontend...$(RESET)"
  167. @cd frontend && npm run build
  168. # Start backend
  169. start-backend:
  170. @echo "$(YELLOW)Starting backend...$(RESET)"
  171. @poetry run uvicorn opendevin.server.listen:app --port $(BACKEND_PORT) --reload --reload-exclude "workspace/*"
  172. # Start frontend
  173. start-frontend:
  174. @echo "$(YELLOW)Starting frontend...$(RESET)"
  175. @cd frontend && VITE_BACKEND_HOST=$(BACKEND_HOST) VITE_FRONTEND_PORT=$(FRONTEND_PORT) npm run start
  176. # Run the app
  177. run:
  178. @echo "$(YELLOW)Running the app...$(RESET)"
  179. @if [ "$(OS)" = "Windows_NT" ]; then \
  180. echo "$(RED)`make run` is not supported on Windows. Please run `make start-frontend` and `make start-backend` separately.$(RESET)"; \
  181. exit 1; \
  182. fi
  183. @mkdir -p logs
  184. @echo "$(YELLOW)Starting backend server...$(RESET)"
  185. @poetry run uvicorn opendevin.server.listen:app --port $(BACKEND_PORT) &
  186. @echo "$(YELLOW)Waiting for the backend to start...$(RESET)"
  187. @until nc -z localhost $(BACKEND_PORT); do sleep 0.1; done
  188. @echo "$(GREEN)Backend started successfully.$(RESET)"
  189. @cd frontend && echo "$(BLUE)Starting frontend with npm...$(RESET)" && npm run start -- --port $(FRONTEND_PORT)
  190. @echo "$(GREEN)Application started successfully.$(RESET)"
  191. # Setup config.toml
  192. setup-config:
  193. @echo "$(YELLOW)Setting up config.toml...$(RESET)"
  194. @$(MAKE) setup-config-prompts
  195. @mv $(CONFIG_FILE).tmp $(CONFIG_FILE)
  196. @echo "$(GREEN)Config.toml setup completed.$(RESET)"
  197. setup-config-prompts:
  198. @echo "[core]" > $(CONFIG_FILE).tmp
  199. @read -p "Enter your workspace directory [default: $(DEFAULT_WORKSPACE_DIR)]: " workspace_dir; \
  200. workspace_dir=$${workspace_dir:-$(DEFAULT_WORKSPACE_DIR)}; \
  201. echo "workspace_base=\"$$workspace_dir\"" >> $(CONFIG_FILE).tmp
  202. @read -p "Do you want to persist the sandbox container? [true/false] [default: true]: " persist_sandbox; \
  203. persist_sandbox=$${persist_sandbox:-true}; \
  204. if [ "$$persist_sandbox" = "true" ]; then \
  205. read -p "Enter a password for the sandbox container: " ssh_password; \
  206. echo "ssh_password=\"$$ssh_password\"" >> $(CONFIG_FILE).tmp; \
  207. else \
  208. echo "persist_sandbox=\"$$persist_sandbox\"" >> $(CONFIG_FILE).tmp
  209. fi
  210. @echo "" >> $(CONFIG_FILE).tmp
  211. @echo "[llm]" >> $(CONFIG_FILE).tmp
  212. @read -p "Enter your LLM model name, used for running without UI. Set the model in the UI after you start the app. (see https://docs.litellm.ai/docs/providers for full list) [default: $(DEFAULT_MODEL)]: " llm_model; \
  213. llm_model=$${llm_model:-$(DEFAULT_MODEL)}; \
  214. echo "model=\"$$llm_model\"" >> $(CONFIG_FILE).tmp
  215. @read -p "Enter your LLM api key: " llm_api_key; \
  216. echo "api_key=\"$$llm_api_key\"" >> $(CONFIG_FILE).tmp
  217. @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; \
  218. if [[ ! -z "$$llm_base_url" ]]; then echo "base_url=\"$$llm_base_url\"" >> $(CONFIG_FILE).tmp; fi
  219. @echo "Enter your LLM Embedding Model"; \
  220. echo "Choices are:"; \
  221. echo " - openai"; \
  222. echo " - azureopenai"; \
  223. echo " - Embeddings available only with OllamaEmbedding:"; \
  224. echo " - llama2"; \
  225. echo " - mxbai-embed-large"; \
  226. echo " - nomic-embed-text"; \
  227. echo " - all-minilm"; \
  228. echo " - stable-code"; \
  229. echo " - Leave blank to default to 'BAAI/bge-small-en-v1.5' via huggingface"; \
  230. read -p "> " llm_embedding_model; \
  231. echo "embedding_model=\"$$llm_embedding_model\"" >> $(CONFIG_FILE).tmp; \
  232. if [ "$$llm_embedding_model" = "llama2" ] || [ "$$llm_embedding_model" = "mxbai-embed-large" ] || [ "$$llm_embedding_model" = "nomic-embed-text" ] || [ "$$llm_embedding_model" = "all-minilm" ] || [ "$$llm_embedding_model" = "stable-code" ]; then \
  233. read -p "Enter the local model URL for the embedding model (will set llm.embedding_base_url): " llm_embedding_base_url; \
  234. echo "embedding_base_url=\"$$llm_embedding_base_url\"" >> $(CONFIG_FILE).tmp; \
  235. elif [ "$$llm_embedding_model" = "azureopenai" ]; then \
  236. read -p "Enter the Azure endpoint URL (will overwrite llm.base_url): " llm_base_url; \
  237. echo "base_url=\"$$llm_base_url\"" >> $(CONFIG_FILE).tmp; \
  238. read -p "Enter the Azure LLM Embedding Deployment Name: " llm_embedding_deployment_name; \
  239. echo "embedding_deployment_name=\"$$llm_embedding_deployment_name\"" >> $(CONFIG_FILE).tmp; \
  240. read -p "Enter the Azure API Version: " llm_api_version; \
  241. echo "api_version=\"$$llm_api_version\"" >> $(CONFIG_FILE).tmp; \
  242. fi
  243. # Clean up all caches
  244. clean:
  245. @echo "$(YELLOW)Cleaning up caches...$(RESET)"
  246. @rm -rf opendevin/.cache
  247. @echo "$(GREEN)Caches cleaned up successfully.$(RESET)"
  248. # Help
  249. help:
  250. @echo "$(BLUE)Usage: make [target]$(RESET)"
  251. @echo "Targets:"
  252. @echo " $(GREEN)build$(RESET) - Build project, including environment setup and dependencies."
  253. @echo " $(GREEN)lint$(RESET) - Run linters on the project."
  254. @echo " $(GREEN)setup-config$(RESET) - Setup the configuration for OpenDevin by providing LLM API key,"
  255. @echo " LLM Model name, and workspace directory."
  256. @echo " $(GREEN)start-backend$(RESET) - Start the backend server for the OpenDevin project."
  257. @echo " $(GREEN)start-frontend$(RESET) - Start the frontend server for the OpenDevin project."
  258. @echo " $(GREEN)run$(RESET) - Run the OpenDevin application, starting both backend and frontend servers."
  259. @echo " Backend Log file will be stored in the 'logs' directory."
  260. @echo " $(GREEN)help$(RESET) - Display this help message, providing information on available targets."
  261. # Phony targets
  262. .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