Skip to content

Commit

Permalink
Refactor prompt registry microservice (#1124)
Browse files Browse the repository at this point in the history
Signed-off-by: lvliang-intel <[email protected]>
  • Loading branch information
lvliang-intel authored Jan 9, 2025
1 parent ec66b91 commit 179b5da
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 26 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/docker/compose/prompt_registry-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# this file should be run in the root of the repo
services:
promptregistry-mongo-server:
promptregistry-server:
build:
dockerfile: comps/prompt_registry/mongo/Dockerfile
image: ${REGISTRY:-opea}/promptregistry-mongo-server:${TAG:-latest}
dockerfile: comps/prompt_registry/src/Dockerfile
image: ${REGISTRY:-opea}/promptregistry-server:${TAG:-latest}
2 changes: 1 addition & 1 deletion comps/prompt_registry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ The Prompt Registry microservice able to support various database backends for s

### Prompt Registry with MongoDB

For more detail, please refer to this [README](./mongo/README.md)
For more detail, please refer to this [README](./src/README.md)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:

promptregistry-mongo:
image: opea/promptregistry-mongo:latest
container_name: promptregistry-mongo-server
container_name: promptregistry-server
ports:
- "6018:6018"
ipc: host
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -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/prompt_registry/mongo/requirements.txt && \
pip install --no-cache-dir -r /home/user/comps/prompt_registry/src/requirements.txt && \
pip install --no-cache-dir -r /home/user/requirements.txt

ENV PYTHONPATH=$PYTHONPATH:/home/user

WORKDIR /home/user/comps/prompt_registry/mongo
WORKDIR /home/user/comps/prompt_registry/src/

ENTRYPOINT ["python", "prompt.py"]
ENTRYPOINT ["python", "opea_prompt_microservice.py"]
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export COLLECTION_NAME=${COLLECTION_NAME}

```bash
cd ~/GenAIComps
docker build -t opea/promptregistry-mongo-server:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/prompt_registry/mongo/Dockerfile .
docker build -t opea/promptregistry-server:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/prompt_registry/src/Dockerfile .
```

### Run Docker with CLI
Expand All @@ -37,7 +37,7 @@ docker build -t opea/promptregistry-mongo-server:latest --build-arg https_proxy=
- Run Prompt Registry microservice

```bash
docker run -d --name="promptregistry-mongo-server" -p 6018:6018 -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy -e MONGO_HOST=${MONGO_HOST} -e MONGO_PORT=${MONGO_PORT} -e DB_NAME=${DB_NAME} -e COLLECTION_NAME=${COLLECTION_NAME} opea/promptregistry-mongo-server:latest
docker run -d --name="promptregistry-server" -p 6018:6018 -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy -e MONGO_HOST=${MONGO_HOST} -e MONGO_PORT=${MONGO_PORT} -e DB_NAME=${DB_NAME} -e COLLECTION_NAME=${COLLECTION_NAME} opea/promptregistry-server:latest
```

---
Expand Down
2 changes: 2 additions & 0 deletions comps/prompt_registry/src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
2 changes: 2 additions & 0 deletions comps/prompt_registry/src/integrations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
2 changes: 2 additions & 0 deletions comps/prompt_registry/src/integrations/mongo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from typing import Any

import motor.motor_asyncio as motor
from config import DB_NAME, MONGO_HOST, MONGO_PORT

from .config import DB_NAME, MONGO_HOST, MONGO_PORT


class MongoClient:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import os
from typing import Optional

from mongo_store import PromptStore
from prompt_store import PromptStore
from pydantic import BaseModel

from comps import CustomLogger
from comps.cores.mega.micro_service import opea_microservices, register_microservice

logger = CustomLogger("prompt_mongo")
logger = CustomLogger("prompt_registry")
logflag = os.getenv("LOGFLAG", False)


Expand Down Expand Up @@ -39,7 +39,7 @@ class PromptId(BaseModel):


@register_microservice(
name="opea_service@prompt_mongo",
name="opea_service@prompt",
endpoint="/v1/prompt/create",
host="0.0.0.0",
input_datatype=PromptCreate,
Expand Down Expand Up @@ -70,7 +70,7 @@ async def create_prompt(prompt: PromptCreate):


@register_microservice(
name="opea_service@prompt_mongo",
name="opea_service@prompt",
endpoint="/v1/prompt/get",
host="0.0.0.0",
input_datatype=PromptId,
Expand Down Expand Up @@ -106,7 +106,7 @@ async def get_prompt(prompt: PromptId):


@register_microservice(
name="opea_service@prompt_mongo",
name="opea_service@prompt",
endpoint="/v1/prompt/delete",
host="0.0.0.0",
input_datatype=PromptId,
Expand Down Expand Up @@ -140,4 +140,4 @@ async def delete_prompt(prompt: PromptId):


if __name__ == "__main__":
opea_microservices["opea_service@prompt_mongo"].start()
opea_microservices["opea_service@prompt"].start()
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import bson.errors as BsonError
from bson.objectid import ObjectId
from config import COLLECTION_NAME
from mongo_conn import MongoClient
from integrations.mongo.config import COLLECTION_NAME
from integrations.mongo.mongo_conn import MongoClient


class PromptStore:
Expand All @@ -16,8 +16,9 @@ def __init__(
):
self.user = user

def initialize_storage(self) -> None:
self.db_client = MongoClient.get_db_client()
def initialize_storage(self, db_type="mongo") -> None:
if db_type == "mongo":
self.db_client = MongoClient.get_db_client()
self.collection = self.db_client[COLLECTION_NAME]

async def save_prompt(self, prompt) -> str:
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions tests/prompt_registry/test_prompt_registry_mongo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ function build_docker_images() {
echo $(pwd)
docker run -d -p 27017:27017 --name=test-comps-mongo mongo:latest

docker build --no-cache -t opea/promptregistry-mongo-server:comps --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/prompt_registry/mongo/Dockerfile .
docker build --no-cache -t opea/promptregistry-server:comps --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/prompt_registry/src/Dockerfile .
if [ $? -ne 0 ]; then
echo "opea/promptregistry-mongo-server built fail"
echo "opea/promptregistry-server built fail"
exit 1
else
echo "opea/promptregistry-mongo-server built successful"
echo "opea/promptregistry-server built successful"
fi
}

function start_service() {

docker run -d --name="test-comps-promptregistry-mongo-server" -p 6018:6018 -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy -e MONGO_HOST=${MONGO_HOST} -e MONGO_PORT=${MONGO_PORT} -e DB_NAME=${DB_NAME} -e COLLECTION_NAME=${COLLECTION_NAME} opea/promptregistry-mongo-server:comps
docker run -d --name="test-comps-promptregistry-server" -p 6018:6018 -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy -e MONGO_HOST=${MONGO_HOST} -e MONGO_PORT=${MONGO_PORT} -e DB_NAME=${DB_NAME} -e COLLECTION_NAME=${COLLECTION_NAME} opea/promptregistry-server:comps

sleep 10s
}
Expand All @@ -46,7 +46,7 @@ function validate_microservice() {
echo "Correct result."
else
echo "Incorrect result."
docker logs test-comps-promptregistry-mongo-server
docker logs test-comps-promptregistry-server
exit 1
fi

Expand Down

0 comments on commit 179b5da

Please sign in to comment.