langchain本地部署

conda环境搭建 python3.10

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

$ cd /data/envs/chatchat

$ conda activate /data/envs/chatchat

拉取仓库

$ git clone https://github.com/chatchat-space/Langchain-Chatchat.git

进入目录

$ 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 https://huggingface.co/THUDM/chatglm3-6b

git clone https://huggingface.co/BAAI/bge-large-zh

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

$ git clone https://www.modelscope.cn/ZhipuAI/chatglm3-6b.git

$ git clone https://www.modelscope.cn/AI-ModelScope/bge-large-zh.git

复制配置文件

$ 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 torch1.11.0+cu113 torchvision0.12.0+cu113 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu113

官网:https://pytorch.org/get-started/previous-versions/

通过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)

模型:(https://github.com/chatchat-space/Langchain-Chatchat?tab=readme-ov-file)

  • 14
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值