Merge branch 'main' of github.com:1Panel-dev/maxkb

This commit is contained in:
shaohuzhang1 2024-03-19 20:38:39 +08:00
commit 21d918736e
13 changed files with 116 additions and 113 deletions

BIN
.DS_Store vendored

Binary file not shown.

1
.dockerignore Normal file
View File

@ -0,0 +1 @@
.git*

View File

@ -1,2 +0,0 @@
[worker.oci]
max-parallelism=1

View File

@ -43,18 +43,15 @@ jobs:
DOCKER_IMAGE_TAGS="--tag ${DOCKER_IMAGE}:${TAG_NAME} --tag ${DOCKER_IMAGE}:latest"
echo ::set-output name=docker_image::${DOCKER_IMAGE}
echo ::set-output name=version::${TAG_NAME}
echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \
echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} --no-cache \
--build-arg VERSION=${TAG_NAME} \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg --no-cache --provenance=false \
--build-arg VCS_REF=${GITHUB_SHA::8} \
${DOCKER_IMAGE_TAGS} .
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
config: .github/buildkitd.toml
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:

View File

@ -48,18 +48,15 @@ jobs:
DOCKER_IMAGE_TAGS="--tag ${DOCKER_IMAGE}:${TAG_NAME} --tag ${DOCKER_IMAGE}:latest"
echo ::set-output name=docker_image::${DOCKER_IMAGE}
echo ::set-output name=version::${TAG_NAME}
echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \
echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} --no-cache \
--build-arg VERSION=${TAG_NAME} \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg --no-cache --provenance=false \
--build-arg VCS_REF=${GITHUB_SHA::8} \
${DOCKER_IMAGE_TAGS} .
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
config: .github/buildkitd.toml
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:

View File

@ -5,7 +5,7 @@ on:
inputs:
dockerImageTag:
description: 'Docker Image Tag'
default: 'v1.0.0'
default: 'v1.0.0-dev'
required: true
architecture:
description: 'Architecture'
@ -16,9 +16,19 @@ on:
- linux/amd64
- linux/arm64
- linux/amd64,linux/arm64
registry:
description: 'Push To Registry'
required: true
default: 'dockerhub, fit2cloud-registry'
type: choice
options:
- dockerhub
- fit2cloud-registry
- dockerhub, fit2cloud-registry
jobs:
build-and-push-fit2cloud-registry:
build-and-push-to-fit2cloud-registry:
if: ${{ contains(github.event.inputs.registry, 'fit2cloud') }}
runs-on: ubuntu-latest
steps:
- name: Check Disk Space
@ -45,38 +55,35 @@ jobs:
DOCKER_IMAGE=registry-hkproxy.fit2cloud.com/maxkb/maxkb
DOCKER_PLATFORMS=${{ github.event.inputs.architecture }}
TAG_NAME=${{ github.event.inputs.dockerImageTag }}
if [[ ${TAG_NAME} == *dev* ]]; then
DOCKER_IMAGE_TAGS="--tag ${DOCKER_IMAGE}:${TAG_NAME}"
else
DOCKER_IMAGE_TAGS="--tag ${DOCKER_IMAGE}:${TAG_NAME} --tag ${DOCKER_IMAGE}:latest"
echo ::set-output name=docker_image::${DOCKER_IMAGE}
echo ::set-output name=version::${TAG_NAME}
echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \
--build-arg VERSION=${TAG_NAME} \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg --no-cache \
--build-arg VCS_REF=${GITHUB_SHA::8} \
fi
echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} --no-cache \
${DOCKER_IMAGE_TAGS} .
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
config: .github/buildkitd.toml
- name: Login to FIT2CLOUD Registry
uses: docker/login-action@v3
with:
registry: registry-hkproxy.fit2cloud.com
username: ${{ secrets.FIT2CLOUD_REGISTRY_USERNAME }}
password: ${{ secrets.FIT2CLOUD_REGISTRY_PASSWORD }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GH_TOKEN }}
- name: Login to FIT2CLOUD Registry
uses: docker/login-action@v3
with:
registry: registry-hkproxy.fit2cloud.com
username: ${{ secrets.FIT2CLOUD_REGISTRY_USERNAME }}
password: ${{ secrets.FIT2CLOUD_REGISTRY_PASSWORD }}
- name: Docker Buildx (build-and-push)
run: |
docker buildx build --output "type=image,push=true" ${{ steps.prepare.outputs.buildx_args }} -f installer/Dockerfile
build-and-push-to-ghcr:
build-and-push-to-dockerhub:
if: ${{ contains(github.event.inputs.registry, 'dockerhub') }}
runs-on: ubuntu-latest
steps:
- name: Check Disk Space
@ -100,30 +107,32 @@ jobs:
- name: Prepare
id: prepare
run: |
DOCKER_IMAGE=ghcr.io/1panel-dev/maxkb
DOCKER_IMAGE=1panel/maxkb
DOCKER_PLATFORMS=${{ github.event.inputs.architecture }}
TAG_NAME=${{ github.event.inputs.dockerImageTag }}
if [[ ${TAG_NAME} == *dev* ]]; then
DOCKER_IMAGE_TAGS="--tag ${DOCKER_IMAGE}:${TAG_NAME}"
else
DOCKER_IMAGE_TAGS="--tag ${DOCKER_IMAGE}:${TAG_NAME} --tag ${DOCKER_IMAGE}:latest"
echo ::set-output name=docker_image::${DOCKER_IMAGE}
echo ::set-output name=version::${TAG_NAME}
echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \
--build-arg VERSION=${TAG_NAME} \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg --no-cache --provenance=false \
--build-arg VCS_REF=${GITHUB_SHA::8} \
fi
echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} --no-cache \
${DOCKER_IMAGE_TAGS} .
env
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
config: .github/buildkitd.toml
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GH_TOKEN }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker Buildx (build-and-push)
run: |
docker buildx build --output "type=image,push=true" ${{ steps.prepare.outputs.buildx_args }} -f installer/Dockerfile

