赞
踩
git clone https://github.com/chatchat-space/Langchain-Chatchat.git
打开第一个窗口 ,创建环境
conda create -n chatchat python=3.1
pip install Poetry
如果遇到网络错误,可以尝试换源
https://mirrors.tuna.tsinghua.edu.cn #清华源https://developer.aliyun.com/mirror #阿里源
示例:pip install Poetry -i https://developer.aliyun.com/mirror
注:小编是用阿里源下载成功的,如果两个都不行,可以搜索一下其他源
下载完以后,进入Langchain-Chatchat/libs/chatchat-server 路径下有个pyproject.toml文件,我们运行以下命令进入
cd Langchain-Chatchat/libs/chatchat-server
vim pyproject.toml #修改文件配置
进入文件后执行shift+g,进入文件最后,然后修改以下行数,把#号删除
如下图:
然后运行如下命令:
poetry install --with lint,test
打开第二个窗口,创建环境
conda create -n xinference python=3.1
conda activate xinference #进入环境
pip install "xinference[all]" -i https://pypi.tuna.tsinghua.edu.cn/simple #下载环境所需包
本地运行Xinference, Xinference 运行大模型,我这里自定义了一个存储日志文件和大模型,embidding模型的路径,如果不自定义一个路径将会下载到默认的一个路径下,这样很容易将我们的系统盘给撑爆,以魔塔社区下载模型为例。
XINFERENCE_HOME=/root/autodl-tmp/Langchain-Chatchat/xinference XINFERENCE_MODEL_SRC=modelscope xinference-local --host 0.0.0.0 --port 9997
#以后每次运行知识库前都要先在xinference环境下运行这个命令,然后打开web页面,加载模型,如果不想每次都打开xinference的web页面,可以选择shell命令,参考xinference框架shell启动文档
注:xinference放到Langchain-Chatchat目录里面,所以XINFERENCE_HOME的路径就是Langchain-Chatchat路径加个xinference
注:打开此链接,如果用的是autodl,需要端口映射,详细请看如下文章:端口映射
模型下载中:
如果嫌麻烦,也可以使用命令加载模型:
xinference launch --model-engine vllm --model-name qwen2-instruct --size-in-billions 7 --model-format pytorch --quantization none
然后下载embedding模型,这里我选择的是bge-large-zh-v1.5版本的embedding模型
命令行运行
xinference launch --model-name bge-large-zh-v1.5 --model-type embedding
或者在web页面运行,如下图:
创建个新窗口(第三个窗口),进入xinference环境,输入xinference list,可以看到模型已经加载成功
然后进入环境是chatchat的窗口,进入/root/autodl-tmp/Langchain-Chatchat/libs/chatchat-server/chatchat路径下,可以看到以下文件:
初始化仓库(使用默认 embedding 模型)
cd Langchain-Chatchat/libs/chatchat-server/chatchat python init_database.py --recreate-vs
初始化仓库(指定 embedding 模型)
python init_database.py --recreate-vs --embed-model=text-embedding-3-small # embedding 模型名称
注:由于模型的默认模型就是bge-large-zh-v1.5,所以我们只需要运行默认embedding模型的命令就可以了,由于我们用的是CPU加载的embedding模型,所以初始化仓库的时候会比较慢,请耐心等待
小技巧:数据加载太慢,我们可以进入Langchain-Chatchat/libs/chatchat-server/chatchat/data/knowledge_base/samples/content 路径下,把里面md后缀文件删的只剩一个,这样模型加载就快了,因为只是模型初始化,里面的文件我们也用不到
数据库初始化完成!!
使用chatchat-config model --show可以查看默认模型
chatchat-config model --show
由于我们加载的是qwen2-instruct模型,而默认的是glm4模型,所以我们需要更改一下模型配置,运行如下命令,把默认模型改成qwen2-instruct
chatchat-config model --default_llm_model qwen2-instruct
启动服务
cd Langchain-Chatchat/libs/chatchat-server/chatchat python startup.py -a
这个时候我们需要做个端口映射,把autodl服务器的8501端口映射到本地的8501
知识库选择
七、mysql查询
进到/root/autodl-tmp/Langchain-Chatchat/libs/chatchat-server/chatchat/configs目录下,修改_model_config.py文件
在主目录有个.chatchat目录,进入/root/.chatchat/workspace/workspace_config.json文件内,修改参数,参数配置_model_config.py的一样
因为我的mysql在我的本地,而我的知识库部署在autodl服务器,正常用本地ip服务器上无法连接到本地mysql的,这个时候我们需要把本地ip变成公网ip,我这里借住路由侠工具,他能可视化的把内网IP变成公网IP,而且送免费的一个G流量,下载链接路由侠
打开路由侠
然后点击创建就好了,把你的公网ip按格式配置就可以了
下面展示小编的查询结果,web页面
后台:
注:经过小编测试,还是不要用glm4-9b-chat来构造sql语句,效果很不好,写的sql错误,导致查询报错
完结!!!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。