Skip to content

Commit 72123b2

Browse files
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 <[email protected]> * 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 <[email protected]> * Include test for feedback_management microservice Signed-off-by: Yeoh, Hoong Tee <[email protected]> * 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 <[email protected]> * [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 <[email protected]> --------- Signed-off-by: Yeoh, Hoong Tee <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 0bb69ac commit 72123b2

File tree

9 files changed

+680
-0
lines changed

9 files changed

+680
-0
lines changed
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# Feedback Management Microservice
2+
3+
The Feedback Management microservice facilitates the storage and retrieval of users'feedback data by establishing a connection with the database.
4+
5+
## Setup Environment Variables
6+
7+
```bash
8+
export http_proxy=${your_http_proxy}
9+
export https_proxy=${your_http_proxy}
10+
export MONGO_HOST=${MONGO_HOST}
11+
export MONGO_HOST=27017
12+
export DB_NAME=${DB_NAME}
13+
export COLLECTION_NAME=${COLLECTION_NAME}
14+
```
15+
16+
## Start Feedback Management microservice for MongoDB with Python script
17+
18+
Start document preparation microservice for Milvus with below command.
19+
20+
```bash
21+
python feedback.py
22+
```
23+
24+
## 🚀Start Microservice with Docker
25+
26+
### Build Docker Image
27+
28+
```bash
29+
cd ~/GenAIComps
30+
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 .
31+
```
32+
33+
### Run Docker with CLI
34+
35+
1. Run mongoDB image
36+
37+
```bash
38+
docker run -d -p 27017:27017 --name=mongo mongo:latest
39+
```
40+
41+
2. Run Feedback Management service
42+
43+
```bash
44+
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
45+
```
46+
47+
### Invoke Microservice
48+
49+
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.
50+
51+
- Save feedback data into database.
52+
53+
```bash
54+
curl -X 'POST' \
55+
http://{host_ip}:6016/v1/feedback/create \
56+
-H 'accept: application/json' \
57+
-H 'Content-Type: application/json' \
58+
-d '{
59+
"chat_id": "66445d4f71c7eff23d44f78d",
60+
"chat_data": {
61+
"user": "test",
62+
"messages": [
63+
{
64+
"role": "system",
65+
"content": "You are helpful assistant"
66+
},
67+
{
68+
"role": "user",
69+
"content": "hi",
70+
"time": "1724915247"
71+
},
72+
{
73+
"role": "assistant",
74+
"content": "Hi, may I help you?",
75+
"time": "1724915249"
76+
}
77+
]
78+
},
79+
"feedback_data": {
80+
"comment": "Moderate",
81+
"rating": 3,
82+
"is_thumbs_up": true
83+
}}'
84+
85+
86+
# Take note that chat_id here would be the id get from chathistory_mongo service
87+
# 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.
88+
```
89+
90+
- Update the feedback data of specified feedback_id
91+
92+
```bash
93+
curl -X 'POST' \
94+
http://{host_ip}:6016/v1/feedback/create \
95+
-H 'accept: application/json' \
96+
-H 'Content-Type: application/json' \
97+
-d '{
98+
"chat_id": "66445d4f71c7eff23d44f78d",
99+
"chat_data": {
100+
"user": "test",
101+
"messages": [
102+
{
103+
"role": "system",
104+
"content": "You are helpful assistant"
105+
},
106+
{
107+
"role": "user",
108+
"content": "hi",
109+
"time": "1724915247"
110+
},
111+
{
112+
"role": "assistant",
113+
"content": "Hi, may I help you?",
114+
"time": "1724915249"
115+
}
116+
]
117+
},
118+
"feedback_data": {
119+
"comment": "Fair and Moderate answer",
120+
"rating": 2,
121+
"is_thumbs_up": true
122+
},
123+
"feedback_id": "{feedback_id of the data that wanted to update}"}'
124+
125+
# Just include any feedback_data field value that you wanted to update.
126+
```
127+
128+
- Retrieve feedback data from database based on user or feedback_id
129+
130+
```bash
131+
curl -X 'POST' \
132+
http://{host_ip}:6016/v1/feedback/get \
133+
-H 'accept: application/json' \
134+
-H 'Content-Type: application/json' \
135+
-d '{
136+
"user": "test"}'
137+
```
138+
139+
```bash
140+
curl -X 'POST' \
141+
http://{host_ip}:6016/v1/feedback/get \
142+
-H 'accept: application/json' \
143+
-H 'Content-Type: application/json' \
144+
-d '{
145+
"user": "test", "feedback_id":"{feedback_id returned from save feedback route above}"}'
146+
```
147+
148+
- Delete feedback data from database based on feedback_id provided
149+
150+
```bash
151+
curl -X 'POST' \
152+
http://{host_ip}:6016/v1/feedback/delete \
153+
-H 'accept: application/json' \
154+
-H 'Content-Type: application/json' \
155+
-d '{
156+
"user": "test", "feedback_id":"{feedback_id to be deleted}"}'
157+
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
import os
5+
6+
# MONGO configuration
7+
MONGO_HOST = os.getenv("MONGO_HOST", "localhost")
8+
MONGO_PORT = os.getenv("MONGO_PORT", 27017)
9+
DB_NAME = os.getenv("DB_NAME", "OPEA")
10+
COLLECTION_NAME = os.getenv("COLLECTION_NAME", "Feedback")
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
FROM python:3.11-slim
5+
6+
ENV LANG=C.UTF-8
7+
8+
RUN apt-get update -y && apt-get install -y --no-install-recommends --fix-missing \
9+
build-essential \
10+
libgl1-mesa-glx \
11+
libjemalloc-dev \
12+
vim
13+
14+
RUN useradd -m -s /bin/bash user && \
15+
mkdir -p /home/user && \
16+
chown -R user /home/user/
17+
18+
USER user
19+
20+
COPY comps /home/user/comps
21+
COPY requirements.txt /home/user/
22+
23+
RUN pip install --no-cache-dir --upgrade pip && \
24+
pip install --no-cache-dir -r /home/user/comps/feedback_management/mongo/requirements.txt && \
25+
pip install --no-cache-dir -r /home/user/requirements.txt
26+
27+
ENV PYTHONPATH=$PYTHONPATH:/home/user
28+
29+
WORKDIR /home/user/comps/feedback_management/mongo
30+
31+
ENTRYPOINT ["python", "feedback.py"]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
version: "3"
5+
services:
6+
mongo:
7+
image: mongo:7.0.11
8+
container_name: mongodb
9+
ports:
10+
- 27017:27017
11+
environment:
12+
http_proxy: ${http_proxy}
13+
https_proxy: ${https_proxy}
14+
no_proxy: ${no_proxy}
15+
command: mongod --quiet --logpath /dev/null
16+
17+
feedbackmanagement-mongo:
18+
image: opea/feedbackmanagement-mongo:latest
19+
container_name: feedbackmanagement-mongo-server
20+
ports:
21+
- "6016:6016"
22+
ipc: host
23+
environment:
24+
http_proxy: ${http_proxy}
25+
https_proxy: ${https_proxy}
26+
no_proxy: ${no_proxy}
27+
MONGO_HOST: ${MONGO_HOST}
28+
MONGO_PORT: ${MONGO_PORT}
29+
DB_NAME: ${DB_NAME}
30+
COLLECTION_NAME: ${COLLECTION_NAME}
31+
restart: unless-stopped
32+
33+
networks:
34+
default:
35+
driver: bridge

0 commit comments

Comments
 (0)