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

相关推荐
LinXunFeng5 小时前
AI - Gemini CLI 摆脱终端限制
openai·ai编程·gemini
软件测试君13 小时前
【Rag实用分享】小白也能看懂的文档解析和分割教程
aigc·openai·ai编程
会写代码的斯皮尔伯格3 天前
Spring Boot 3整合Spring AI实战:9轮面试对话解析AI应用开发
openai·微服务架构·java面试·rag·ollama·spring ai·spring boot 3
新智元3 天前
AI教父Hinton首次现身中国,合照全网刷屏!预警AI觉醒临界点已至
人工智能·openai
新智元3 天前
无惧封禁!Cursor最佳国产平替诞生,彻底告别代码泄露风险
人工智能·openai
花落人散处3 天前
SpringAI——完成 Function Calling
java·后端·openai
新智元4 天前
奥特曼首次体验GPT-5!被吓到眩晕瘫坐,那一刻就像看到原子弹爆炸
人工智能·openai
星际码仔4 天前
AI浪潮下,程序员的岗位不会消失,但可能断层
openai·claude·cursor
柠檬豆腐脑4 天前
Node.js调用OpenAI API指南:从入门到工具调用
node.js·llm·openai
Code_流苏5 天前
ChatGPT Agent深度解析:告别单纯问答,一个指令搞定复杂任务?
人工智能·自然语言处理·chatgpt·openai·agent·智能体