From c7917e14e3aa0a28a4d3c8f38f54b64161b99dcc Mon Sep 17 00:00:00 2001 From: "Yao, Qing" Date: Thu, 16 Jan 2025 10:52:32 +0800 Subject: [PATCH] Refactor chathistory based on E-RAG code structure. Previously, the code for implementing microservice and functionalities was placed in one folder. Now the microservice and functionalities code have been separated. Fix [Issue](https://github.com/opea-project/GenAIComps/issues/989) Signed-off-by: Yao, Qing --- .github/workflows/docker/compose/chathistory-compose.yaml | 2 +- comps/chathistory/README.md | 2 +- comps/chathistory/{mongo => src}/Dockerfile | 6 +++--- comps/chathistory/{mongo => src}/README.md | 2 +- comps/chathistory/src/__init__.py | 0 comps/chathistory/src/integrations/__init__.py | 0 comps/chathistory/src/integrations/mongo/__init__.py | 0 comps/chathistory/{ => src/integrations}/mongo/config.py | 0 .../chathistory/{ => src/integrations}/mongo/mongo_conn.py | 0 .../chathistory/{ => src/integrations}/mongo/mongo_store.py | 0 .../opea_chathistory_microservice.py} | 4 ++-- comps/chathistory/{mongo => src}/requirements.txt | 0 tests/chathistory/test_chathistory_mongo.sh | 2 +- 13 files changed, 9 insertions(+), 9 deletions(-) rename comps/chathistory/{mongo => src}/Dockerfile (76%) rename comps/chathistory/{mongo => src}/README.md (98%) create mode 100644 comps/chathistory/src/__init__.py create mode 100644 comps/chathistory/src/integrations/__init__.py create mode 100644 comps/chathistory/src/integrations/mongo/__init__.py rename comps/chathistory/{ => src/integrations}/mongo/config.py (100%) rename comps/chathistory/{ => src/integrations}/mongo/mongo_conn.py (100%) rename comps/chathistory/{ => src/integrations}/mongo/mongo_store.py (100%) rename comps/chathistory/{mongo/chathistory_mongo.py => src/opea_chathistory_microservice.py} (97%) rename comps/chathistory/{mongo => src}/requirements.txt (100%) diff --git a/.github/workflows/docker/compose/chathistory-compose.yaml b/.github/workflows/docker/compose/chathistory-compose.yaml index 987447feea..3991a99734 100644 --- a/.github/workflows/docker/compose/chathistory-compose.yaml +++ b/.github/workflows/docker/compose/chathistory-compose.yaml @@ -5,5 +5,5 @@ services: chathistory-mongo-server: build: - dockerfile: comps/chathistory/mongo/Dockerfile + dockerfile: comps/chathistory/src/Dockerfile image: ${REGISTRY:-opea}/chathistory-mongo-server:${TAG:-latest} diff --git a/comps/chathistory/README.md b/comps/chathistory/README.md index 4f7bcbf717..5ba529774b 100644 --- a/comps/chathistory/README.md +++ b/comps/chathistory/README.md @@ -23,4 +23,4 @@ The Chat History microservice able to support various database backends for stor ### Chat History with MongoDB -For more detail, please refer to this [README](./mongo/README.md) +For more detail, please refer to this [README](src/README.md) diff --git a/comps/chathistory/mongo/Dockerfile b/comps/chathistory/src/Dockerfile similarity index 76% rename from comps/chathistory/mongo/Dockerfile rename to comps/chathistory/src/Dockerfile index 58b1c5aa4d..f1ef18b459 100644 --- a/comps/chathistory/mongo/Dockerfile +++ b/comps/chathistory/src/Dockerfile @@ -20,11 +20,11 @@ COPY comps /home/user/comps COPY requirements.txt /home/user/ RUN pip install --no-cache-dir --upgrade pip setuptools && \ - pip install --no-cache-dir -r /home/user/comps/chathistory/mongo/requirements.txt && \ + pip install --no-cache-dir -r /home/user/comps/chathistory/src/requirements.txt && \ pip install --no-cache-dir -r /home/user/requirements.txt ENV PYTHONPATH=$PYTHONPATH:/home/user -WORKDIR /home/user/comps/chathistory/mongo +WORKDIR /home/user/comps/chathistory/src -ENTRYPOINT ["python", "chathistory_mongo.py"] +ENTRYPOINT ["python", "opea_chathistory_microservice.py"] diff --git a/comps/chathistory/mongo/README.md b/comps/chathistory/src/README.md similarity index 98% rename from comps/chathistory/mongo/README.md rename to comps/chathistory/src/README.md index 0eb949cfc6..d6c6054d7f 100644 --- a/comps/chathistory/mongo/README.md +++ b/comps/chathistory/src/README.md @@ -23,7 +23,7 @@ export COLLECTION_NAME=${COLLECTION_NAME} ```bash cd ../../../../ -docker build -t opea/chathistory-mongo-server:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/chathistory/mongo/Dockerfile . +docker build -t opea/chathistory-mongo-server:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/chathistory/src/Dockerfile . ``` ### Run Docker with CLI diff --git a/comps/chathistory/src/__init__.py b/comps/chathistory/src/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/comps/chathistory/src/integrations/__init__.py b/comps/chathistory/src/integrations/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/comps/chathistory/src/integrations/mongo/__init__.py b/comps/chathistory/src/integrations/mongo/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/comps/chathistory/mongo/config.py b/comps/chathistory/src/integrations/mongo/config.py similarity index 100% rename from comps/chathistory/mongo/config.py rename to comps/chathistory/src/integrations/mongo/config.py diff --git a/comps/chathistory/mongo/mongo_conn.py b/comps/chathistory/src/integrations/mongo/mongo_conn.py similarity index 100% rename from comps/chathistory/mongo/mongo_conn.py rename to comps/chathistory/src/integrations/mongo/mongo_conn.py diff --git a/comps/chathistory/mongo/mongo_store.py b/comps/chathistory/src/integrations/mongo/mongo_store.py similarity index 100% rename from comps/chathistory/mongo/mongo_store.py rename to comps/chathistory/src/integrations/mongo/mongo_store.py diff --git a/comps/chathistory/mongo/chathistory_mongo.py b/comps/chathistory/src/opea_chathistory_microservice.py similarity index 97% rename from comps/chathistory/mongo/chathistory_mongo.py rename to comps/chathistory/src/opea_chathistory_microservice.py index 29f5d41cb6..c93d8fdea2 100644 --- a/comps/chathistory/mongo/chathistory_mongo.py +++ b/comps/chathistory/src/opea_chathistory_microservice.py @@ -1,13 +1,13 @@ -# Copyright (C) 2024 Intel Corporation +# Copyright (C) 2024 Intel Corporation # SPDX-License-Identifier: Apache-2.0 import os from typing import Optional from fastapi import HTTPException -from mongo_store import DocumentStore from pydantic import BaseModel from comps import CustomLogger +from comps.chathistory.src.integrations.mongo.mongo_store import DocumentStore from comps.cores.mega.micro_service import opea_microservices, register_microservice from comps.cores.proto.api_protocol import ChatCompletionRequest diff --git a/comps/chathistory/mongo/requirements.txt b/comps/chathistory/src/requirements.txt similarity index 100% rename from comps/chathistory/mongo/requirements.txt rename to comps/chathistory/src/requirements.txt diff --git a/tests/chathistory/test_chathistory_mongo.sh b/tests/chathistory/test_chathistory_mongo.sh index dd81b48d2e..f4fa7ad127 100644 --- a/tests/chathistory/test_chathistory_mongo.sh +++ b/tests/chathistory/test_chathistory_mongo.sh @@ -17,7 +17,7 @@ function build_docker_images() { echo $(pwd) docker run -d -p 27017:27017 --name=test-comps-mongo mongo:latest - docker build --no-cache -t opea/chathistory-mongo-server:comps --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/chathistory/mongo/Dockerfile . + docker build --no-cache -t opea/chathistory-mongo-server:comps --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/chathistory/src/Dockerfile . if [ $? -ne 0 ]; then echo "opea/chathistory-mongo-server built fail" exit 1