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

相关推荐
营赢盈英2 小时前
Give azure openai an encyclopedia of information
ai·openai·azure
Snowbowღ6 小时前
OpenAI / GPT-4o:Python 返回结构化 / JSON 输出
python·json·openai·api·gpt-4o·pydantic·结构化输出
营赢盈英21 小时前
Allow anonymous access to my Azure OpenAI chat bot
ai·openai·azure·webapps
网络研究院2 天前
解码 OpenAI 的 o1 系列大型语言模型
人工智能·语言模型·自然语言处理·openai·技术·推理·能力
营赢盈英2 天前
OpenAI GPT-3 API error: “You must provide a model parameter“
chatgpt·gpt-3·openai·swift
营赢盈英2 天前
OpenAI API key not working in my React App
javascript·ai·openai·reactjs·chatbot
营赢盈英3 天前
Using OpenAI API from Firebase Cloud Functions in flutter app
ai·node.js·openai·googlecloud·firebase
营赢盈英5 天前
404 error when doing workload anlysis using locust on OpenAI API (GPT.35)
人工智能·python·openai·locust
CaiYongji5 天前
深度!程序员生涯的垃圾时间(上)
人工智能·gpt·chatgpt·openai
营赢盈英6 天前
How to see if openAI (node js) createModeration response “flagged“ is true
javascript·ai·node.js·openai·api