笔记笔记
  • Home
  • AI&ML
  • Example
  • Zoo
  • 关于
⌘ K
简介
RAGFlow
Ollama
Stable Diffusion
ComfyUI
PyTorch
Paddle
关注的模型
关注的组织
目标检测
研究
YOLO
其他
文档技巧
最后更新时间:
Copyright © 2023-2024 | Powered by dumi | GuoDapeng | 冀ICP备20004032号-1 | 冀公网安备 冀公网安备 13024002000293号

TABLE OF CONTENTS

‌
‌
‌
‌

RAGFlow

Apple Silicon

WARNING

如果是 x86 电脑,不需要这么繁琐的步骤。

# 克隆 ragflow 仓库
git clone https://github.com/infiniflow/ragflow.git

配置环境变量

vi docker/.env

打开 macOS 优化

# Optimizations for MacOS
# Uncomment the following line if your OS is MacOS:
MACOS=1

构建 infiniflow/ragflow_deps 图像

构建 RAGFlow Docker 镜像

# 进入项目根目录
cd ragflow/
poetry env use python3
source .venv/bin/activate
# 这一步是在 https://github.com/infiniflow/ragflow/issues/5367 这里提到的
pip3 install huggingface_hub nltk --index-url https://mirrors.aliyun.com/pypi/simple/

pip3 config list 查看 pip3 配置。

修改 download_deps.py 脚本

urllib.request 修改为 requests,避免出现证书错误。

# import urllib.request
import requests
for url in urls:
filename = url.split("/")[-1]
print(f"Downloading {url}...")
if not os.path.exists(filename):
# urllib.request.urlretrieve(url, filename)
response = requests.get(url, verify=True)
with open(filename, 'wb') as f:
f.write(response.content)

遇到以下错误时,添加以下代码解决:

Downloading nltk wordnet...
[nltk_data] Error loading wordnet: <urlopen error [SSL:
[nltk_data] CERTIFICATE_VERIFY_FAILED] certificate verify failed:
[nltk_data] unable to get local issuer certificate (_ssl.c:1000)>

可能上面的问题也可以这么解决,因为下载太慢,我没有测试。

import ssl
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
pass
else:
ssl._create_default_https_context = _create_unverified_https_context
# 漫长的下载
python3 download_deps.py
# 构建镜像
docker build -f Dockerfile.deps -t infiniflow/ragflow_deps .
docker build --build-arg NEED_MIRROR=1 --build-arg LIGHTEN=1 -f Dockerfile -t infiniflow/ragflow:nightly-slim .
# 为镜像打上最新标签
docker tag infiniflow/ragflow:nightly-slim infiniflow/ragflow:latest
docker tag infiniflow/ragflow:nightly-slim infiniflow/ragflow:v0.17.0
# 重新构建镜像
docker build --no-cache --build-arg NEED_MIRROR=1 --build-arg LIGHTEN=1 -f Dockerfile -t infiniflow/ragflow:nightly-slim .

启动服务

# 拉取 ubuntu:22.04;先使用代理拉取,避免容器内还使用代理,造成安装缓慢。
docker pull docker.io/library/ubuntu:22.04
cd ragflow/docker
docker compose -f docker-compose-macos.yml pull
docker compose -f docker-compose-macos.yml up -d

Xinference

Xinference - 文档

# MLX-lm 用来在苹果 silicon 芯片上提供高效的 LLM 推理
pip install "xinference[mlx]" --index-url https://mirrors.aliyun.com/pypi/simple/
XINFERENCE_MODEL_SRC=modelscope XINFERENCE_HOME=./xinference xinference-local --host 0.0.0.0 --port 9997
# 这样可以启动下载好的模型
xinference launch --model-name bge-large-zh-v1.5 --model-type embedding
xinference launch --model-name bge-reranker-v2-m3 --model-type rerank
xinference launch --model-name ChatTTS --model-type audio
xinference launch --model-name SenseVoiceSmall --model-type audio

在 http://127.0.0.1:9997 里配置 bge-reranker-v2-m3 模型。

下载模型时选择 modelscope 下载中心,要不特别慢。

系统模型设置

Supported models - 支持的模型

--- 查看模型设置
SELECT tenant_id, llm_factory, model_type, llm_name, max_tokens
FROM tenant_llm
WHERE tenant_id = 'df75265cf7da11ef9a840242ac120006';

聊天(chat)模型

ollama run deepseek-r1:70b

基础 Url:http://host.docker.internal:11434

嵌入(embedding)模型

ollama run shaw/dmeta-embedding-zh:latest

基础 Url:http://host.docker.internal:11434

Img2txt模型

ollama run llava:34b

基础 Url:http://host.docker.internal:11434

Sequence2txt 模型

pip3 install funasr

Xinference -> Audio Models -> SenseVoiceSmall

基础 Url:http://host.docker.internal:9997

重排(rerank)模型

pip3 install sentence-transformers

Xinference -> Rerank Models -> bge-reranker-v2-m3

基础 Url:http://host.docker.internal:9997

TTS 模型

pip3 install ChatTTS

Xinference -> Audio Models -> ChatTTS

基础 Url:http://host.docker.internal:9997

其他

出现如下错误,可能是知识库被删除过,重新设置助理的知识库。

ERROR: Knowledge bases use different embedding models.