dify 本地源码启动
依赖环境
- docker win docker mac
- python 推荐使用 pyenv
- Miniconda 清华镜像
- TensorFlow/Pytorch
git clone https://github.com/langgenius/dify.git
cd docker
docker compose -f docker-compose.middleware.yaml up -d
# 创建名为 Python 3.10 环境
conda create -n py310 python=3.10
# 切换
conda activate py310
# TensorFlow 安装
conda install -c apple tensorflow-deps
pip install tensorflow-macos
pip install tensorflow-metal
# TensorFlow 测试
python
import tensorflow as tf
print("tf version",tf.__version__)
print("tf gpu",tf.test.is_gpu_available())
# Pytorch
conda install pytorch torchvision torchaudio -c pytorch-nightly
# test.py
import torch
if torch.backends.mps.is_available():
mps_device = torch.device("mps")
x = torch.ones(1, device=mps_device)
print (x)
else:
print ("MPS device not found.")
服务端部署
cd api
cp .env.example .env
openssl rand -base64 42
sed -i 's/SECRET_KEY=.*/SECRET_KEY=<your_value>/' .env
# 报错就直接把生成的值复制到 .env 里面
pip install -r requirements.txt
# 执行数据库迁移
flask db upgrade
# 启动服务
flask run --host 0.0.0.0 --port=5001 --debug
# 启动 Worker 服务
# mac
celery -A app.celery worker -P gevent -c 1 -Q dataset,generation,mail --loglevel INFO
# win
celery -A app.celery worker -P solo --without-gossip --without-mingle -Q dataset,generation,mail --loglevel INFO
前端部署
cd web
pnpm i
cp .env.example .env.local
pnpm run build
pnpm start
Ollama
访问 ollama.ai/download 下载
运行:ollama run llava
,可通过 http://localhost:11434 访问。
接入:
- 右上角头像点击,选择设置,选择模型供应商。
- 模型名称:llava
- 基础 URL:
http://localhost:11434
- 是否支持 Vision:是
最后的成果是这样的