langchain本地部署

399 阅读1分钟

conda环境搭建 python3.10

$ conda create --prefix /data/envs/chatchat python=3.10

$ cd /data/envs/chatchat

$ conda activate /data/envs/chatchat

拉取仓库

$ git clone github.com/chatchat-sp…

进入目录

$ cd Langchain-Chatchat

安装全部依赖

$ pip install -r requirements.txt

$ pip install -r requirements_api.txt

$ pip install -r requirements_webui.txt

$ pip install openai==0.28

默认依赖包括基本运行环境(FAISS向量库)。如果要使用 milvus/pg_vector 等向量库,请将 requirements.txt 中相应依赖取消注释再安装。

git lfs下载

$ yum install git-lfs

验证

$ git lfs install Git LFS initialized.

git clone huggingface.co/THUDM/chatg…

git clone huggingface.co/BAAI/bge-la…

#以上两个模型下载很慢,从网上找到模型库,clone下来即可

$ git clone www.modelscope.cn/ZhipuAI/cha…

$ git clone www.modelscope.cn/AI-ModelSco…

复制配置文件

$ python copy_config_example.py

初始化知识库

$ python init_database.py --recreate-vs

修改configs/model_config.py配置文件中模型的路径,建议将两个模型单独放一个文件夹中

MODEL_ROOT_PATH = "/data/envs/chatchat/Langchain-Chatchat/aimodel"

pytorch与cuda版本不一致,先卸载torch、torchvision,然后再安装对应版本

$ pip uninstall torch

$ pip uninstall torchvision

$ pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 --extra-index-url download.pytorch.org/whl/cu113

官网:pytorch.org/get-started…

通过python查看安装版本以及是否可使用

python

import torch

print(torch.version)

1.11.0+cu113

print(torch.cuda.is_available())

True

启动

$ python startup.py -a

##报错:RuntimeError: Failed to import transformers.models.llama.modeling_llama because of the following error (look up to see its traceback): module 'torch' has no attribute 'fx'

##发现是transformers版本问题,transformers 4.35.2 降低4.34.0 $ pip install transformers==4.34.0

重新启动

$ python startup.py -a

启动成功

Chatchat WEBUI Server: http://0.0.0.0:8501

服务器开放端口

$ /sbin/iptables -I INPUT -p tcp --dport 8501 -j ACCEPT

$ /sbin/iptables -I INPUT -p tcp --dport 7861 -j ACCEPT

文章参考:本地搭建chatgpt知识库 - 掘金 (juejin.cn)

模型:(github.com/chatchat-sp…)