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

前言

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

效果图

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

Langchain-Chatchat 是什么?

github github.com/chatchat-sp...

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

google 实验室基本使用手法

笔记本环境中默认已经安装了 nodejspython 等环境。

新建文档

  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...

相关推荐
serendipity7332 小时前
一文带你彻底掌握Function Call 的使用(nodejs版)
openai
机器之心2 小时前
太强了!DeepSeek刚刚开源新模型,用视觉方式压缩一切
人工智能·openai
机器之心4 小时前
Meta用40万个GPU小时做了一个实验,只为弄清强化学习Scaling Law
人工智能·openai
_清欢l5 小时前
搭建Dify
openai
AntBlack21 小时前
虽迟但到 :盘一盘 SpringAI 现在发展得怎么样了?
后端·spring·openai
叶庭云1 天前
一文掌握 CodeX CLI 安装以及使用!
人工智能·openai·安装·使用教程·codex cli·编码智能体·vibe coding 终端
数据智能老司机1 天前
使用 OpenAI Agents SDK 构建智能体——记忆与知识
llm·openai·agent
数据智能老司机1 天前
使用 OpenAI Agents SDK 构建智能体——代理工具与 MCP
llm·openai·agent
Larcher2 天前
n8n 入门笔记:用零代码工作流自动化重塑效率边界
前端·openai
七牛云行业应用2 天前
从API调用到智能体编排:GPT-5时代的AI开发新模式
大数据·人工智能·gpt·openai·agent开发