使用 Langchain-Chatchat 搭建一个自己的知识库(使用google实验室环境)

前言

本文将在 google 实验室中使用 Langchain-Chatchat 搭建一个知识库,还可以进行聊天等功能。 由于是在 google 实验室上面跑代码,所以本地电脑什么配置都无所谓!

效果图

运行起来后可以上传各种文档文件到知识库。

Langchain-Chatchat 是什么?

github github.com/chatchat-sp...

一种利用 langchain 思想实现的基于本地知识库的问答应用,目标期望建立一套对中文场景与开源模型支持友好、可离线运行的知识库问答解决方案。

google 实验室基本使用手法

笔记本环境中默认已经安装了 nodejs、python 等环境。

新建文档

  1. 打开地址 drive.google.com/drive/my-dr... (需fq)
  2. 在 colab notebooks 目录下新增笔记文件即可

基本语法

  • 在代码前面加上 "!" 符号就是可执行的命令语句
  • %cd 用于切换将当前环境的目录

开始啦

1、仓库拉取

python 复制代码
!git clone https://github.com/chatchat-space/Langchain-Chatchat.git

2、切换环境目录

python 复制代码
repo_dir = "/content/Langchain-Chatchat"
%cd $repo_dir

3、修改配置文件

google 实验室使用默认的模型 chatglm3-6b 跑不起来,换一个小一点的模型就行, 我这里用 Qwen-1_8B-Chat

a. 打开文件 Langchain-Chatchat/configs/model_config.py.example 第 22 行改为:

ini 复制代码
LLM_MODELS = ["Qwen-1_8B-Chat", "zhipu-api", "openai-api"] 

b. 打开文件 Langchain-Chatchat/configs/server_config.py.example 第 9 行改为:

ini 复制代码
OPEN_CROSS_DOMAIN = True

b. 打开文件 Langchain-Chatchat/configs/server_config.py.example 第 17 行下面追加:

python 复制代码
"share": True

依赖安装

python 复制代码
# 安装全部依赖
!pip install -r requirements.txt
!pip install -r requirements_api.txt
!pip install -r requirements_webui.txt

模型下载

python 复制代码
!rm -r Qwen-1_8B-Chat
!git clone https://huggingface.co/Qwen/Qwen-1_8B-Chat

!rm -r bge-large-zh
!git clone https://huggingface.co/BAAI/bge-large-zh

初始化知识库和配置文件

python 复制代码
# 删除多余的知识库文件
# 删除后自己将文件上传到 /content/Langchain-Chatchat/knowledge_base/samples/content/ 目录即可
!rm -R /content/Langchain-Chatchat/knowledge_base/samples/content/
!mkdir /content/Langchain-Chatchat/knowledge_base/samples/content/

内网穿透插件安装

由于google实验室不提供公网ip,所以是没有办法直接访问我们运行的服务的,这时候用内网穿透即可

python 复制代码
!npm install -g localtunnel

获取服务器 ipv4 地址

在访问内网穿透插件提供的地址时需要填入才可以进行访问页面

python 复制代码
!curl ipv4.icanhazip.com

启动

python 复制代码
!python ./startup.py -a & lt --port 8501

访问这个地址即可

最后

完整笔记: colab.research.google.com/drive/1TDYS...

相关推荐
学无止境小袁同学1 天前
OpenAI Agents SDK 模板操作手册(可直接操作)
大模型·openai·agent·sdk·大模型应用
沉默王二1 天前
腾讯这波上大分,Hy4-flash值得你猛蹬。
openai·agent·vibecoding
可夫小子1 天前
OpenAI 用 Codex 修 ChatGPT 性能,1700 次调查只直接合入 15 个 PR
openai·ai编程
ZzT3 天前
GPT-6.2 API 降价 20%,为什么老代码直接切过去反而更费钱?
openai·ai编程
ndz3 天前
GPT-6.2 API 接入笔记:Sol / Astra 怎么选,思考强度和调用示例
openai
AAA修煤气灶刘哥4 天前
为什么你的Codex 重连到 5/5 才开始工作?理解重试、协议回退与代理链路
人工智能·架构·openai
大西瓜瓜瓜6 天前
使用 AutoDL/RTX4090/QWeb7B
aigc·openai
沉默王二8 天前
官方点名,DeepSeek Harness 的 4 个神级插件。
openai·agent·ai编程
夕阳_醉了9 天前
Codex 客户端从装好到跑通:第三方 API 接入与配置避坑指南
人工智能·gpt·openai·codex·ai 编程
threerocks10 天前
一个人指挥一支 AI 剧组:Gemini 4 + Omni 1.2 剧情短片制作保姆级教程
aigc·openai·ai编程