Langchain-Chatchat-0.3.0部署过程及常见报错记录

2024-7-15 更新

由于项目已更新至0.3.1版本,其命令行调用方式发生调整,本文“步骤4”部分内容已不再适用,请依据项目 README 进行操作。

Langchain-Chatchat-0.3.0发布后部署架构发生一些变化,这里简单记录一下自己踩坑的经历,包括两部分:

  1. 部署过程
  2. 常见报错记录

部署过程

简单来说可以分为以下步骤:

  1. 安装 Langchain-Chatchat
  2. 安装模型部署框架(Langchain-Chatchat0.3.0需接入第三方模型部署框架,这里选择XInference)
  3. 运行模型部署框架,并加载模型(启动 Langchain-Chatchat 项目前,需首先进行模型推理框架的运行,并加载所需使用的模型。)
  4. 运行 Langchain-Chatchat

接下来我们进行部署:

(参考:Langchain-Chatchat官方安装说明XInference官方安装说明

1 安装 Langchain-Chatchat

# 1.给langchain-chatchat创建一个虚拟环境,采用python3.10
conda create -n langchain-chatchat-x python==3.10
conda activate langchain-chatchat-x

# 2.安装langchain-chatchat,这里安装xinference版
pip install "langchain-chatchat[xinference]" -U

2 安装模型部署框架

# 1.为 Xinference 创建一个虚拟环境,采用 python3.10
conda create -n xinference python==3.10
conda activate xinference

# 2.安装 Xinference 框架,这里我们安装 [Transformers] 引擎,因为该引擎支持几乎有所的最新模型,这是 Pytorch 模型默认使用的引擎
# 注:由于模型推理引擎有多种,如 [Transformers]、[vLLM]、[SGLang] 等。可以根据自己的模型支持的引擎进行选择
pip install "xinference[transformers]"

 3 运行模型部署框架,并加载模型

# 1.运行 Xinference 框架,默认9997端口
xinference-local --host 0.0.0.0 --port 9997
# 此时可以通过访问 http://0.0.0.0:9997/ 进入 Xinference ui界面

# 2. 自行下载 LLM 模型和 Embedding 模型(HuggingFace不通可以去ModelScope)
# 如果是自定义的模型需要注册:xinference register --model-type <model_type> --file model.json --persist

# 3.加载 LLM 模型,这里使用了自定义的glm4-chat模型
xinference launch --model-name custom-glm4-chat --model-format pytorch --model-engine Transformers

# 4.加载 Embedding 模型,这里使用了自定义的bge-large-zh-v1.5模型
xinference launch --model-name custom-bge-large-zh-v1.5 --model-type embedding

4  运行 Langchain-Chatchat

# 1.clone项目
git clone https://github.com/chatchat-space/Langchain-Chatchat.git

# 2.激活环境,安装项目
conda activate chatchat-x

# 3.配置默认模型信息,这里使用我自定义的custom-glm4-chat和custom-bge-large-zh-v1.5
chatchat-config model --default_llm_model  custom-glm4-chat
chatchat-config model --default_embedding_model custom-bge-large-zh-v1.5
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\": []
}]"

# 4.初始化知识库
chatchat-kb -r --embed-model=custom-bge-large-zh-v1.5

# 5.启动chatchat
chatchat -a

常见报错

1  Connection refused

urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=9997): Max retries exceeded with url: /v1/cluster/auth (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7febe88d6200>: Failed to establish a new connection: [Errno 111] Connection refused'))

错误原因

未运行模型部署框架

解决方法

按照上文步骤3中开启xinference

xinference-local --host 0.0.0.0 --port 9997

2 知识库初始化错误

卡在warnings.warn(

错误原因

当前0.3.0版本项目bug,正在fix中

解决办法

跳过这一步骤,不初始化知识库,直接运行

chatchat -a

3 在chatchat问答页面中出现peer closed connection without sending complete message body

RemoteProtocolError: peer closed connection without sending complete message body (incomplete chunked read)

解决办法

把openai版本从1.1换成0.28.1

如果不行就删除现有虚拟环境,重新创建,还不行就基于python3.9重新创建

  • 23
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值