方式一:通过命令方式搭建
搭建该项目分为两部分:安装 xinference 框架以载入 LLM 和嵌入模型,以及配置 Langchain-Chatchat 项目。
第一步:创建 xinference 的 conda 环境
conda create -n xinference python=3.10
进入该环境:
conda activate xinference
第二步:安装 xinference 框架
pip install "xinference[transformers]" -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
拉起 xinference 服务:
XINFERENCE_HOME=自定义路径 xinference-local --host 0.0.0.0 --port 9997
详细信息请查看 xinference 官网。注意不同模型要求的引擎可能不同(如 Transformers),请根据模型查询官方文档。
第三步:装载 LLM 模型
确保模型文件完整后再加载。使用本地下载模型或参考官网自动下载。
xinference launch --model-engine Transformers --model-name qwen-chat --size-in-billions 7 --model-format pytorch --quantization none --model_path ~/.cache/modelscope/hub/Qwen/Qwen-7B-Chat
参数说明:
--model-name:固定为模型注册名,不可随意更改。--model_path:本地模型存储路径,若使用 modelscope 下载通常在~/.cache/modelscope/hub下。--model-engine:在 xinference 管理页面查看对应引擎类型。
第四步:装载嵌入模型
例如使用 bge-large-zh-v1.5:
xinference launch --model-name bge-large-zh-v1.5 --model-type embedding --model_path ~/.cache/modelscope/hub/Xorbits/bge-large-zh-v1.5
第五步:创建 chatchat 的环境
conda create -n chatchat python=3.10
conda activate chatchat
第六步:安装 Langchain-Chatchat 项目
pip install "langchain-chatchat[xinference]" -U -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
第七步:初始化项目配置与数据目录
设置 Chatchat 存储配置文件和数据文件的根目录(可选):
# Linux or macOS
export CHATCHAT_ROOT=/path/to/chatchat_data
# Windows
set CHATCHAT_ROOT=/path/to/chatchat_data
若不设置环境变量,则自动使用当前目录。
第八步:执行初始化
chatchat init
该命令会创建数据目录、复制知识库内容并生成默认 yaml 配置文件。
第九步:修改配置文件
配置模型(model_settings.yaml) 根据步骤中使用的模型推理框架与加载模型进行配置,主要修改以下内容:
DEFAULT_LLM_MODEL: qwen1.5-chat
DEFAULT_EMBEDDING_MODEL: bge-large-zh-v1.5
在 MODEL_PLATFORMS 中修改对应模型平台信息。
配置知识库路径(basic_settings.yaml)
默认知识库位于 CHATCHAT_ROOT/data/knowledge_base。如需修改存储位置或数据库连接 URI,可在此调整。
配置知识库(kb_settings.yaml)
默认使用 FAISS 知识库,如需切换其他类型可修改 DEFAULT_VS_TYPE 和 kbs_config。
第十步:初始化知识库
chatchat kb -r
第十一步:启动项目
chatchat start -a
启动成功后应显示 Web 界面。
注意事项: 若部署后无法对话,可能是 xinference 版本兼容性问题,建议降低 xinference 版本至稳定版(如 0.15.3)。
pip install xinference==0.15.3 -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
方式二:通过网页搭建
使用网页搭建与命令方式类似,区别在于通过 Xinference 网页界面装载模型。
- 安装并拉起 Xinference 服务:
XINFERENCE_HOME=自定义路径 xinference-local --host 0.0.0.0 --port 9997 - 访问
http://127.0.0.1:9997/ui。 - 在网页中注册模型,选择引擎并点击 Run 加载。
- 嵌入模型加载方式类似。
- 后续步骤(环境创建、安装、配置、启动)与命令方式一致。


