Skip to content

Commit

Permalink
Rename videoragqna to videoqna to align with other examples (#680)
Browse files Browse the repository at this point in the history
Signed-off-by: BaoHuiling <[email protected]>
  • Loading branch information
BaoHuiling authored Sep 12, 2024
1 parent 0458443 commit 2b68323
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 35 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/docker/compose/reranks-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
2 changes: 1 addition & 1 deletion comps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
AudioQnAGateway,
RetrievalToolGateway,
FaqGenGateway,
VideoRAGQnAGateway,
VideoQnAGateway,
VisualQnAGateway,
MultimodalRAGWithVideosGateway,
)
Expand Down
2 changes: 1 addition & 1 deletion comps/cores/mega/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions comps/cores/mega/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
# 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

### 1.1 Build Images

```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

Expand Down Expand Up @@ -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
```
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ 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",
port=8000,
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:
Expand All @@ -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()
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions tests/reranks/test_reranks_video-rag-qna.sh → tests/reranks/test_reranks_videoqna.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ 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} \
-e http_proxy=${http_proxy} \
-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
}
Expand Down

0 comments on commit 2b68323

Please sign in to comment.