|
| 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 | +``` |
0 commit comments