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.5KB

2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. docker compose -f docker-compose.middleware.yaml -p dify up -d
  11. cd ../api
  12. ```
  13. 2. Copy `.env.example` to `.env`
  14. 3. Generate a `SECRET_KEY` in the `.env` file.
  15. ```bash for Linux
  16. sed -i "/^SECRET_KEY=/c\SECRET_KEY=$(openssl rand -base64 42)" .env
  17. ```
  18. ```bash for Mac
  19. secret_key=$(openssl rand -base64 42)
  20. sed -i '' "/^SECRET_KEY=/c\\
  21. SECRET_KEY=${secret_key}" .env
  22. ```
  23. 4. Create environment.
  24. Dify API service uses [Poetry](https://python-poetry.org/docs/) to manage dependencies. You can execute `poetry shell` to activate the environment.
  25. 5. Install dependencies
  26. ```bash
  27. poetry env use 3.10
  28. poetry install
  29. ```
  30. In case of contributors missing to update dependencies for `pyproject.toml`, you can perform the following shell instead.
  31. ```bash
  32. poetry shell # activate current environment
  33. poetry add $(cat requirements.txt) # install dependencies of production and update pyproject.toml
  34. poetry add $(cat requirements-dev.txt) --group dev # install dependencies of development and update pyproject.toml
  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 debug local async processing, 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. The started celery app handles the async tasks, e.g. dataset importing and documents indexing.
  52. ## Testing
  53. 1. Install dependencies for both the backend and the test environment
  54. ```bash
  55. poetry install --with dev
  56. ```
  57. 2. Run the tests locally with mocked system environment variables in `tool.pytest_env` section in `pyproject.toml`
  58. ```bash
  59. cd ../
  60. poetry run -C api bash dev/pytest/pytest_all_tests.sh
  61. ```