-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feedback management microservice component (#581)
* comps: Implement feedback_management component Implement feedback_management component with following endpoint: - /v1/feedback/create: Create and save user feedback data from mongo database. - /v1/feedback/get: Retrieve user feedback data from mongo database. - /v1/feedback/delete: Delete user feedback data from mongo database entry. Signed-off-by: Yeoh, Hoong Tee <hoong.tee.yeoh@intel.com> * feedback_management: Include README Include steps to build feedback_management microservice. Include example to invoke API endpoint for the microservice. Signed-off-by: Yeoh, Hoong Tee <hoong.tee.yeoh@intel.com> * Include test for feedback_management microservice Signed-off-by: Yeoh, Hoong Tee <hoong.tee.yeoh@intel.com> * feedback_management: Update schema Update endpoint schema for data to be collected and stored in database. Updated README and test script for the same. Signed-off-by: Yeoh, Hoong Tee <hoong.tee.yeoh@intel.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix typo in test_feedback_management_mongo Signed-off-by: Yeoh, Hoong Tee <hoong.tee.yeoh@intel.com> --------- Signed-off-by: Yeoh, Hoong Tee <hoong.tee.yeoh@intel.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
0bb69ac
commit 72123b2
Showing
9 changed files
with
680 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
# Feedback Management Microservice | ||
|
||
The Feedback Management microservice facilitates the storage and retrieval of users'feedback data by establishing a connection with the database. | ||
|
||
## Setup Environment Variables | ||
|
||
```bash | ||
export http_proxy=${your_http_proxy} | ||
export https_proxy=${your_http_proxy} | ||
export MONGO_HOST=${MONGO_HOST} | ||
export MONGO_HOST=27017 | ||
export DB_NAME=${DB_NAME} | ||
export COLLECTION_NAME=${COLLECTION_NAME} | ||
``` | ||
|
||
## Start Feedback Management microservice for MongoDB with Python script | ||
|
||
Start document preparation microservice for Milvus with below command. | ||
|
||
```bash | ||
python feedback.py | ||
``` | ||
|
||
## 🚀Start Microservice with Docker | ||
|
||
### Build Docker Image | ||
|
||
```bash | ||
cd ~/GenAIComps | ||
docker build -t opea/feedbackmanagement-mongo-server:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/feedback_management/mongo/docker/Dockerfile . | ||
``` | ||
|
||
### Run Docker with CLI | ||
|
||
1. Run mongoDB image | ||
|
||
```bash | ||
docker run -d -p 27017:27017 --name=mongo mongo:latest | ||
``` | ||
|
||
2. Run Feedback Management service | ||
|
||
```bash | ||
docker run -d --name="feedbackmanagement-mongo-server" -p 6016:6016 -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/feedbackmanagement-mongo-server:latest | ||
``` | ||
|
||
### Invoke Microservice | ||
|
||
Once feedback management service is up and running, user can access the database by using API endpoint below. Each API serves different purpose and return appropriate response. | ||
|
||
- Save feedback data into database. | ||
|
||
```bash | ||
curl -X 'POST' \ | ||
http://{host_ip}:6016/v1/feedback/create \ | ||
-H 'accept: application/json' \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{ | ||
"chat_id": "66445d4f71c7eff23d44f78d", | ||
"chat_data": { | ||
"user": "test", | ||
"messages": [ | ||
{ | ||
"role": "system", | ||
"content": "You are helpful assistant" | ||
}, | ||
{ | ||
"role": "user", | ||
"content": "hi", | ||
"time": "1724915247" | ||
}, | ||
{ | ||
"role": "assistant", | ||
"content": "Hi, may I help you?", | ||
"time": "1724915249" | ||
} | ||
] | ||
}, | ||
"feedback_data": { | ||
"comment": "Moderate", | ||
"rating": 3, | ||
"is_thumbs_up": true | ||
}}' | ||
|
||
|
||
# Take note that chat_id here would be the id get from chathistory_mongo service | ||
# If you do not wish to maintain chat history via chathistory_mongo service, you may generate some random uuid for it or just leave it empty. | ||
``` | ||
|
||
- Update the feedback data of specified feedback_id | ||
|
||
```bash | ||
curl -X 'POST' \ | ||
http://{host_ip}:6016/v1/feedback/create \ | ||
-H 'accept: application/json' \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{ | ||
"chat_id": "66445d4f71c7eff23d44f78d", | ||
"chat_data": { | ||
"user": "test", | ||
"messages": [ | ||
{ | ||
"role": "system", | ||
"content": "You are helpful assistant" | ||
}, | ||
{ | ||
"role": "user", | ||
"content": "hi", | ||
"time": "1724915247" | ||
}, | ||
{ | ||
"role": "assistant", | ||
"content": "Hi, may I help you?", | ||
"time": "1724915249" | ||
} | ||
] | ||
}, | ||
"feedback_data": { | ||
"comment": "Fair and Moderate answer", | ||
"rating": 2, | ||
"is_thumbs_up": true | ||
}, | ||
"feedback_id": "{feedback_id of the data that wanted to update}"}' | ||
|
||
# Just include any feedback_data field value that you wanted to update. | ||
``` | ||
|
||
- Retrieve feedback data from database based on user or feedback_id | ||
|
||
```bash | ||
curl -X 'POST' \ | ||
http://{host_ip}:6016/v1/feedback/get \ | ||
-H 'accept: application/json' \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{ | ||
"user": "test"}' | ||
``` | ||
|
||
```bash | ||
curl -X 'POST' \ | ||
http://{host_ip}:6016/v1/feedback/get \ | ||
-H 'accept: application/json' \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{ | ||
"user": "test", "feedback_id":"{feedback_id returned from save feedback route above}"}' | ||
``` | ||
|
||
- Delete feedback data from database based on feedback_id provided | ||
|
||
```bash | ||
curl -X 'POST' \ | ||
http://{host_ip}:6016/v1/feedback/delete \ | ||
-H 'accept: application/json' \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{ | ||
"user": "test", "feedback_id":"{feedback_id to be deleted}"}' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import os | ||
|
||
# MONGO configuration | ||
MONGO_HOST = os.getenv("MONGO_HOST", "localhost") | ||
MONGO_PORT = os.getenv("MONGO_PORT", 27017) | ||
DB_NAME = os.getenv("DB_NAME", "OPEA") | ||
COLLECTION_NAME = os.getenv("COLLECTION_NAME", "Feedback") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
FROM python:3.11-slim | ||
|
||
ENV LANG=C.UTF-8 | ||
|
||
RUN apt-get update -y && apt-get install -y --no-install-recommends --fix-missing \ | ||
build-essential \ | ||
libgl1-mesa-glx \ | ||
libjemalloc-dev \ | ||
vim | ||
|
||
RUN useradd -m -s /bin/bash user && \ | ||
mkdir -p /home/user && \ | ||
chown -R user /home/user/ | ||
|
||
USER user | ||
|
||
COPY comps /home/user/comps | ||
COPY requirements.txt /home/user/ | ||
|
||
RUN pip install --no-cache-dir --upgrade pip && \ | ||
pip install --no-cache-dir -r /home/user/comps/feedback_management/mongo/requirements.txt && \ | ||
pip install --no-cache-dir -r /home/user/requirements.txt | ||
|
||
ENV PYTHONPATH=$PYTHONPATH:/home/user | ||
|
||
WORKDIR /home/user/comps/feedback_management/mongo | ||
|
||
ENTRYPOINT ["python", "feedback.py"] |
35 changes: 35 additions & 0 deletions
35
comps/feedback_management/mongo/docker/docker-compose-user-feedback-mongo.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
version: "3" | ||
services: | ||
mongo: | ||
image: mongo:7.0.11 | ||
container_name: mongodb | ||
ports: | ||
- 27017:27017 | ||
environment: | ||
http_proxy: ${http_proxy} | ||
https_proxy: ${https_proxy} | ||
no_proxy: ${no_proxy} | ||
command: mongod --quiet --logpath /dev/null | ||
|
||
feedbackmanagement-mongo: | ||
image: opea/feedbackmanagement-mongo:latest | ||
container_name: feedbackmanagement-mongo-server | ||
ports: | ||
- "6016:6016" | ||
ipc: host | ||
environment: | ||
http_proxy: ${http_proxy} | ||
https_proxy: ${https_proxy} | ||
no_proxy: ${no_proxy} | ||
MONGO_HOST: ${MONGO_HOST} | ||
MONGO_PORT: ${MONGO_PORT} | ||
DB_NAME: ${DB_NAME} | ||
COLLECTION_NAME: ${COLLECTION_NAME} | ||
restart: unless-stopped | ||
|
||
networks: | ||
default: | ||
driver: bridge |
Oops, something went wrong.