Makefile 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. # Makefile for OpenDevin project
  2. # Variables
  3. DOCKER_IMAGE = ghcr.io/opendevin/sandbox
  4. BACKEND_PORT = 3000
  5. BACKEND_HOST = "127.0.0.1:$(BACKEND_PORT)"
  6. FRONTEND_PORT = 3001
  7. DEFAULT_WORKSPACE_DIR = "./workspace"
  8. DEFAULT_MODEL = "gpt-3.5-turbo-1106"
  9. CONFIG_FILE = config.toml
  10. PRECOMMIT_CONFIG_PATH = "./dev_config/python/.pre-commit-config.yaml"
  11. # ANSI color codes
  12. GREEN=\033[0;32m
  13. YELLOW=\033[0;33m
  14. RED=\033[0;31m
  15. BLUE=\033[0;34m
  16. RESET=\033[0m
  17. # Build
  18. build:
  19. @echo "$(GREEN)Building project...$(RESET)"
  20. @$(MAKE) -s check-dependencies
  21. @$(MAKE) -s pull-docker-image
  22. @$(MAKE) -s install-python-dependencies
  23. @$(MAKE) -s install-frontend-dependencies
  24. @$(MAKE) -s install-precommit-hooks
  25. @$(MAKE) -s build-frontend
  26. @echo "$(GREEN)Build completed successfully.$(RESET)"
  27. check-dependencies:
  28. @echo "$(YELLOW)Checking dependencies...$(RESET)"
  29. @$(MAKE) -s check-python
  30. @$(MAKE) -s check-npm
  31. @$(MAKE) -s check-docker
  32. @$(MAKE) -s check-poetry
  33. @echo "$(GREEN)Dependencies checked successfully.$(RESET)"
  34. check-python:
  35. @echo "$(YELLOW)Checking Python installation...$(RESET)"
  36. @if command -v python3.11 > /dev/null; then \
  37. echo "$(BLUE)$(shell python3.11 --version) is already installed.$(RESET)"; \
  38. else \
  39. echo "$(RED)Python 3.11 is not installed. Please install Python 3.11 to continue.$(RESET)"; \
  40. exit 1; \
  41. fi
  42. check-npm:
  43. @echo "$(YELLOW)Checking npm installation...$(RESET)"
  44. @if command -v npm > /dev/null; then \
  45. echo "$(BLUE)npm $(shell npm --version) is already installed.$(RESET)"; \
  46. else \
  47. echo "$(RED)npm is not installed. Please install Node.js to continue.$(RESET)"; \
  48. exit 1; \
  49. fi
  50. check-docker:
  51. @echo "$(YELLOW)Checking Docker installation...$(RESET)"
  52. @if command -v docker > /dev/null; then \
  53. echo "$(BLUE)$(shell docker --version) is already installed.$(RESET)"; \
  54. else \
  55. echo "$(RED)Docker is not installed. Please install Docker to continue.$(RESET)"; \
  56. exit 1; \
  57. fi
  58. check-poetry:
  59. @echo "$(YELLOW)Checking Poetry installation...$(RESET)"
  60. @if command -v poetry > /dev/null; then \
  61. echo "$(BLUE)$(shell poetry --version) is already installed.$(RESET)"; \
  62. else \
  63. echo "$(RED)Poetry is not installed. You can install poetry by running the following command, then adding Poetry to your PATH:"; \
  64. echo "$(RED) curl -sSL https://install.python-poetry.org | python3.11 -$(RESET)"; \
  65. echo "$(RED)More detail here: https://python-poetry.org/docs/#installing-with-the-official-installer$(RESET)"; \
  66. exit 1; \
  67. fi
  68. pull-docker-image:
  69. @echo "$(YELLOW)Pulling Docker image...$(RESET)"
  70. @docker pull $(DOCKER_IMAGE)
  71. @echo "$(GREEN)Docker image pulled successfully.$(RESET)"
  72. install-python-dependencies:
  73. @echo "$(GREEN)Installing Python dependencies...$(RESET)"
  74. @if [ "$(shell uname)" = "Darwin" ]; then \
  75. echo "$(BLUE)Installing `chroma-hnswlib`...$(RESET)"; \
  76. export HNSWLIB_NO_NATIVE=1; \
  77. poetry run pip install chroma-hnswlib; \
  78. fi
  79. @poetry install --without evaluation
  80. @echo "$(GREEN)Python dependencies installed successfully.$(RESET)"
  81. install-frontend-dependencies:
  82. @echo "$(YELLOW)Setting up frontend environment...$(RESET)"
  83. @echo "$(YELLOW)Detect Node.js version...$(RESET)"
  84. @cd frontend && node ./scripts/detect-node-version.js
  85. @cd frontend && \
  86. echo "$(BLUE)Installing frontend dependencies with npm...$(RESET)" && \
  87. npm install && \
  88. echo "$(BLUE)Running make-i18n with npm...$(RESET)" && \
  89. npm run make-i18n
  90. @echo "$(GREEN)Frontend dependencies installed successfully.$(RESET)"
  91. install-precommit-hooks:
  92. @echo "$(YELLOW)Installing pre-commit hooks...$(RESET)"
  93. @git config --unset-all core.hooksPath || true
  94. @poetry run pre-commit install --config $(PRECOMMIT_CONFIG_PATH)
  95. @echo "$(GREEN)Pre-commit hooks installed successfully.$(RESET)"
  96. lint:
  97. @echo "$(YELLOW)Running linters...$(RESET)"
  98. @poetry run pre-commit run --files opendevin/**/* agenthub/**/* --show-diff-on-failure --config $(PRECOMMIT_CONFIG_PATH)
  99. build-frontend:
  100. @echo "$(YELLOW)Building frontend...$(RESET)"
  101. @cd frontend && npm run build
  102. # Start backend
  103. start-backend:
  104. @echo "$(YELLOW)Starting backend...$(RESET)"
  105. @poetry run uvicorn opendevin.server.listen:app --port $(BACKEND_PORT)
  106. # Start frontend
  107. start-frontend:
  108. @echo "$(YELLOW)Starting frontend...$(RESET)"
  109. @cd frontend && BACKEND_HOST=$(BACKEND_HOST) FRONTEND_PORT=$(FRONTEND_PORT) npm run start
  110. # Run the app
  111. run:
  112. @echo "$(YELLOW)Running the app...$(RESET)"
  113. @if [ "$(OS)" = "Windows_NT" ]; then \
  114. echo "$(RED)`make run` is not supported on Windows. Please run `make start-frontend` and `make start-backend` separately.$(RESET)"; \
  115. exit 1; \
  116. fi
  117. @mkdir -p logs
  118. @echo "$(YELLOW)Starting backend server...$(RESET)"
  119. @poetry run uvicorn opendevin.server.listen:app --port $(BACKEND_PORT) &
  120. @echo "$(YELLOW)Waiting for the backend to start...$(RESET)"
  121. @until nc -z localhost $(BACKEND_PORT); do sleep 0.1; done
  122. @echo "$(GREEN)Backend started successfully.$(RESET)"
  123. @cd frontend && echo "$(BLUE)Starting frontend with npm...$(RESET)" && npm run start -- --port $(FRONTEND_PORT)
  124. @echo "$(GREEN)Application started successfully.$(RESET)"
  125. # Setup config.toml
  126. setup-config:
  127. @echo "$(YELLOW)Setting up config.toml...$(RESET)"
  128. @$(MAKE) setup-config-prompts
  129. @mv $(CONFIG_FILE).tmp $(CONFIG_FILE)
  130. @echo "$(GREEN)Config.toml setup completed.$(RESET)"
  131. setup-config-prompts:
  132. @read -p "Enter your LLM Model name (see https://docs.litellm.ai/docs/providers for full list) [default: $(DEFAULT_MODEL)]: " llm_model; \
  133. llm_model=$${llm_model:-$(DEFAULT_MODEL)}; \
  134. echo "LLM_MODEL=\"$$llm_model\"" > $(CONFIG_FILE).tmp
  135. @read -p "Enter your LLM API key: " llm_api_key; \
  136. echo "LLM_API_KEY=\"$$llm_api_key\"" >> $(CONFIG_FILE).tmp
  137. @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; \
  138. if [[ ! -z "$$llm_base_url" ]]; then echo "LLM_BASE_URL=\"$$llm_base_url\"" >> $(CONFIG_FILE).tmp; fi
  139. @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"; \
  140. read -p "> " llm_embedding_model; \
  141. echo "LLM_EMBEDDING_MODEL=\"$$llm_embedding_model\"" >> $(CONFIG_FILE).tmp; \
  142. if [ "$$llm_embedding_model" = "llama2" ]; then \
  143. read -p "Enter the local model URL (will overwrite LLM_BASE_URL): " llm_base_url; \
  144. echo "LLM_BASE_URL=\"$$llm_base_url\"" >> $(CONFIG_FILE).tmp; \
  145. elif [ "$$llm_embedding_model" = "azureopenai" ]; then \
  146. read -p "Enter the Azure endpoint URL (will overwrite LLM_BASE_URL): " llm_base_url; \
  147. echo "LLM_BASE_URL=\"$$llm_base_url\"" >> $(CONFIG_FILE).tmp; \
  148. read -p "Enter the Azure LLM Deployment Name: " llm_deployment_name; \
  149. echo "LLM_DEPLOYMENT_NAME=\"$$llm_deployment_name\"" >> $(CONFIG_FILE).tmp; \
  150. read -p "Enter the Azure API Version: " llm_api_version; \
  151. echo "LLM_API_VERSION=\"$$llm_api_version\"" >> $(CONFIG_FILE).tmp; \
  152. fi
  153. @read -p "Enter your workspace directory [default: $(DEFAULT_WORKSPACE_DIR)]: " workspace_dir; \
  154. workspace_dir=$${workspace_dir:-$(DEFAULT_WORKSPACE_DIR)}; \
  155. echo "WORKSPACE_BASE=\"$$workspace_dir\"" >> $(CONFIG_FILE).tmp
  156. # Help
  157. help:
  158. @echo "$(BLUE)Usage: make [target]$(RESET)"
  159. @echo "Targets:"
  160. @echo " $(GREEN)build$(RESET) - Build project, including environment setup and dependencies."
  161. @echo " $(GREEN)lint$(RESET) - Run linters on the project."
  162. @echo " $(GREEN)setup-config$(RESET) - Setup the configuration for OpenDevin by providing LLM API key,"
  163. @echo " LLM Model name, and workspace directory."
  164. @echo " $(GREEN)start-backend$(RESET) - Start the backend server for the OpenDevin project."
  165. @echo " $(GREEN)start-frontend$(RESET) - Start the frontend server for the OpenDevin project."
  166. @echo " $(GREEN)run$(RESET) - Run the OpenDevin application, starting both backend and frontend servers."
  167. @echo " Backend Log file will be stored in the 'logs' directory."
  168. @echo " $(GREEN)help$(RESET) - Display this help message, providing information on available targets."
  169. # Phony targets
  170. .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