diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml new file mode 100644 index 000000000..fe3108aa1 --- /dev/null +++ b/.github/workflows/build-and-push.yml @@ -0,0 +1,53 @@ +name: build-and-push + +on: + workflow_dispatch: + inputs: + registryAddress: + description: 'Registry Address' + default: 'registry-hkproxy.fit2cloud.com' + required: true + dockerImageName: + description: 'Docker Image Name' + default: 'maxkb/maxkb' + required: true + dockerImageTag: + description: 'Docker Image Tag' + default: 'v1.0.0' + required: true + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Prepare + id: prepare + run: | + DOCKER_IMAGE=${{ github.event.inputs.registryAddress }}/${{ github.event.inputs.dockerImageName }} + DOCKER_PLATFORMS=linux/amd64,linux/arm64 + TAG_NAME=${{ github.event.inputs.dockerImageTag }} + 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} \ + ${DOCKER_IMAGE_TAGS} . + - name: Set up Docker Buildx + uses: crazy-max/ghaction-docker-buildx@v3 + - name: Docker Buildx (build) + run: | + docker buildx build --output "type=image,push=false" ${{ steps.prepare.outputs.buildx_args }} + - name: Login to Registry + uses: docker/login-action@v1 + with: + registry: ${{ github.event.inputs.registryAddress }} + username: ${{ secrets.FIT2CLOUD_REGISTRY_USERNAME }} + password: ${{ secrets.FIT2CLOUD_REGISTRY_PASSWORD }} + - name: Docker Buildx (push) + run: | + docker buildx build --output "type=image,push=true" ${{ steps.prepare.outputs.buildx_args }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 5c8b0b26a..26a451024 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,16 @@ +FROM python:3.11-slim as vector-model-build +COPY install_model.py install_model.py +RUN pip3 install --upgrade pip setuptools && \ + pip install pycrawlers && \ + pip install transformers && \ + python3 install_model.py + +FROM node:18-alpine3.18 as web-build +COPY ui ui +RUN cd ui && \ + npm install && \ + npm run build + FROM python:3.11-slim ENV LANG=C.UTF-8 @@ -6,7 +19,10 @@ USER root # 创建工作目录 RUN mkdir -p /opt/maxkb/app && mkdir -p /opt/maxkb/model # 拷贝项目 +RUN ls -la COPY . /opt/maxkb/app +COPY --from=vector-model-build model /opt/maxkb/app/model +COPY --from=web-build ui /opt/maxkb/app/ui # 复制模型 RUN mv /opt/maxkb/app/model/* /opt/maxkb/model RUN ls /opt/maxkb/model @@ -22,7 +38,7 @@ 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 --trusted-host pypi.tuna.tsinghua.edu.cn +RUN pip3 install --no-cache-dir -r requirements.txt # 删除前端依赖 RUN rm -rf ui/node_modules # 启动命令 diff --git a/ui/package.json b/ui/package.json index d5fe95064..774b1c467 100644 --- a/ui/package.json +++ b/ui/package.json @@ -14,7 +14,7 @@ }, "dependencies": { "axios": "^0.27.2", - "element-plus": "^2.4.3", + "element-plus": "^2.5.3", "install": "^0.13.0", "lodash": "^4.17.21", "markdown-it": "^13.0.2", diff --git a/ui/src/components/ai-chat/index.vue b/ui/src/components/ai-chat/index.vue index 6492de5ed..07bb9b642 100644 --- a/ui/src/components/ai-chat/index.vue +++ b/ui/src/components/ai-chat/index.vue @@ -211,7 +211,7 @@ const prologueList = computed(() => { const temp = props.data?.prologue let arr: any = [] const lines = temp?.split('\n') - lines.forEach((str: string, index: number) => { + lines?.forEach((str: string, index: number) => { if (isMdArray(str)) { arr[index] = { type: 'question', @@ -292,7 +292,8 @@ function getChartOpenId() { chatMessage() }) .catch((res) => { - if (res.response.status === 401) { + console.log(res) + if (res.response.status === 403) { application.asyncAppAuthentication(accessToken).then(() => { getChartOpenId() }) @@ -405,26 +406,33 @@ function chatMessage() { record_id: '', vote_status: '-1' }) - chatList.value.push(chat) - inputValue.value = '' - nextTick(() => { - // 将滚动条滚动到最下面 - scrollDiv.value.setScrollTop(Number.MAX_SAFE_INTEGER) - }) // 对话 applicationApi .postChatMessage(chartOpenId.value, problem_text) .then((response) => { - ChatManagement.addChatRecord(chat, 50, loading) - ChatManagement.write(chat.id) - const reader = response.body.getReader() - // 处理流数据 - const write = getWrite( - chat, - reader, - response.headers.get('Content-Type') !== 'application/json' - ) - return reader.read().then(write) + console.log(response.status) + if (response.status === 401) { + application.asyncAppAuthentication(accessToken).then(() => { + chatMessage() + }) + } else { + chatList.value.push(chat) + inputValue.value = '' + nextTick(() => { + // 将滚动条滚动到最下面 + scrollDiv.value.setScrollTop(Number.MAX_SAFE_INTEGER) + }) + ChatManagement.addChatRecord(chat, 50, loading) + ChatManagement.write(chat.id) + const reader = response.body.getReader() + // 处理流数据 + const write = getWrite( + chat, + reader, + response.headers.get('Content-Type') !== 'application/json' + ) + return reader.read().then(write) + } }) .then(() => { return !props.appId && getSourceDetail(chat) diff --git a/ui/src/components/login-layout/index.vue b/ui/src/components/login-layout/index.vue index 120ed6815..c8e33646e 100644 --- a/ui/src/components/login-layout/index.vue +++ b/ui/src/components/login-layout/index.vue @@ -2,15 +2,8 @@
- + + @@ -21,18 +14,18 @@