Makefile 6.7 KB

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