Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: source_documents url error #2

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file renamed deploy/.DS_Store → .DS_Store
Binary file not shown.
83 changes: 44 additions & 39 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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} .
- 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} .
2 changes: 1 addition & 1 deletion deploy/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
26 changes: 20 additions & 6 deletions libs/aitutor/server/chat/kb_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""<span style='color:red'>未找到相关文档,该回答为大模型自身能力解答!</span>"""
)
elif mode == "temp_kb":
ok, msg = check_embed_model()
if not ok:
Expand All @@ -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"""<span style='color:red'>未找到相关文档,该回答为大模型自身能力解答!</span>"""
)
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", [])]
Expand Down
Loading