From 2b68323c2c57027b62c11f8546d4a9aba137796d Mon Sep 17 00:00:00 2001 From: Huiling Bao Date: Thu, 12 Sep 2024 22:12:39 +0800 Subject: [PATCH] Rename videoragqna to videoqna to align with other examples (#680) Signed-off-by: BaoHuiling --- .../workflows/docker/compose/reranks-compose.yaml | 6 +++--- comps/__init__.py | 2 +- comps/cores/mega/constants.py | 2 +- comps/cores/mega/gateway.py | 4 ++-- .../reranks/{video-rag-qna => videoqna}/Dockerfile | 4 ++-- .../reranks/{video-rag-qna => videoqna}/README.md | 14 +++++++------- .../docker_compose_reranking.yaml | 4 ++-- .../{video-rag-qna => videoqna}/local_reranking.py | 8 ++++---- .../{video-rag-qna => videoqna}/requirements.txt | 0 ...t_service_orchestrator_with_videoqnagateway.py} | 11 ++--------- ...s_video-rag-qna.sh => test_reranks_videoqna.sh} | 8 ++++---- 11 files changed, 28 insertions(+), 35 deletions(-) rename comps/reranks/{video-rag-qna => videoqna}/Dockerfile (86%) rename comps/reranks/{video-rag-qna => videoqna}/README.md (57%) rename comps/reranks/{video-rag-qna => videoqna}/docker_compose_reranking.yaml (81%) rename comps/reranks/{video-rag-qna => videoqna}/local_reranking.py (92%) rename comps/reranks/{video-rag-qna => videoqna}/requirements.txt (100%) rename tests/cores/mega/{test_service_orchestrator_with_videoragqnagateway.py => test_service_orchestrator_with_videoqnagateway.py} (90%) rename tests/reranks/{test_reranks_video-rag-qna.sh => test_reranks_videoqna.sh} (86%) mode change 100644 => 100755 diff --git a/.github/workflows/docker/compose/reranks-compose.yaml b/.github/workflows/docker/compose/reranks-compose.yaml index b11fb8a4a..1a160d3b6 100644 --- a/.github/workflows/docker/compose/reranks-compose.yaml +++ b/.github/workflows/docker/compose/reranks-compose.yaml @@ -8,7 +8,7 @@ services: build: dockerfile: comps/reranks/tei/Dockerfile image: ${REGISTRY:-opea}/reranking-tei:${TAG:-latest} - reranking-videoragqna: + reranking-videoqna: build: - dockerfile: comps/reranks/video-rag-qna/Dockerfile - image: ${REGISTRY:-opea}/reranking-videoragqna:${TAG:-latest} + dockerfile: comps/reranks/videoqna/Dockerfile + image: ${REGISTRY:-opea}/reranking-videoqna:${TAG:-latest} diff --git a/comps/__init__.py b/comps/__init__.py index 1ad435bf2..d4cec4d53 100644 --- a/comps/__init__.py +++ b/comps/__init__.py @@ -46,7 +46,7 @@ AudioQnAGateway, RetrievalToolGateway, FaqGenGateway, - VideoRAGQnAGateway, + VideoQnAGateway, VisualQnAGateway, MultimodalRAGWithVideosGateway, ) diff --git a/comps/cores/mega/constants.py b/comps/cores/mega/constants.py index a23fdaf55..1e80ad7dc 100644 --- a/comps/cores/mega/constants.py +++ b/comps/cores/mega/constants.py @@ -38,7 +38,7 @@ class MegaServiceEndpoint(Enum): CHAT_QNA = "/v1/chatqna" AUDIO_QNA = "/v1/audioqna" VISUAL_QNA = "/v1/visualqna" - VIDEO_RAG_QNA = "/v1/videoragqna" + VIDEO_RAG_QNA = "/v1/videoqna" CODE_GEN = "/v1/codegen" CODE_TRANS = "/v1/codetrans" DOC_SUMMARY = "/v1/docsum" diff --git a/comps/cores/mega/gateway.py b/comps/cores/mega/gateway.py index b14ef6075..e5645844a 100644 --- a/comps/cores/mega/gateway.py +++ b/comps/cores/mega/gateway.py @@ -548,7 +548,7 @@ async def handle_request(self, request: Request): return ChatCompletionResponse(model="visualqna", choices=choices, usage=usage) -class VideoRAGQnAGateway(Gateway): +class VideoQnAGateway(Gateway): def __init__(self, megaservice, host="0.0.0.0", port=8888): super().__init__( megaservice, @@ -594,7 +594,7 @@ async def handle_request(self, request: Request): finish_reason="stop", ) ) - return ChatCompletionResponse(model="videoragqna", choices=choices, usage=usage) + return ChatCompletionResponse(model="videoqna", choices=choices, usage=usage) class RetrievalToolGateway(Gateway): diff --git a/comps/reranks/video-rag-qna/Dockerfile b/comps/reranks/videoqna/Dockerfile similarity index 86% rename from comps/reranks/video-rag-qna/Dockerfile rename to comps/reranks/videoqna/Dockerfile index 617f47b6a..17a4a1c92 100644 --- a/comps/reranks/video-rag-qna/Dockerfile +++ b/comps/reranks/videoqna/Dockerfile @@ -15,10 +15,10 @@ USER user COPY comps /home/user/comps RUN pip install --no-cache-dir --upgrade pip && \ - pip install --no-cache-dir -r /home/user/comps/reranks/video-rag-qna/requirements.txt + pip install --no-cache-dir -r /home/user/comps/reranks/videoqna/requirements.txt ENV PYTHONPATH=$PYTHONPATH:/home/user -WORKDIR /home/user/comps/reranks/video-rag-qna +WORKDIR /home/user/comps/reranks/videoqna ENTRYPOINT ["python", "local_reranking.py"] \ No newline at end of file diff --git a/comps/reranks/video-rag-qna/README.md b/comps/reranks/videoqna/README.md similarity index 57% rename from comps/reranks/video-rag-qna/README.md rename to comps/reranks/videoqna/README.md index bdb4fc47d..3ec4810be 100644 --- a/comps/reranks/video-rag-qna/README.md +++ b/comps/reranks/videoqna/README.md @@ -1,8 +1,8 @@ # Rerank Microservice -This is a Docker-based microservice that do result rerank for VideoRAGQnA use case. Local rerank is used rather than rerank model. +This is a Docker-based microservice that do result rerank for VideoQnA use case. Local rerank is used rather than rerank model. -For the `VideoRAGQnA` usecase, during the data preparation phase, frames are extracted from videos and stored in a vector database. To identify the most relevant video, we count the occurrences of each video source among the retrieved data with rerank function `get_top_doc`. This sorts the video as a descending list of names, ranked by their degree of match with the query. Then we could send the `top_n` videos to the downstream LVM. +For the `VideoQnA` usecase, during the data preparation phase, frames are extracted from videos and stored in a vector database. To identify the most relevant video, we count the occurrences of each video source among the retrieved data with rerank function `get_top_doc`. This sorts the video as a descending list of names, ranked by their degree of match with the query. Then we could send the `top_n` videos to the downstream LVM. ## 🚀1. Start Microservice with Docker @@ -10,22 +10,22 @@ For the `VideoRAGQnA` usecase, during the data preparation phase, frames are ext ```bash cd GenAIComps -docker build --no-cache -t opea/reranking-videoragqna:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/reranks/video-rag-qna/Dockerfile . +docker build --no-cache -t opea/reranking-videoqna:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/reranks/videoqna/Dockerfile . ``` ### 1.2 Start Rerank Service ```bash -docker compose -f comps/reranks/video-rag-qna/docker/docker_compose_reranking.yaml up -d +docker compose -f comps/reranks/videoqna/docker_compose_reranking.yaml up -d # wait until ready -until docker logs reranking-videoragqna-server 2>&1 | grep -q "Uvicorn running on"; do +until docker logs reranking-videoqna-server 2>&1 | grep -q "Uvicorn running on"; do sleep 2 done ``` Available configuration by environment variable: -- CHUNK_DURATION: target chunk duration, should be aligned with VideoRAGQnA dataprep. Default 10s. +- CHUNK_DURATION: target chunk duration, should be aligned with VideoQnA dataprep. Default 10s. ## ✅ 2. Test @@ -57,6 +57,6 @@ The result should be: ```bash # remove the container -cid=$(docker ps -aq --filter "name=reranking-videoragqna-server") +cid=$(docker ps -aq --filter "name=reranking-videoqna-server") if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid && sleep 1s; fi ``` diff --git a/comps/reranks/video-rag-qna/docker_compose_reranking.yaml b/comps/reranks/videoqna/docker_compose_reranking.yaml similarity index 81% rename from comps/reranks/video-rag-qna/docker_compose_reranking.yaml rename to comps/reranks/videoqna/docker_compose_reranking.yaml index d819f331a..4b39fd115 100644 --- a/comps/reranks/video-rag-qna/docker_compose_reranking.yaml +++ b/comps/reranks/videoqna/docker_compose_reranking.yaml @@ -3,8 +3,8 @@ services: reranking: - image: opea/reranking-videoragqna:latest - container_name: reranking-videoragqna-server + image: opea/reranking-videoqna:latest + container_name: reranking-videoqna-server ports: - "8000:8000" ipc: host diff --git a/comps/reranks/video-rag-qna/local_reranking.py b/comps/reranks/videoqna/local_reranking.py similarity index 92% rename from comps/reranks/video-rag-qna/local_reranking.py rename to comps/reranks/videoqna/local_reranking.py index 9ba8aeb6f..ac234499b 100644 --- a/comps/reranks/video-rag-qna/local_reranking.py +++ b/comps/reranks/videoqna/local_reranking.py @@ -75,7 +75,7 @@ def format_video_name(video_name): @register_microservice( - name="opea_service@reranking_visual_rag", + name="opea_service@reranking_videoqna", service_type=ServiceType.RERANK, endpoint="/v1/reranking", host="0.0.0.0", @@ -83,7 +83,7 @@ def format_video_name(video_name): input_datatype=SearchedMultimodalDoc, output_datatype=LVMVideoDoc, ) -@register_statistics(names=["opea_service@reranking_visual_rag"]) +@register_statistics(names=["opea_service@reranking_videoqna"]) def reranking(input: SearchedMultimodalDoc) -> LVMVideoDoc: start = time.time() try: @@ -110,10 +110,10 @@ def reranking(input: SearchedMultimodalDoc) -> LVMVideoDoc: # Handle any other exceptions with a generic server error response raise HTTPException(status_code=500, detail="An unexpected error occurred.") - statistics_dict["opea_service@reranking_visual_rag"].append_latency(time.time() - start, None) + statistics_dict["opea_service@reranking_videoqna"].append_latency(time.time() - start, None) return result if __name__ == "__main__": - opea_microservices["opea_service@reranking_visual_rag"].start() + opea_microservices["opea_service@reranking_videoqna"].start() diff --git a/comps/reranks/video-rag-qna/requirements.txt b/comps/reranks/videoqna/requirements.txt similarity index 100% rename from comps/reranks/video-rag-qna/requirements.txt rename to comps/reranks/videoqna/requirements.txt diff --git a/tests/cores/mega/test_service_orchestrator_with_videoragqnagateway.py b/tests/cores/mega/test_service_orchestrator_with_videoqnagateway.py similarity index 90% rename from tests/cores/mega/test_service_orchestrator_with_videoragqnagateway.py rename to tests/cores/mega/test_service_orchestrator_with_videoqnagateway.py index a9bdcdb33..4905120fb 100644 --- a/tests/cores/mega/test_service_orchestrator_with_videoragqnagateway.py +++ b/tests/cores/mega/test_service_orchestrator_with_videoqnagateway.py @@ -6,14 +6,7 @@ from fastapi.responses import StreamingResponse -from comps import ( - ServiceOrchestrator, - ServiceType, - TextDoc, - VideoRAGQnAGateway, - opea_microservices, - register_microservice, -) +from comps import ServiceOrchestrator, ServiceType, TextDoc, VideoQnAGateway, opea_microservices, register_microservice from comps.cores.proto.docarray import LLMParams @@ -51,7 +44,7 @@ def setUp(self): self.service_builder.add(opea_microservices["s1"]).add(opea_microservices["s2"]) self.service_builder.flow_to(self.s1, self.s2) - self.gateway = VideoRAGQnAGateway(self.service_builder, port=9898) + self.gateway = VideoQnAGateway(self.service_builder, port=9898) def tearDown(self): self.s1.stop() diff --git a/tests/reranks/test_reranks_video-rag-qna.sh b/tests/reranks/test_reranks_videoqna.sh old mode 100644 new mode 100755 similarity index 86% rename from tests/reranks/test_reranks_video-rag-qna.sh rename to tests/reranks/test_reranks_videoqna.sh index 631124c16..9d6cdf051 --- a/tests/reranks/test_reranks_video-rag-qna.sh +++ b/tests/reranks/test_reranks_videoqna.sh @@ -9,11 +9,11 @@ ip_address=$(hostname -I | awk '{print $1}') function build_docker_images() { cd $WORKPATH - docker build --no-cache -t opea/reranking-videoragqna:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/reranks/video-rag-qna/Dockerfile . + docker build --no-cache -t opea/reranking-videoqna:comps --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/reranks/videoqna/Dockerfile . } function start_service() { - docker run -d --name "test-comps-reranking-videoragqna-server" \ + docker run -d --name "test-comps-reranking-videoqna-server" \ -p 5037:8000 \ --ipc=host \ -e no_proxy=${no_proxy} \ @@ -21,10 +21,10 @@ function start_service() { -e https_proxy=${https_proxy} \ -e CHUNK_DURATION=${CHUNK_DURATION} \ -e FILE_SERVER_ENDPOINT=${FILE_SERVER_ENDPOINT} \ - opea/reranking-videoragqna:latest + opea/reranking-videoqna:comps - until docker logs test-comps-reranking-videoragqna-server 2>&1 | grep -q "Uvicorn running on"; do + until docker logs test-comps-reranking-videoqna-server 2>&1 | grep -q "Uvicorn running on"; do sleep 2 done }