无坑!部署langchain-chatchat + glm4-9b-chat,轻松实现知识库智能问答!

Langchain-chatchat 最新版本0.3.0地址 谢谢你的点赞/关注支持

通过该项目可以轻松实现智能问答,由于chatglm4的开源,该项目最新版本0.3.0与0.2.0版本部署有所不同。

这里 llm 模型使用 glm4-9b-chat
embedding 模型使用 bge-large-zh-v1.5

配置虚拟环境

  1. 创建虚拟环境
    conda create --name chat3 python=3.10.9
  2. 激活虚拟环境
    conda activate chat3

安装项目库

从 0.3.0 版本起,Langchain-Chatchat 提供以 Python 库形式的安装方式

为确保所使用的 Python 库为最新版,建议使用官方 Pypi 源或清华源。

因模型部署框架 Xinference 接入 Langchain-Chatchat 时需要额外安装对应的 Python 依赖库,因此如需搭配 Xinference 框架使用时,建议使用如下安装方式:

pip install "langchain-chatchat[xinference]" -U

模型推理框架并加载模型

从 0.3.0 版本起,Langchain-Chatchat 不再根据用户输入的本地模型路径直接进行模型加载,涉及到的模型种类包括 LLM、Embedding、Reranker 及后续会提供支持的多模态模型等,均改为支持市面常见的各大模型推理框架接入,如 Xinference、Ollama、LocalAI、FastChat、One API 等。

因此,请确认在启动 Langchain-Chatchat 项目前,首先进行模型推理框架的运行,并加载所需使用的模型。

这里以 Xinference 举例

为避免依赖冲突,请将 Langchain-Chatchat 和模型部署框架如 Xinference 等放在不同的 Python 虚拟环境中

具体 Xinference 部署模型教程请参考: 无错误!xinference部署本地模型glm4-9b-chat、bge-large-zh-v1.5

修改 Langchain-Chatchat 配置

  1. 修改默认 llm 模型(模型名称和在xinference中配置的相同)
    chatchat-config model --default_llm_model custom-glm4-chat

  2. 修改默认 embedding 模型
    chatchat-config model --default_embedding_model custom-bge-large-zh-v1.5

  3. 配置模型推理框架 xinference

chatchat-config model --set_model_platforms "[{
    \"platform_name\": \"xinference\",
    \"platform_type\": \"xinference\",
    \"api_base_url\": \"http://127.0.0.1:9997/v1\",
    \"api_key\": \"EMPT\",
    \"api_concurrencies\": 5,
    \"llm_models\": [
        \"custom-glm4-chat\"
    ],
    \"embed_models\": [
        \"custom-bge-large-zh-v1.5\"
    ],
    \"image_models\": [],
    \"reranking_models\": [],
    \"speech2text_models\": [],
    \"tts_models\": []
}]"

这里仅展示必要的修改,其他 查看/修改 配置的方法可参见官方文档。https://github.com/chatchat-space/Langchain-Chatchat/tree/master

启动项目

  1. 初始化知识库 chatchat-kb -r

  2. 启动项目 chatchat -a

配置监听地址

如需通过机器ip 进行访问(如 Linux 系统), 需要将监听地址修改为 0.0.0.0。

chatchat-config server --default_bind_host=0.0.0.0

你可能感兴趣的:(langchain,langchain)