##### 说明:这个实验必须使用GPU,我选的RTX 4090D * 1卡,不管学习还是用大模型,都要用带GPU的服务器,不要想在本机测试,完全无意义。 ##### GPU服务器使用:AutoDL ##### 向量模型:bge-large-zh-v1.5 ##### 大模型:glm4-chat ##### 推理框架:xinference ##### 环境管理工具:conda ##### 还涉及到一些其他概念:如Cuda、Pytorch、pip、transformers 这些概念对java开发的人都没有接触过,大家可以自行了解。 ##### Langchain-Chatchat是python语言开发的,需要python运行环境,创建AutoDL实例时可以可以选择带有python环境和Cuda的镜像 ![1725517840071](C:\Users\tianzhidan\AppData\Roaming\Typora\typora-user-images\1725517840071.png) 如果带有GPU的物理机,可以通过拉取网上已经有的镜像。 https://github.com/chatchat-space/Langchain-Chatchat ![1724656326198](C:\Users\tianzhidan\AppData\Roaming\Typora\typora-user-images\1724656326198.png) #终端拉取Chatchat git clone https://github.com/chatchat-space/Langchain-Chatchat.git conda create -n xinference python==3.11 conda init #关闭终端,重新打开 ![1724656690893](C:\Users\tianzhidan\AppData\Roaming\Typora\typora-user-images\1724656690893.png) #进入xinference虚拟环境 conda activate xinference #下载xinference依赖包 pip install xinference -i https://pypi.tuna.tsinghua.edu.cn/simple pip install "xinference[transformers]" -i https://pypi.tuna.tsinghua.edu.cn/simple pip install "xinference[vllm]" -i https://pypi.tuna.tsinghua.edu.cn/simple pip install sentence-transformers XINFERENCE_HOME=/root/autodl-tmp/xinference XINFERENCE_MODEL_SRC=modelscope xinference-local --host 0.0.0.0 --port 9997 #再打开一个终端,第一次拉起会自动安装 conda activate xinference xinference launch --model-name bge-large-zh-v1.5 --model-type embedding xinference launch --model-engine vllm --model-name glm4-chat --size-in-billions 9 --model-format pytorch --quantization none #试了Qwen2-1.5B模型会报错,不知道是不是参数传的不对:Model not found, name: Qwen2-1.5B, format: None, size: None, quantization: none #xinference launch --model-engine vllm --model-name Qwen2-1.5B --quantization none xinference list #再打开一个终端 onda create -n chatglm-4 python==3.11 conda init #这里是python的虚拟环境,名字可以自己起 conda activate chatglm-4 #下载langchain-chatchat 依赖包 pip install langchain-chatchat -U -i https://pypi.tuna.tsinghua.edu.cn/simple #下载langchain-chatchat与 xinference的依赖包 pip install langchain-chatchat[xinference] -U -i https://pypi.tuna.tsinghua.edu.cn/simple #进入Langchain-Chatchat路径 cd Langchain-Chatchat #初始化向量库 chatchat init #产生一个data文件夹,知识文件在里面 ![1724765540269](C:\Users\tianzhidan\AppData\Roaming\Typora\typora-user-images\1724765540269.png) #修改配置文件model_settings.yaml ![1724765792632](C:\Users\tianzhidan\AppData\Roaming\Typora\typora-user-images\1724765792632.png) #初始化知识库 chatchat kb -r ![1724765953068](C:\Users\tianzhidan\AppData\Roaming\Typora\typora-user-images\1724765953068.png) #启动chatchat chatchat start -a #连接本地端口与服务器实例端口 ![1724766445909](C:\Users\tianzhidan\AppData\Roaming\Typora\typora-user-images\1724766445909.png) #执行命令 ssh -CNg -L 6006:127.0.0.1:8501 root@connect.cqa1.seetacloud.com -p 44602 ![1724766543283](C:\Users\tianzhidan\AppData\Roaming\Typora\typora-user-images\1724766543283.png) ![1724766554666](C:\Users\tianzhidan\AppData\Roaming\Typora\typora-user-images\1724766554666.png) #复制完直接ctrl+v,回车后不提示密码错误就可以。 #本地浏览器输入:127.0.0.1:6006启动客户端 ![1724766907460](C:\Users\tianzhidan\AppData\Roaming\Typora\typora-user-images\1724766907460.png)