Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # Dify Backend API
  2. ## Usage
  3. > [!IMPORTANT]
  4. >
  5. > In the v1.3.0 release, `poetry` has been replaced with
  6. > [`uv`](https://docs.astral.sh/uv/) as the package manager
  7. > for Dify API backend service.
  8. 1. Start the docker-compose stack
  9. The backend require some middleware, including PostgreSQL, Redis, and Weaviate, which can be started together using `docker-compose`.
  10. ```bash
  11. cd ../docker
  12. cp middleware.env.example middleware.env
  13. # change the profile to other vector database if you are not using weaviate
  14. docker compose -f docker-compose.middleware.yaml --profile weaviate -p dify up -d
  15. cd ../api
  16. ```
  17. 2. Copy `.env.example` to `.env`
  18. ```cli
  19. cp .env.example .env
  20. ```
  21. 3. Generate a `SECRET_KEY` in the `.env` file.
  22. bash for Linux
  23. ```bash for Linux
  24. sed -i "/^SECRET_KEY=/c\SECRET_KEY=$(openssl rand -base64 42)" .env
  25. ```
  26. bash for Mac
  27. ```bash for Mac
  28. secret_key=$(openssl rand -base64 42)
  29. sed -i '' "/^SECRET_KEY=/c\\
  30. SECRET_KEY=${secret_key}" .env
  31. ```
  32. 4. Create environment.
  33. Dify API service uses [UV](https://docs.astral.sh/uv/) to manage dependencies.
  34. First, you need to add the uv package manager, if you don't have it already.
  35. ```bash
  36. pip install uv
  37. # Or on macOS
  38. brew install uv
  39. ```
  40. 5. Install dependencies
  41. ```bash
  42. uv sync --dev
  43. ```
  44. 6. Run migrate
  45. Before the first launch, migrate the database to the latest version.
  46. ```bash
  47. uv run flask db upgrade
  48. ```
  49. 7. Start backend
  50. ```bash
  51. uv run flask run --host 0.0.0.0 --port=5001 --debug
  52. ```
  53. 8. Start Dify [web](../web) service.
  54. 9. Setup your application by visiting `http://localhost:3000`.
  55. 10. If you need to handle and debug the async tasks (e.g. dataset importing and documents indexing), please start the worker service.
  56. ```bash
  57. uv run celery -A app.celery worker -P gevent -c 1 --loglevel INFO -Q dataset,generation,mail,ops_trace,app_deletion,plugin
  58. ```
  59. Addition, if you want to debug the celery scheduled tasks, you can use the following command in another terminal:
  60. ```bash
  61. uv run celery -A app.celery beat
  62. ```
  63. ## Testing
  64. 1. Install dependencies for both the backend and the test environment
  65. ```bash
  66. uv sync --dev
  67. ```
  68. 2. Run the tests locally with mocked system environment variables in `tool.pytest_env` section in `pyproject.toml`
  69. ```bash
  70. uv run -P api bash dev/pytest/pytest_all_tests.sh
  71. ```