Makefile 13 KB

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