diff --git a/deploy/.DS_Store b/.DS_Store similarity index 74% rename from deploy/.DS_Store rename to .DS_Store index ae5bc1a..b7be2cb 100644 Binary files a/deploy/.DS_Store and b/.DS_Store differ diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml index fc944f8..a1db6e2 100644 --- a/.github/workflows/build-image.yml +++ b/.github/workflows/build-image.yml @@ -4,48 +4,53 @@ on: push: branches: - main - - 'release/*' + - "release-*" + paths: + - '**.py' + - '**.yaml' jobs: build: runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Set up docker buildx - id: buildx - uses: docker/setup-buildx-action@v2 - with: - version: latest - - - name: Docker login - env: - DOCKER_USERNAME: ${{ secrets.ALIYUN_REGISTRY_USERNAME }} - DOCKER_PASSWORD: ${{ secrets.ALIYUN_REGISTRY_PASSWORD }} - run: | - echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin registry.cn-shanghai.aliyuncs.com - - - name: Extract branch name - id: extract_branch - run: echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV - - - name: Extract Tag - id: extract_tag - run: echo ::set-output name=version::${GITHUB_REF/refs\/tags\//} - - - name: Run buildx - run: | - tag=latest - if [[ "${{ steps.extract_branch.outputs.branch }}" == "main" ]];then - tag=latest - elif [[ "${{ steps.extract_tag.outputs.version }}" == v* ]]; then - tag="${{ steps.extract_tag.outputs.version }}" - fi - - echo extract_tag ${{ steps.extract_tag.outputs.version }} - echo extract_branch ${{ steps.extract_branch.outputs.branch }} - echo current tag is ${tag} - - docker buildx build --platform linux/amd64,linux/arm64 --push -f deploy/docker/Dockerfile -t registry.cn-shanghai.aliyuncs.com/openhydra/aes-ai-tutor:${tag} . \ No newline at end of file + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up docker buildx + id: buildx + uses: docker/setup-buildx-action@v2 + with: + version: latest + + - name: Docker login + env: + DOCKER_USERNAME: ${{ secrets.ALIYUN_REGISTRY_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.ALIYUN_REGISTRY_PASSWORD }} + run: | + echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin registry.cn-shanghai.aliyuncs.com + + - name: Extract Tag + id: extract_tag + run: echo ::set-output name=version::${GITHUB_REF/refs\/tags\//} + + - name: Extract branch name + shell: bash + run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" + id: extract_branch + + - name: Run buildx + run: | + if [[ "${{ steps.extract_branch.outputs.branch }}" == "main" ]];then + tag=latest + elif [[ "${{ steps.extract_tag.outputs.version }}" == v* ]]; then + tag="${{ steps.extract_tag.outputs.version }}" + else + tag="${{ steps.extract_branch.outputs.branch }}" + fi + + echo extract_tag ${{ steps.extract_tag.outputs.version }} + echo extract_branch ${{ steps.extract_branch.outputs.branch }} + echo current tag is ${tag} + + docker buildx build --platform linux/amd64,linux/arm64 --push -f deploy/docker/Dockerfile -t registry.cn-shanghai.aliyuncs.com/openhydra/aes-ai-tutor:${tag} . diff --git a/deploy/install.yaml b/deploy/install.yaml index f329202..1fc8dcd 100644 --- a/deploy/install.yaml +++ b/deploy/install.yaml @@ -18,7 +18,7 @@ spec: serviceAccountName: ai-education-studio-admin containers: - name: aes-ai-tutor-container - image: registry.cn-shanghai.aliyuncs.com/openhydra/aes-ai-tutor:latest + image: registry.cn-shanghai.aliyuncs.com/openhydra/aes-ai-tutor:release-2.0 imagePullPolicy: IfNotPresent command: ["/bin/sh", "-c"] args: ["python cli.py init && python cli.py start --api"] diff --git a/libs/aitutor/server/chat/kb_chat.py b/libs/aitutor/server/chat/kb_chat.py index 6ac4c9e..dec305d 100644 --- a/libs/aitutor/server/chat/kb_chat.py +++ b/libs/aitutor/server/chat/kb_chat.py @@ -101,9 +101,16 @@ async def knowledge_base_chat_iterator() -> AsyncIterable[str]: file_name="", metadata={}, ) - source_documents = format_reference( - kb_name, docs, api_address(is_public=True) - ) + source_documents = [] + for inum, doc in enumerate(docs): + filename = doc.metadata.get("source") + text = f"""出处 [{inum + 1}] [{filename}] \n\n{doc.page_content}\n\n""" + source_documents.append(text) + + if len(source_documents) == 0: # 没有找到相关文档 + source_documents.append( + f"""未找到相关文档,该回答为大模型自身能力解答!""" + ) elif mode == "temp_kb": ok, msg = check_embed_model() if not ok: @@ -115,9 +122,16 @@ async def knowledge_base_chat_iterator() -> AsyncIterable[str]: top_k=top_k, score_threshold=score_threshold, ) - source_documents = format_reference( - kb_name, docs, api_address(is_public=True) - ) + source_documents = [] + for inum, doc in enumerate(docs): + filename = doc.metadata.get("source") + text = f"""出处 [{inum + 1}] [{filename}] \n\n{doc.page_content}\n\n""" + source_documents.append(text) + + if len(source_documents) == 0: # 没有找到相关文档 + source_documents.append( + f"""未找到相关文档,该回答为大模型自身能力解答!""" + ) elif mode == "search_engine": result = await run_in_threadpool(search_engine, query, top_k, kb_name) docs = [x.dict() for x in result.get("docs", [])]