跳转至

快速开始

1. 克隆整个项目到本地

git clone https://github.com/RapidAI/Knowledge-QA-LLM.git

2. 安装运行环境

cd Knowledge-QA-LLM
pip install -r requirements.txt

3. 下载提取向量模型到本地

本项目目前以Moka-AI的m3e模型作为提取特征向量的主要模型,当然其他模型,也可自行配置。

moka-ai/m3e-small下载下来放到assets/models/m3e-small目录下,下载命令如下:

from sentence_transformers import SentenceTransformer

# 指定cache_dir即可
model = SentenceTransformer("moka-ai/m3e-small", cache_folder="assets/models")

# 验证是否可用
sentences = ["* Moka 此文本嵌入模型由 MokaAI 训练并开源,训练脚本使用 uniem",]
embeddings = model.encode(sentences)
for sentence, embedding in zip(sentences, embeddings):
    print("Sentence:", sentence)
    print("Embedding:", embedding)
    print("")

4. 配置LLM API接口

首先需要单独在本地部署大模型,以API方式启动。以ChatGLM-6B为例,具体可参考ChatGLM2-6B API

随后,knowledge_qa_llm/llm/chatglm2_6b.py是调用上一步LLM接口的类。

如果自己使用的LLM,没有该文件,可自行实现,保证输入和输出与现有的一致即可。

5. 更改config.yaml配置文件

将调用ChatGLM-6B的llm_api的url写到knowledge_qa_llm/config.yaml配置文件中

LLM_API:
  ChatGLM2_6B: your_api

6. 运行

Note

streamlit框架的启动,不可以用python webui.py方式启动,必须用以下方式启动。

UI Demo

streamlit run webui.py

CLI Demo

python cli.py

评论