Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # Dify Backend API
  2. ## Usage
  3. 1. Start the docker-compose stack
  4. The backend require some middleware, including PostgreSQL, Redis, and Weaviate, which can be started together using `docker-compose`.
  5. ```bash
  6. cd ../docker
  7. docker-compose -f docker-compose.middleware.yaml -p dify up -d
  8. cd ../api
  9. ```
  10. 2. Copy `.env.example` to `.env`
  11. 3. Generate a `SECRET_KEY` in the `.env` file.
  12. ```bash
  13. sed -i "/^SECRET_KEY=/c\SECRET_KEY=$(openssl rand -base64 42)" .env
  14. ```
  15. 4. Create environment.
  16. - Anaconda
  17. If you use Anaconda, create a new environment and activate it
  18. ```bash
  19. conda create --name dify python=3.10
  20. conda activate dify
  21. ```
  22. - Poetry
  23. If you use Poetry, you don't need to manually create the environment. You can execute `poetry shell` to activate the environment.
  24. 5. Install dependencies
  25. - Anaconda
  26. ```bash
  27. pip install -r requirements.txt
  28. ```
  29. - Poetry
  30. ```bash
  31. poetry install
  32. ```
  33. In case of contributors missing to update dependencies for `pyproject.toml`, you can perform the following shell instead.
  34. ```base
  35. poetry shell # activate current environment
  36. poetry add $(cat requirements.txt) # install dependencies of production and update pyproject.toml
  37. poetry add $(cat requirements-dev.txt) --group dev # install dependencies of development and update pyproject.toml
  38. ```
  39. 6. Run migrate
  40. Before the first launch, migrate the database to the latest version.
  41. ```bash
  42. flask db upgrade
  43. ```
  44. ⚠️ If you encounter problems with jieba, for example
  45. ```
  46. > flask db upgrade
  47. Error: While importing 'app', an ImportError was raised:
  48. ```
  49. Please run the following command instead.
  50. ```
  51. pip install -r requirements.txt --upgrade --force-reinstall
  52. ```
  53. 7. Start backend:
  54. ```bash
  55. flask run --host 0.0.0.0 --port=5001 --debug
  56. ```
  57. 8. Setup your application by visiting http://localhost:5001/console/api/setup or other apis...
  58. 9. If you need to debug local async processing, please start the worker service by running
  59. `celery -A app.celery worker -P gevent -c 1 --loglevel INFO -Q dataset,generation,mail`.
  60. The started celery app handles the async tasks, e.g. dataset importing and documents indexing.
  61. ## Testing
  62. 1. Install dependencies for both the backend and the test environment
  63. ```bash
  64. pip install -r requirements.txt -r requirements-dev.txt
  65. ```
  66. 2. Run the tests locally with mocked system environment variables in `tool.pytest_env` section in `pyproject.toml`
  67. ```bash
  68. dev/pytest/pytest_all_tests.sh
  69. ```