15
.gitignore vendored
View File

@ -1,3 +1,18 @@
# Mac
.DS_Store
*/.DS_Store
# VS Code
.vscode
*.project
*.factorypath
# IntelliJ IDEA
.idea
*.iws
*.iml
*.ipr
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

View File

@ -1,66 +1,59 @@
<p align="center"></p>
<h3 align="center">基于大语言模型的知识库问答系统</h3>
<p align="center">
<p align="center"><img src= "https://github.com/1Panel-dev/maxkb/assets/52996290/c0694996-0eed-40d8-b369-322bf2a380bf" alt="MaxKB" width="300" /></p>
<h3 align="center">基于 LLM 大语言模型的知识库问答系统</h3>
<p align="center">
<a href="https://www.gnu.org/licenses/old-licenses/gpl-3.0"><img src="https://img.shields.io/github/license/1Panel-dev/maxkb?color=%231890FF" alt="License: GPL v3"></a>
<a href="https://app.codacy.com/gh/1Panel-dev/maxkb?utm_source=github.com&utm_medium=referral&utm_content=1Panel-dev/maxkb&utm_campaign=Badge_Grade_Dashboard"><img src="https://app.codacy.com/project/badge/Grade/da67574fd82b473992781d1386b937ef" alt="Codacy"></a>
<a href="https://github.com/1Panel-dev/maxkb/releases/latest"><img src="https://img.shields.io/github/v/release/1Panel-dev/maxkb" alt="Latest release"></a>
<a href="https://github.com/1Panel-dev/maxkb"><img src="https://img.shields.io/github/stars/1Panel-dev/maxkb?color=%231890FF&style=flat-square" alt="Stars"></a>
</p>
<hr/>
MaxKB 是一款基于 LLM 大语言模型的知识库问答系统。
MaxKB Max Knowlegde Base 的简称)是一款基于大语言模型的知识库问答系统,其核心目标是利用大语言模型对自然语言理解和生成的能力揣摩用户意图,对原始知识点进行汇总、整合,生成更贴切的答案。
- **多模型**:支持对接主流的大模型,包括本地私有大模型(如 Llama 2、Azure OpenAI 和百度千帆大模型等;
- **开箱即用**:支持直接上传文档、自动爬取在线文档,支持文本自动拆分、向量化,智能问答交互体验好;
- **无缝嵌入**:支持零编码快速嵌入到第三方业务系统。
MaxKB 的产品特性:
- **多模型对接**
MaxKB 支持对接市场上主流的模型供应商,包括百度千帆大模型、 Azure OpenAI 和 Ollama 私有模型平台等。
## 快速开始
- **开箱即用**
支持一键获取在线文本或直接上传文档MaxKB 系统自动进行文本拆分、知识向量化;构建应用实现 LLM 问答功能,根据用户提问和知识库内容生成精确回答。
- **无缝集成**
MaxKB 应用支持零编码集成到企业第三方系统。
## 一键启动
MaxKB 支持一键启动,仅需执行以下命令:
```
docker run --name="maxkb" -p 8000:8000 -d ghcr.io/1panel-dev/maxkb
docker run -d --name=maxkb -p 8080:8080 1panel/maxkb
```
## 自定义持久化数据
## 整体架构
![arch](https://github.com/1Panel-dev/maxkb/assets/52996290/ca786342-8a0a-4921-b847-a96fff9a3e09)
## 实现原理
- 获取本地文档;
- 读取文本;
- 文本分割;
- 文本向量化;
- Query 向量化;
- 向量匹配最相似的 TOP N 个文本;
- 匹配出的文本作为上下文和问题一起添加到 prompt 中;
- 提交给 LLM 做生成回答。
![Implementation principle](https://github.com/1Panel-dev/maxkb/assets/52996290/51956c12-1396-4625-8b29-005ac60ca11d)
- 在主机系统上创建一个存储数据的目录,例如:/opt/maxkb/data
- 在主机系统上创建一个存储配置文件的目录,例如:/opt/maxkb/conf
```
docker run --name=maxkb -p 8080:8000 -v /opt/maxkb/data:/var/lib/postgresql/data -v /opt/maxkb/conf:/opt/maxkb/conf -d 1panel/maxkb
```
也可以通过 [1Panel 应用商店](https://apps.fit2cloud.com/1panel) 快速部署 MaxKB + OllamaLlama 230 分钟内即可上线基于本地大模型的知识库问答系统。
## 社区
## UI 展示
<table style="border-collapse: collapse; border: 1px solid black;">
<tr>
<td style="padding: 5px;background-color:#fff;"><img src= "https://github.com/1Panel-dev/MaxKB/assets/80892890/2b893a25-ae46-48da-b6a1-61d23015565e" alt="Demo1" /></td>
<td style="padding: 5px;background-color:#fff;"><img src= "https://github.com/1Panel-dev/MaxKB/assets/80892890/3e50e7ff-cdc4-4a37-b430-d84975f11d4e" alt="Demo2" /></td>
</tr>
<tr>
<td style="padding: 5px;background-color:#fff;"><img src= "https://github.com/1Panel-dev/MaxKB/assets/80892890/dfdcc03f-ef36-4f75-bb82-797c0f9da1ad" alt="Demo3" /></td>
<td style="padding: 5px;background-color:#fff;"><img src= "https://github.com/1Panel-dev/MaxKB/assets/80892890/884a9db1-3f93-4013-bc8f-a3f0dbcfeb2f" alt="Demo4" /></td>
</tr>
</table>
如果您在使用过程中有任何疑问或建议,欢迎提交 GitHub Issue 或到我们官方论坛进行交流沟通:
## 社区交流
[论坛](https://bbs.fit2cloud.com/c/mk/11)
- [论坛](https://bbs.fit2cloud.com/)
## 技术栈
- 前端:[Vue3.js](https://cn.vuejs.org/)、[Element Plus](https://element-plus.org/zh-CN/)、[TypeScript](https://www.tslang.cn/)
- 后端:[django](https://www.djangoproject.com/)、[langchain](https://www.langchain.com/)
- 中间件:[postgresql](https://www.postgresql.org/)
- 基础设施:[Docker](https://www.docker.com/)
- 前端:[Vue.js](https://cn.vuejs.org/)
- 后端:[Django](https://www.djangoproject.com/)
- Langchain[Langchain](https://www.langchain.com/)
- 向量数据库:[PostgreSQL](https://www.postgresql.org/)
- 大模型Azure OpenAI、百度千帆大模型、[Ollama](https://github.com/ollama/ollama)
## License

View File

@ -12,32 +12,25 @@ FROM ghcr.io/1panel-dev/maxkb-python-pg:python3.11.8-pg15.3
RUN mkdir -p /opt/maxkb/app && mkdir -p /opt/maxkb/model && mkdir -p /opt/maxkb/conf
# 拷贝项目
COPY . /opt/maxkb/app
RUN rm -rf /opt/maxkb/app/ui
COPY installer/config.yaml /opt/maxkb/conf
ENV POSTGRES_USER root
ENV POSTGRES_PASSWORD Password123@postgres
RUN rm -rf /opt/maxkb/app/ui /opt/maxkb/app/build
COPY --from=vector-model model /opt/maxkb/app/model
COPY --from=web-build ui /opt/maxkb/app/ui
RUN ls -la /opt/maxkb/app
# 复制模型
RUN mv /opt/maxkb/app/model/* /opt/maxkb/model
RUN ls /opt/maxkb/model
RUN cp -r /opt/maxkb/model/base/hub /opt/maxkb/model/tokenizer
# 设置工作目录
ENV POSTGRES_USER root
ENV POSTGRES_PASSWORD Password123@postgres
WORKDIR /opt/maxkb/app
# 更新apt-get包管理器
RUN apt-get update&&apt-get install -y curl
# 更新pip
RUN pip3 install --upgrade pip
# 安装 poetry包管理器
RUN pip3 install poetry
# 导出依赖
RUN poetry export -f requirements.txt --output requirements.txt --without-hashes
# 下载python依赖
RUN pip3 install --no-cache-dir -r requirements.txt
RUN mv /opt/maxkb/app/model/* /opt/maxkb/model && \
cp -r /opt/maxkb/model/base/hub /opt/maxkb/model/tokenizer && \
apt-get update && apt-get install -y curl && \
pip3 install --upgrade pip && \
pip3 install poetry && \
poetry export -f requirements.txt --output requirements.txt --without-hashes && \
pip3 install --no-cache-dir -r requirements.txt && \
pip3 cache purge && \
rm -rf /var/lib/apt/lists/*
# 启动命令
VOLUME /opt/maxkb/conf
EXPOSE 8000
EXPOSE 8080
COPY installer/run-maxkb.sh /usr/bin/
RUN chmod 755 /usr/bin/run-maxkb.sh
ENTRYPOINT ["bash", "-c"]

View File

@ -44,7 +44,7 @@ def perform_db_migrate():
def start_services():
management.call_command('migrate')
management.call_command('runserver', "0.0.0.0:8000")
management.call_command('runserver', "0.0.0.0:8080")
if __name__ == '__main__':

View File

@ -7,7 +7,7 @@ readme = "README.md"
[tool.poetry.dependencies]
python = "^3.11"
django = "4.1.10"
django = "4.1.13"
djangorestframework = "3.14.0"
drf-yasg = "1.21.7"
django-filter = "23.2"
@ -16,7 +16,7 @@ langchain = "^0.1.11"
psycopg2-binary = "2.9.7"
jieba = "^0.42.1"
diskcache = "^5.6.3"
pillow = "9.5.0"
pillow = "^10.2.0"
filetype = "^1.2.0"
chardet = "^5.2.0"
sentence-transformers = "^2.2.2"

View File

@ -13,7 +13,7 @@
"format": "prettier --write src/"
},
"dependencies": {
"axios": "^0.27.2",
"axios": "^0.28.0",
"element-plus": "^2.5.6",
"install": "^0.13.0",
"lodash": "^4.17.21",

View File

@ -11,7 +11,7 @@ export default defineConfig(({ mode }) => {
const ENV = loadEnv(mode, envDir)
const proxyConf: Record<string, string | ProxyOptions> = {}
proxyConf['/api'] = {
target: 'http://127.0.0.1:8000',
target: 'http://127.0.0.1:8080',
changeOrigin: true,
rewrite: (path) => path.replace(ENV.VITE_BASE_PATH, '/')
}