AI 文摘

Langchain-chatchat--大模型知识库





作者: 人工智能达人 来源: 人工智能达人

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

  1. 下载Langchain-chatchat

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

  1. 下载大模型和embedding模型

大模型:git clone https://huggingface.co/THUDM/chatglm3-6b-32k

embedding 模型:  git clone https://huggingface.co/BAAI/bge-large-zh

如果在下载过程中遇到huggingface.co is not conneted, 可以使用以下方法解决:  
完美解决huggingface问题:Failed to connect to huggingface.co port 443_failed to connect to huggingface.co port 443 after-CSDN博客  


pip install -U huggingface_hub  
export HF_ENDPOINT=https://hf-mirror.com  
  
huggingface-cli download --resume-download --local-dir-use-symlinks False THUDM/chatglm3-6b --local-dir chatglm3-6b  
  
  
huggingface-cli download --resume-download --local-dir-use-symlinks False BAAI/bge-large-zh --local-dir bge-large-zh


3. 下载需要的包  
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

pip install spacy

pip install cchardet

pip install accelerate

pip install –upgrade pip

pip install -r requirements.txt

  1. 修改配置文件

生成配置文件

python copy_config_example.py  
cd configs  
vim model_config.py

修改

EMBEDDING_MODEL = “bge-large-zh”

LLM_MODELS = [“chatglm3-6b-32k”]

编辑

编辑

  1. 安装相应的向量数据库

1)安装postgresql数据库

PostgreSQL: Linux downloads (Ubuntu)

启动数据库

service postgresql start

查看是否启动成功

pg_lsclusters

编辑

2)安装向量数据库

GitHub - pgvector/pgvector: Open-source vector similarity search for Postgres

编辑

通过以下的命令解决:

pg_config –includedir-server
sudo apt install postgresql-server-dev-all

su - postgres  
  
psql

修改kb_config.py

SQLALCHEMY_DATABASE_URI = f"postgresql://langchain:[email protected]:5432/langchain_chatchat"

DEFAULT_VS_TYPE = “pg”
创建新的user

CREATE USER langchain WITH PASSWORD ’langchain';

创建数据库langchain_chatchat

CREATE DATABASE langchain_chatchat;

ALTER USER “langchain” WITH login superuser createrole createdb replication bypassrls;

  1. 安装插件

python -m spacy download en_core_web_sm

python -m spacy download zh_core_web_sm

pip install psycopg2

pip install pgvector

pip install flask-mysqldb

pip install protobuf==3.20

pip install filemagic

  1. 启动服务的代码:

    python startup.py -a

postgres sql操作

查询所有的数据库:\l

查看所有的用户:

SELECT usename AS username,

usesysid AS user_id,

usecreatedb AS can_create_db,

usesuper AS is_superuser,

userepl AS can_replicate,

passwd AS password,

valuntil AS password_expiration

FROM pg_catalog.pg_user;

GRANT CONNECT ON DATABASE langchain_chatchat TO langchain;
GRANT USAGE ON SCHEMA public TO langchain;
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO langchain;
ALTER USER “langchain” WITH login superuser createrole createdb replication bypassrls;

更多AI工具,参考Github-AiBard123国内AiBard123

可关注我们的公众号:每天AI新工具