摘要:本文在Rocky Linux下部署Langchain-Chatchat,利用langchan思想实现的基于本地知识库的问答应用,目标是建立对中文场景与开源模型支持友好、可离线运行的知识库问答解决方案。Rocky 版本9.5,python版本3.11或者3.10,Langchain-Chatchat版本0.3.1.3,xinference版本0.15.4。大语言模型采用glm-4-9b-chat,文本嵌入模型采用bge-large-zh-v1.5。
#1.获取源代码
#拉取Langchain-Chatchat项目源代码
git clone https://github.com/chatchat-space/Langchain-Chatchat.git
#进入项目目录
cd Langchain-Chatchat/
#2.建虚拟环境
#创建新conda虚拟环境 langchain-chatchat
conda create -n langchain-chatchat python=3.11
#激活 langchain-chatchat虚拟环境
conda activate langchain-chatchat
#3.安装依赖
#安装Langchain-Chatchat依赖
pip install "langchain-chatchat[xinference]" -U -i https://pypi.tuna.tsinghua.edu.cn/simple
#4.部署并启动大模型管理框架
#安装大模型管理框架xinference
#创建虚拟环境xinference
conda create -n xinference python=3.11
#切换到虚拟环境xinference
conda activate xinference
#安装支撑库
pip install llama_cpp_python-0.3.4-cp311-cp311-linux_x86_64.whl
pip install sentence-transformers -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install tiktoken -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install "xinference[all]"==0.15.4 -i https://pypi.tuna.tsinghua.edu.cn/simple
#前台启动xinference,已默认注释掉
#xinference-local --host 0.0.0.0 --port 9997
#后台启动大模型管理框架xinference
nohup xinference-local --host 0.0.0.0 --port 9997 >> /aiwork/logs/xinference.log 2>&1 &
#访问xinference UI,链接:http://192.168.20.119:9997/ui
#添加自定义大语言模型
#自定义大语言模型添加成功后:
#点方块,启动自定义大语言模型(旨在理解和生成人类语言的人工智能模型)
#添加自定义文本嵌入模型(文本嵌入模型是指将高维度的数据,例如文字、图片、视频,映射到低维度空间的过程,嵌入向量就是一个N维的实值向量,将输入的数据表示成一个连续的数值空间中的点,目的是让机器更好的理解和处理)
#点方块启动自定义文本嵌入模型
#点启动按钮后:
#访问http://192.168.20.119:9997/docs
#下载glm4模型