You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 2.2KB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # Dify Backend API
  2. ## Usage
  3. > [!IMPORTANT]
  4. > In the v0.6.12 release, we deprecated `pip` as the package management tool for Dify API Backend service and replaced it with `poetry`.
  5. 1. Start the docker-compose stack
  6. The backend require some middleware, including PostgreSQL, Redis, and Weaviate, which can be started together using `docker-compose`.
  7. ```bash
  8. cd ../docker
  9. cp middleware.env.example middleware.env
  10. # change the profile to other vector database if you are not using weaviate
  11. docker compose -f docker-compose.middleware.yaml --profile weaviate -p dify up -d
  12. cd ../api
  13. ```
  14. 2. Copy `.env.example` to `.env`
  15. ```cli
  16. cp .env.example .env
  17. ```
  18. 3. Generate a `SECRET_KEY` in the `.env` file.
  19. bash for Linux
  20. ```bash for Linux
  21. sed -i "/^SECRET_KEY=/c\SECRET_KEY=$(openssl rand -base64 42)" .env
  22. ```
  23. bash for Mac
  24. ```bash for Mac
  25. secret_key=$(openssl rand -base64 42)
  26. sed -i '' "/^SECRET_KEY=/c\\
  27. SECRET_KEY=${secret_key}" .env
  28. ```
  29. 4. Create environment.
  30. Dify API service uses [Poetry](https://python-poetry.org/docs/) to manage dependencies. You can execute `poetry shell` to activate the environment.
  31. 5. Install dependencies
  32. ```bash
  33. poetry env use 3.12
  34. poetry install
  35. ```
  36. 6. Run migrate
  37. Before the first launch, migrate the database to the latest version.
  38. ```bash
  39. poetry run python -m flask db upgrade
  40. ```
  41. 7. Start backend
  42. ```bash
  43. poetry run python -m flask run --host 0.0.0.0 --port=5001 --debug
  44. ```
  45. 8. Start Dify [web](../web) service.
  46. 9. Setup your application by visiting `http://localhost:3000`...
  47. 10. If you need to handle and debug the async tasks (e.g. dataset importing and documents indexing), please start the worker service.
  48. ```bash
  49. poetry run python -m celery -A app.celery worker -P gevent -c 1 --loglevel INFO -Q dataset,generation,mail,ops_trace,app_deletion
  50. ```
  51. ## Testing
  52. 1. Install dependencies for both the backend and the test environment
  53. ```bash
  54. poetry install -C api --with dev
  55. ```
  56. 2. Run the tests locally with mocked system environment variables in `tool.pytest_env` section in `pyproject.toml`
  57. ```bash
  58. poetry run -P api bash dev/pytest/pytest_all_tests.sh
  59. ```