Makefile 7.8 KB

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