win10 Langchain-chatchat 知识库本地搭建记录

一、clone源码

git clone https://github.com/chatchat-space/Langchain-Chatchat.git

二、环境准备

conda create -n Chatchat python==3.10
conda activate Chatchat
​

三、模型配置

model_config.py 中

​
# 选用的 Embedding 名称
EMBEDDING_MODEL = "m3e-base"
​
LLM_MODELS = ["zhipu-api"] 
​
ONLINE_LLM_MODEL = {
    # 具体注册及api key获取请前往 http://open.bigmodel.cn
    "zhipu-api": {
        "api_key": "你自己的智普API key",
        "version": "chatglm_turbo",  # 可选包括 "chatglm_turbo"
        "provider": "ChatGLMWorker",
    },
 }
    
    MODEL_PATH = {
    "embed_model": {
        "zhipu-api": "lucidrains/GLM-130B",
        "m3e-base": "G:\AIGC\Langchain\m3e-base-main",
    },
    
    "llm_model": {
        "zhipu-api": "lucidrains/GLM-130B",
     }
  }

四、报错问题

python init_database.py --recreate-vs 初始数据库失败:

(langchain) G:\AIGC\Langchain\Langchain-Chatchat>
(langchain) G:\AIGC\Langchain\Langchain-Chatchat>python init_database.py --recreate-vs
recreating all vector stores
2023-12-19 17:02:47,732 - faiss_cache.py[line:80] - INFO: loading vector store in 'samples/vector_store/bge-large-zh' from disk.
2023-12-19 17:02:51,277 - SentenceTransformer.py[line:66] - INFO: Load pretrained SentenceTransformer: BAAI/bge-large-zh
2023-12-19 17:03:33,432 - embeddings_api.py[line:39] - ERROR: (MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /api/models/BAAI/bge-large-zh (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x000001F06C868BE0>, 'Connection to huggingface.co timed out. (connect timeout=None)'))"), '(Request ID: 149213c1-2ec8-4340-90cd-f6d60fdde1da)')
AttributeError: 'NoneType' object has no attribute 'conjugate'
​
The above exception was the direct cause of the following exception:
​
Traceback (most recent call last):
  File "G:\AIGC\Langchain\Langchain-Chatchat\init_database.py", line 108, in <module>
    folder2db(kb_names=args.kb_name, mode="recreate_vs", embed_model=args.embed_model)
  File "G:\AIGC\Langchain\Langchain-Chatchat\server\knowledge_base\migrate.py", line 121, in folder2db
    kb.create_kb()
  File "G:\AIGC\Langchain\Langchain-Chatchat\server\knowledge_base\kb_service\base.py", line 81, in create_kb
    self.do_create_kb()
  File "G:\AIGC\Langchain\Langchain-Chatchat\server\knowledge_base\kb_service\faiss_kb_service.py", line 47, in do_create_kb
    self.load_vector_store()
  File "G:\AIGC\Langchain\Langchain-Chatchat\server\knowledge_base\kb_service\faiss_kb_service.py", line 28, in load_vector_store
    return kb_faiss_pool.load_vector_store(kb_name=self.kb_name,
  File "G:\AIGC\Langchain\Langchain-Chatchat\server\knowledge_base\kb_cache\faiss_cache.py", line 90, in load_vector_store
    vector_store = self.new_vector_store(embed_model=embed_model, embed_device=embed_device)
  File "G:\AIGC\Langchain\Langchain-Chatchat\server\knowledge_base\kb_cache\faiss_cache.py", line 48, in new_vector_store
    vector_store = FAISS.from_documents([doc], embeddings, normalize_L2=True)
  File "F:\Anaconda3\envs\langchain\lib\site-packages\langchain_core\vectorstores.py", line 510, in from_documents
    return cls.from_texts(texts, embedding, metadatas=metadatas, **kwargs)
  File "F:\Anaconda3\envs\langchain\lib\site-packages\langchain\vectorstores\faiss.py", line 911, in from_texts
    embeddings = embedding.embed_documents(texts)
  File "G:\AIGC\Langchain\Langchain-Chatchat\server\knowledge_base\kb_service\base.py", line 399, in embed_documents
    return normalize(embeddings).tolist()
  File "G:\AIGC\Langchain\Langchain-Chatchat\server\knowledge_base\kb_service\base.py", line 38, in normalize
    norm = np.linalg.norm(embeddings, axis=1)
  File "<__array_function__ internals>", line 200, in norm
  File "F:\Anaconda3\envs\langchain\lib\site-packages\numpy\linalg\linalg.py", line 2541, in norm
    s = (x.conj() * x).real
TypeError: loop of ufunc does not support argument 0 of type NoneType which has no callable conjugate method

解决方法:

EMBEDDING_MODEL 改成bge-large-zh

然后清空knowledge_base 重新初始化向量库即可。

启动startup.py

python startup.py -a

2023-12-19 15:44:46,117 - utils.py[line:24] - ERROR: object of type 'NoneType' has no len()
Traceback (most recent call last):
  File "G:\AIGC\Langchain\Langchain-Chatchat\server\utils.py", line 22, in wrap_done
    await fn
  File "F:\Anaconda3\envs\langchain\lib\site-packages\langchain\chains\base.py", line 381, in acall
    raise e
  File "F:\Anaconda3\envs\langchain\lib\site-packages\langchain\chains\base.py", line 375, in acall
    await self._acall(inputs, run_manager=run_manager)
  File "F:\Anaconda3\envs\langchain\lib\site-packages\langchain\chains\llm.py", line 275, in _acall
    response = await self.agenerate([inputs], run_manager=run_manager)
  File "F:\Anaconda3\envs\langchain\lib\site-packages\langchain\chains\llm.py", line 142, in agenerate
    return await self.llm.agenerate_prompt(
  File "F:\Anaconda3\envs\langchain\lib\site-packages\langchain_core\language_models\chat_models.py", line 501, in agenerate_prompt
    return await self.agenerate(
  File "F:\Anaconda3\envs\langchain\lib\site-packages\langchain_core\language_models\chat_models.py", line 461, in agenerate
    raise exceptions[0]
  File "F:\Anaconda3\envs\langchain\lib\site-packages\langchain_core\language_models\chat_models.py", line 564, in _agenerate_with_cache
    return await self._agenerate(
  File "F:\Anaconda3\envs\langchain\lib\site-packages\langchain_community\chat_models\openai.py", line 518, in _agenerate
    return await agenerate_from_stream(stream_iter)
  File "F:\Anaconda3\envs\langchain\lib\site-packages\langchain_core\language_models\chat_models.py", line 81, in agenerate_from_stream
    async for chunk in stream:
  File "F:\Anaconda3\envs\langchain\lib\site-packages\langchain_community\chat_models\openai.py", line 489, in _astream
    if len(chunk["choices"]) == 0:
TypeError: object of type 'NoneType' has no len()
2023-12-19 15:44:46,122 - utils.py[line:27] - ERROR: TypeError: Caught exception: object of type 'NoneType' has no len()

启动 webui:

streamlit run webui.py

(langchain) G:\AIGC\Langchain\Langchain-Chatchat>
(langchain) G:\AIGC\Langchain\Langchain-Chatchat>streamlit run webui.py
​
  You can now view your Streamlit app in your browser.
​
  Local URL: http://localhost:8501
  Network URL: http://192.168.43.195:8501
​
2023-12-19 14:21:27,722 - utils.py[line:95] - ERROR: ConnectError: error when post /llm_model/list_running_models: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
2023-12-19 14:21:29,726 - utils.py[line:95] - ERROR: ConnectError: error when post /llm_model/list_running_models: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
2023-12-19 14:21:31,032 - utils.py[line:95] - ERROR: ConnectError: error when post /llm_model/list_running_models: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
2023-12-19 14:21:31,729 - utils.py[line:95] - ERROR: ConnectError: error when post /llm_model/list_running_models: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
2023-12-19 14:21:33,035 - utils.py[line:95] - ERROR: ConnectError: error when post /llm_model/list_running_models: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
2023-12-19 14:21:33,838 - utils.py[line:95] - ERROR: ConnectError: error when post /llm_model/list_running_models: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
2023-12-19 14:21:35,041 - utils.py[line:95] - ERROR: ConnectError: error when post /llm_model/list_running_models: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
2023-12-19 14:21:35,503 - utils.py[line:95] - ERROR: ConnectError: error when post /llm_model/list_running_models: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
2023-12-19 14:21:35,843 - utils.py[line:95] - ERROR: ConnectError: error when post /llm_model/list_running_models: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
2023-12-19 14:21:36,099 - utils.py[line:95] - ERROR: ConnectError: error when post /llm_model/list_running_models: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
2023-12-19 14:21:37,519 - utils.py[line:95] - ERROR: ConnectError: error when post /llm_model/list_running_models: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
2023-12-19 14:21:37,857 - utils.py[line:95] - ERROR: ConnectError: error when post /llm_model/list_running_models: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
2023-12-19 14:21:37.859 Uncaught app exception
Traceback (most recent call last):
  File "F:\Anaconda3\envs\langchain\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 534, in _run_script
    exec(code, module.__dict__)
  File "G:\AIGC\Langchain\Langchain-Chatchat\webui.py", line 64, in <module>
    pages[selected_page]["func"](api=api, is_lite=is_lite)
  File "G:\AIGC\Langchain\Langchain-Chatchat\webui_pages\dialogue\dialogue.py", line 165, in dialogue_page
    running_models = list(api.list_running_models())
TypeError: 'NoneType' object is not iterable
2023-12-19 14:21:38,116 - utils.py[line:95] - ERROR: ConnectError: error when post /llm_model/list_running_models: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
2023-12-19 14:21:39,526 - utils.py[line:95] - ERROR: ConnectError: error when post /llm_model/list_running_models: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
2023-12-19 14:21:40,131 - utils.py[line:95] - ERROR: ConnectError: error when post /llm_model/list_running_models: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
2023-12-19 14:21:41,635 - utils.py[line:95] - ERROR: ConnectError: error when post /llm_model/list_running_models: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
2023-12-19 14:21:42,240 - utils.py[line:95] - ERROR: ConnectError: error when post /llm_model/list_running_models: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
2023-12-19 14:21:43,641 - utils.py[line:95] - ERROR: ConnectError: error when post /llm_model/list_running_models: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
2023-12-19 14:21:44,248 - utils.py[line:95] - ERROR: ConnectError: error when post /llm_model/list_running_models: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
2023-12-19 14:21:45,647 - utils.py[line:95] - ERROR: ConnectError: error when post /llm_model/list_running_models: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
2023-12-19 14:21:45.647 Uncaught app exception
Traceback (most recent call last):
  File "F:\Anaconda3\envs\langchain\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 534, in _run_script
    exec(code, module.__dict__)
  File "G:\AIGC\Langchain\Langchain-Chatchat\webui.py", line 64, in <module>
    pages[selected_page]["func"](api=api, is_lite=is_lite)
  File "G:\AIGC\Langchain\Langchain-Chatchat\webui_pages\dialogue\dialogue.py", line 165, in dialogue_page
    running_models = list(api.list_running_models())
TypeError: 'NoneType' object is not iterable
2023-12-19 14:21:46,262 - utils.py[line:95] - ERROR: ConnectError: error when post /llm_model/list_running_models: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
2023-12-19 14:21:46.262 Uncaught app exception
Traceback (most recent call last):
  File "F:\Anaconda3\envs\langchain\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 534, in _run_script
    exec(code, module.__dict__)
  File "G:\AIGC\Langchain\Langchain-Chatchat\webui.py", line 64, in <module>
    pages[selected_page]["func"](api=api, is_lite=is_lite)
  File "G:\AIGC\Langchain\Langchain-Chatchat\webui_pages\dialogue\dialogue.py", line 165, in dialogue_page
    running_models = list(api.list_running_models())
TypeError: 'NoneType' object is not iterable

创建知识库失败

2023-12-20 10:43:16,728 - SentenceTransformer.py[line:66] - INFO: Load pretrained SentenceTransformer: G:\AIGC\Langchain\m3e-base-main
2023-12-20 10:43:21,466 - embeddings_api.py[line:39] - ERROR: Error while deserializing header: HeaderTooLarge
2023-12-20 10:43:21,483 - kb_api.py[line:34] - ERROR: TypeError: 创建知识库出错: loop of ufunc does not support argument 0 of type NoneType which has no callable conjugate method

解决方法:

EMBEDDING_MODEL 改成bge-large-zh

$ git lfs install
$ git clone https://huggingface.co/BAAI/bge-large-zh

然后清空knowledge_base 执行命令 python init_database.py --recreate-vs 重新初始化向量库即可,以上问题均得到解决。

五、启动信息

(langchain) G:\AIGC\Langchain\Langchain-Chatchat>python startup.py -a
​
​
==============================Langchain-Chatchat Configuration==============================
操作系统:Windows-10-10.0.18363-SP0.
python版本:3.10.12 | packaged by Anaconda, Inc. | (main, Jul  5 2023, 19:01:18) [MSC v.1916 64 bit (AMD64)]
项目版本:v0.2.8
langchain版本:0.0.344. fastchat版本:0.2.34
​
​
当前使用的分词器:ChineseRecursiveTextSplitter
当前启动的LLM模型:['zhipu-api'] @ cpu
{'api_key': '你自己的apikey',
 'device': 'cpu',
 'host': '127.0.0.1',
 'infer_turbo': False,
 'model_path': 'lucidrains/GLM-130B',
 'online_api': True,
 'port': 21001,
 'provider': 'ChatGLMWorker',
 'version': 'chatglm_turbo',
 'worker_class': <class 'server.model_workers.zhipu.ChatGLMWorker'>}
当前Embbedings模型: m3e-base @ cpu
==============================Langchain-Chatchat Configuration==============================
​
​
2023-12-20 10:09:39,873 - startup.py[line:650] - INFO: 正在启动服务:
2023-12-20 10:09:39,873 - startup.py[line:651] - INFO: 如需查看 llm_api 日志,请前往 G:\AIGC\Langchain\Langchain-Chatchat\logs
2023-12-20 10:09:52 | INFO | model_worker | Register to controller
2023-12-20 10:09:54 | ERROR | stderr | INFO:     Started server process [27468]
2023-12-20 10:09:54 | ERROR | stderr | INFO:     Waiting for application startup.
2023-12-20 10:09:54 | ERROR | stderr | INFO:     Application startup complete.
2023-12-20 10:09:54 | ERROR | stderr | INFO:     Uvicorn running on http://127.0.0.1:20000 (Press CTRL+C to quit)
INFO:     Started server process [25024]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:7861 (Press CTRL+C to quit)
​
​
==============================Langchain-Chatchat Configuration==============================
操作系统:Windows-10-10.0.18363-SP0.
python版本:3.10.12 | packaged by Anaconda, Inc. | (main, Jul  5 2023, 19:01:18) [MSC v.1916 64 bit (AMD64)]
项目版本:v0.2.8
langchain版本:0.0.344. fastchat版本:0.2.34
​
​
当前使用的分词器:ChineseRecursiveTextSplitter
当前启动的LLM模型:['zhipu-api'] @ cpu
{'api_key': '你自己的apikey',
 'device': 'cpu',
 'host': '127.0.0.1',
 'infer_turbo': False,
 'model_path': 'lucidrains/GLM-130B',
 'online_api': True,
 'port': 21001,
 'provider': 'ChatGLMWorker',
 'version': 'chatglm_turbo',
 'worker_class': <class 'server.model_workers.zhipu.ChatGLMWorker'>}
当前Embbedings模型: m3e-base @ cpu
​
​
服务端运行信息:
    OpenAI API Server: http://127.0.0.1:20000/v1
    Chatchat  API  Server: http://127.0.0.1:7861
    Chatchat WEBUI Server: http://127.0.0.1:8501
==============================Langchain-Chatchat Configuration==============================
​
​
​
  You can now view your Streamlit app in your browser.
​
  URL: http://127.0.0.1:8501

启动页面如下:

启动信息.PNG

六、注意事项

新建知识库名字不支持中文名称,且导入PDF解析速度较慢:

知识库名称.PNG

如何系统的去学习大模型LLM ?

作为一名热心肠的互联网老兵,我意识到有很多经验和知识值得分享给大家,也可以通过我们的能力和经验解答大家在人工智能学习中的很多困惑,所以在工作繁忙的情况下还是坚持各种整理和分享。

但苦于知识传播途径有限,很多互联网行业朋友无法获得正确的资料得到学习提升,故此将并将重要的 AI大模型资料 包括AI大模型入门学习思维导图、精品AI大模型学习书籍手册、视频教程、实战学习等录播视频免费分享出来

😝有需要的小伙伴,可以V扫描下方二维码免费领取🆓

一、全套AGI大模型学习路线

AI大模型时代的学习之旅:从基础到前沿,掌握人工智能的核心技能!

img

二、640套AI大模型报告合集

这套包含640份报告的合集,涵盖了AI大模型的理论研究、技术实现、行业应用等多个方面。无论您是科研人员、工程师,还是对AI大模型感兴趣的爱好者,这套报告合集都将为您提供宝贵的信息和启示。

img

三、AI大模型经典PDF籍

随着人工智能技术的飞速发展,AI大模型已经成为了当今科技领域的一大热点。这些大型预训练模型,如GPT-3、BERT、XLNet等,以其强大的语言理解和生成能力,正在改变我们对人工智能的认识。 那以下这些PDF籍就是非常不错的学习资源。

img

在这里插入图片描述

四、AI大模型商业化落地方案

img

阶段1:AI大模型时代的基础理解

  • 目标:了解AI大模型的基本概念、发展历程和核心原理。
  • 内容
    • L1.1 人工智能简述与大模型起源
    • L1.2 大模型与通用人工智能
    • L1.3 GPT模型的发展历程
    • L1.4 模型工程
    • L1.4.1 知识大模型
    • L1.4.2 生产大模型
    • L1.4.3 模型工程方法论
    • L1.4.4 模型工程实践
    • L1.5 GPT应用案例

阶段2:AI大模型API应用开发工程

  • 目标:掌握AI大模型API的使用和开发,以及相关的编程技能。
  • 内容
    • L2.1 API接口
    • L2.1.1 OpenAI API接口
    • L2.1.2 Python接口接入
    • L2.1.3 BOT工具类框架
    • L2.1.4 代码示例
    • L2.2 Prompt框架
    • L2.2.1 什么是Prompt
    • L2.2.2 Prompt框架应用现状
    • L2.2.3 基于GPTAS的Prompt框架
    • L2.2.4 Prompt框架与Thought
    • L2.2.5 Prompt框架与提示词
    • L2.3 流水线工程
    • L2.3.1 流水线工程的概念
    • L2.3.2 流水线工程的优点
    • L2.3.3 流水线工程的应用
    • L2.4 总结与展望

阶段3:AI大模型应用架构实践

  • 目标:深入理解AI大模型的应用架构,并能够进行私有化部署。
  • 内容
    • L3.1 Agent模型框架
    • L3.1.1 Agent模型框架的设计理念
    • L3.1.2 Agent模型框架的核心组件
    • L3.1.3 Agent模型框架的实现细节
    • L3.2 MetaGPT
    • L3.2.1 MetaGPT的基本概念
    • L3.2.2 MetaGPT的工作原理
    • L3.2.3 MetaGPT的应用场景
    • L3.3 ChatGLM
    • L3.3.1 ChatGLM的特点
    • L3.3.2 ChatGLM的开发环境
    • L3.3.3 ChatGLM的使用示例
    • L3.4 LLAMA
    • L3.4.1 LLAMA的特点
    • L3.4.2 LLAMA的开发环境
    • L3.4.3 LLAMA的使用示例
    • L3.5 其他大模型介绍

阶段4:AI大模型私有化部署

  • 目标:掌握多种AI大模型的私有化部署,包括多模态和特定领域模型。
  • 内容
    • L4.1 模型私有化部署概述
    • L4.2 模型私有化部署的关键技术
    • L4.3 模型私有化部署的实施步骤
    • L4.4 模型私有化部署的应用场景

学习计划:

  • 阶段1:1-2个月,建立AI大模型的基础知识体系。
  • 阶段2:2-3个月,专注于API应用开发能力的提升。
  • 阶段3:3-4个月,深入实践AI大模型的应用架构和私有化部署。
  • 阶段4:4-5个月,专注于高级模型的应用和部署。
这份完整版的大模型 LLM 学习资料已经上传CSDN,朋友们如果需要可以微信扫描下方CSDN官方认证二维码免费领取【保证100%免费

😝有需要的小伙伴,可以Vx扫描下方二维码免费领取🆓

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值